- Joined
- Oct 9, 2019
- Messages
- 357
I'm trying to make a Lua function override for GetUnitUserData and GetHandleId that addresses the issues found here lua and unit data and wanted to make sure I did it right.
Lua:
DetectRemoveAbility = FourCC("A01Z")
UnitUDataTable = {}
HandleIdKeyTable = {}
HandleIdValueTable = {}
SetUnitUserData = function(u,i)
if u==nil then
return
end
UnitUDataTable[u]=i
end
GetUnitUserData = function(u)
if u==nil or UnitUDataTable[u]==nil then
return 0
end
return UnitUDataTable[u]
end
function CleanUnitUserDataTable()
local u = GetFilterUnit()
if GetUnitAbilityLevel(u, DetectRemoveAbility) == 0 then
UnitUDataTable[u]=nil
end
return false
end
GetHandleId = function(o)
if o==nil then
return 0
end
if HandleIdKeyTable[o]~=nil then
return HandleIdKeyTable[o]
end
local length = #HandleIdValueTable + 1
HandleIdKeyTable[o] = length
HandleIdValueTable[length] = o
return length
end
function InitUserDataCleanup()
local t=CreateTrigger()
for i=0,bj_MAX_PLAYERS do
TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_ISSUED_ORDER, Filter(CleanUnitUserDataTable))
end
end
Last edited:



