- Joined
- Jun 26, 2020
- Messages
- 1,928
I made a system to store the color of the unit (the actual, not the color of the player) and it should have a trigger for the units those apear in the map (and th user pre-placed in the editor), but it doesn't do anything, what's wrong?
Lua:
do
--This library is to store the actual color of a unit and also if is changed.
--Also add a constant PLAYER_COLOR_BLACK that you can use and a function GetUnitColor to have the saved unit color.
LIBRARY_StoreUnitColor=true
PLAYER_COLOR_BLACK=ConvertPlayerColor(PLAYER_NEUTRAL_AGGRESSIVE) ---@type playercolor
local UnitColor={} ---@type playercolor
local oldinit=InitBlizzard
function InitBlizzard()
local re=CreateRegion()
local r=GetWorldBounds()
RegionAddRect(re,r)
RemoveRect(r)
TriggerRegisterEnterRegion(CreateTrigger(),re,Filter(function()
print(GetFilterUnit()) --Doesn't print nothing
UnitColor[GetFilterUnit()]=GetPlayerColor(GetOwningPlayer(GetFilterUnit()))
return false
end))
oldinit()
end
--I just had to change these 2 functions.
local OldSetUnitColor=SetUnitColor
---@param whichUnit unit
---@param color playercolor
function SetUnitColor(whichUnit,color)
UnitColor[whichUnit]=color
OldSetUnitColor(whichUnit,color)
end
local OldSetUnitOwner=SetUnitOwner
---@param whichUnit unit
---@param whichPlayer player
---@param changeColor boolean
function SetUnitOwner(whichUnit,whichPlayer,changeColor)
if changeColor then
UnitColor[whichUnit]=GetPlayerColor(whichPlayer)
end
OldSetUnitOwner(whichUnit,whichPlayer,changeColor)
end
---@param whichUnit unit
---@return playercolor
function GetUnitColor(whichUnit)
return UnitColor[whichUnit]
end
end