- Joined
- Jul 18, 2010
- Messages
- 2,377
This is a Lua system that removes the power to create/destroy Location/Group/Force/Rect after 0.01s passed. This time was choosen to allow creating new Objects in Map init triggers. Instead when the map's code would request a new object of such types, then it cycles a fixed set of such. It mostly is meant for GUI users.
Installing this will remove Leaks of this types, but it also breaks code that depents on creating many new objects in one run.
Like this Trigger will break when one installed this system, because Loc will be moved to some other place when the Location object-Set Size is surpassed on default when the group contains 4 or more units:
ChangeLog:
1.1 can now choose default amount of objects inside Leak preventer with a number, increased default to 64, mentions the Enable/Disable Feature in the head comment.
How to install:
Create a new Custom Script in trigger Editor
Name it Leak Preventer
Copy paste all Lua code from the Lua code Box above
Installing this will remove Leaks of this types, but it also breaks code that depents on creating many new objects in one run.
Like this Trigger will break when one installed this system, because Loc will be moved to some other place when the Location object-Set Size is surpassed on default when the group contains 4 or more units:
-
Actions
-
Set MaxDistance = 0.00
-
Set Loc = (Center of (Playable map area))
-
Unit Group - Pick every unit in (Units within 900.00 of Loc) and do (Actions)
-
Loop - Actions
-
Set Loc2 = (Position of (Picked unit))
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
-
(Distance between Loc and Loc2) Greater than MaxDistance
-
-
Then - Actions
-
Set MaxDistance = (Distance between Loc and Loc2)
-
-
Else - Actions
-
-
Custom script: RemoveLocation(udg_Loc2)
-
-
-
Custom script: RemoveLocation(udg_Loc)
-
-
Actions
-
Set MaxDistance = 0.00
-
Unit Group - Pick every unit in (Units within 900.00 of (Center of (Playable map area))) and do (Actions)
-
Loop - Actions
-
Set Distance = (Distance between (Center of (Playable map area)) and (Position of (Picked unit)))
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
-
Distance Greater than MaxDistance
-
-
Then - Actions
-
Set MaxDistance = Distance
-
-
Else - Actions
-
-
-
-
Lua:
-- Leak Preventer 1.1a By Tasyen
do
--[[
gui Location/Group/Force/Rect functions that would create new objects won't anymore. Instead they move/reuse a fixed amount of objects.
variables created in InitGlobals (variable editor) are unaffected until overwritten by a "new" object.
this version replaces only the creators, hence it is quite small
one can turn of Leak Preventer by executing trigger udg_LeakPreventerDisable
one can turn on Leak Preventer by executing trigger udg_LeakPreventerEnable
if you want to use this feature in GUI you need to create trigger variables for them.
--]]
--local real = InitGlobals
local real = MarkGameStarted
function MarkGameStarted()
--function InitGlobals()
-- amount of objects in usage per type
local objectSize = 64
-- xpcall(function()
real()
local FuncOld = {}
local FuncNew = {}
local FuncKey = {}
local FuncCount = 0
local function overwrite(key, new)
local old = _G[key]
--print(key, old)
if FuncOld[old] then return end
FuncCount = FuncCount + 1
FuncNew[FuncCount] = new
FuncOld[FuncCount] = old
FuncKey[FuncCount] = key
FuncOld[old] = true
end
local function enable(flag)
if flag then
for index = 1, FuncCount, 1 do
_G[FuncKey[index]] = FuncNew[index]
end
else
for index = 1, FuncCount, 1 do
_G[FuncKey[index]] = FuncOld[index]
end
end
end
local GUILoc = {}
for i = 1, objectSize do GUILoc[i] = Location(0, 0) end
local LocCounter = 0
local LocCounterMax = #GUILoc
local function LocXY(x, y)
if LocCounter >= LocCounterMax then
LocCounter = 1
else
LocCounter = LocCounter + 1
end
MoveLocation(GUILoc[LocCounter], x, y)
--print("custom Loc",LocCounter, GetLocationX(GUILoc[LocCounter]), GetLocationY(GUILoc[LocCounter]))
return GUILoc[LocCounter]
end
overwrite("Location", function(x, y) return LocXY(x, y) end)
-- you are not allowed to destroy them
overwrite("RemoveLocation", DoNothing)
overwrite("GetUnitLoc", function(unit) return LocXY(GetWidgetX(unit), GetWidgetY(unit)) end)
overwrite("GetPlayerStartLocationLoc", function(player)
local index = GetPlayerStartLocation(player)
return LocXY(GetStartLocationX(index), GetStartLocationY(index))
end)
local oldGetUnitRallyPoint = GetUnitRallyPoint
overwrite("GetUnitRallyPoint", function(unit) return GetUnitLoc(GetUnitRallyUnit(unit)) end)
overwrite("GetSpellTargetLoc", function() return LocXY(GetSpellTargetX(), GetSpellTargetY()) end)
overwrite("GetOrderPointLoc", function() return LocXY(GetOrderPointX(), GetOrderPointY()) end)
overwrite("BlzGetTriggerPlayerMousePosition", function() return LocXY(BlzGetTriggerPlayerMouseX(), BlzGetTriggerPlayerMouseY()) end)
local GUIGroup = {}
for i = 1, objectSize do GUIGroup[i] = CreateGroup() end
local GroupCounter = 0
local GroupCounterMax = #GUIGroup
local function GetGroup()
if GroupCounter >= GroupCounterMax then
GroupCounter = 1
else
GroupCounter = GroupCounter + 1
end
GroupClear(GUIGroup[GroupCounter])
return GUIGroup[GroupCounter]
end
overwrite("CreateGroup", function() return GetGroup() end)
overwrite("DestroyGroup", DoNothing)
local GUIForce = {}
for i = 1, objectSize do GUIForce[i] = CreateForce() end
local ForceCounter = 0
local ForceCounterMax = #GUIForce
overwrite("GetForceOfPlayer",function(player) return bj_FORCE_PLAYER[GetPlayerId(player)] end)
local function GetForce()
if ForceCounter >= ForceCounterMax then
ForceCounter = 1
else
ForceCounter = ForceCounter + 1
end
ForceClear(GUIForce[ForceCounter])
return GUIForce[ForceCounter]
end
overwrite("CreateForce", function() return GetForce() end)
overwrite("DestroyForce", DoNothing)
local GUIRect = {}
for i = 1, objectSize do GUIRect[i] = Rect(0,0,0,0) end
local RectCounter = 0
local RectCounterMax = #GUIRect
local r
local function GetRect(minx, miny, maxx, maxy)
if RectCounter >= RectCounterMax then
RectCounter = 1
else
RectCounter = RectCounter + 1
end
if minx then
SetRect(GUIRect[RectCounter], minx, miny, maxx, maxy)
end
return GUIRect[RectCounter]
end
overwrite("RectFromLoc", function(min, max)
r = GetRect()
SetRectFromLoc(r, min, max)
return r
end)
r = GetWorldBounds()
-- for whatever reason MaxX/MaxY are 32 smaller than expected
local WorldBounds = {GetRectMinX(r), GetRectMinY(r), GetRectMaxX(r), GetRectMaxY(r)}
RemoveRect(r)
r = nil
--print(table.unpack(WorldBounds))
overwrite("GetWorldBounds", function() return GetRect(table.unpack(WorldBounds)) end)
overwrite("Rect", function(minx, miny, maxx, maxy) return GetRect(minx, miny, maxx, maxy) end)
overwrite("RemoveRect", DoNothing)
udg_LeakPreventerEnable = CreateTrigger()
TriggerAddAction(udg_LeakPreventerEnable, function() enable(true) end)
udg_LeakPreventerDisable = CreateTrigger()
TriggerAddAction(udg_LeakPreventerDisable, function() enable(false) end)
enable(true)
-- end,print)
end
end
1.1 can now choose default amount of objects inside Leak preventer with a number, increased default to 64, mentions the Enable/Disable Feature in the head comment.
How to install:
Create a new Custom Script in trigger Editor
Name it Leak Preventer
Copy paste all Lua code from the Lua code Box above
Last edited: