- Joined
- Feb 29, 2020
- Messages
- 89
I have seen that in the DEMO MAP the enemy units continue to show the prefix. Can it be updated?
globals
string PREFIX_SEPARATOR = "!"
group PREFIX_OFF_GROUP = CreateGroup()
endglobals
library SPS
function SPSSetPrefixArg takes string prefix returns nothing
set PREFIX_SEPARATOR = prefix
endfunction
function SPSSetPrefixGUI takes nothing returns nothing
set PREFIX_SEPARATOR = udg_SPSPrefix
endfunction
function SPSGetRealName takes string unitName, integer separatorPosition returns string
local integer stringLength = StringLength(unitName)
local string prefix
local string remainString
local string newUnitName
set prefix = SubString(unitName, 0, separatorPosition)
set remainString = SubString(unitName, separatorPosition+2, stringLength)
call BJDebugMsg("|cffffff00Prefix|r: " + prefix)
call BJDebugMsg("|cffffff00Separator|r: " + PREFIX_SEPARATOR)
call BJDebugMsg("|cffffff00Real Name|r: " + remainString)
return remainString
endfunction
function SPSGetSeparatorPosition takes string unitName returns integer
local integer i = 0
local integer stringLength = StringLength(unitName)
local boolean hasFindPrefix = false
local string tempString
local integer separatorPosition
loop
set tempString = SubString(unitName, i, i + 1)
if (tempString == PREFIX_SEPARATOR) then
if (hasFindPrefix == false) then
set separatorPosition = i
set hasFindPrefix = true
endif
endif
set i = i + 1
exitwhen i == stringLength
endloop
return separatorPosition
endfunction
function SPSSetRealName takes unit u returns nothing
local string unitName
local integer separatorPosition
local string unitRealName
if (IsUnitInGroup(u, PREFIX_OFF_GROUP) == true) then
return
else
set unitName = GetUnitName(u)
set separatorPosition = SPSGetSeparatorPosition(unitName)
set unitRealName = SPSGetRealName(unitName, separatorPosition)
call BlzSetUnitName(u, unitRealName)
call GroupAddUnit(PREFIX_OFF_GROUP, u)
set u = null
endif
endfunction
endlibrary