GetTriggerUnit-
DogEntrepreneur
- Reaction score
- 129
JIS - Jass Indexing Snippet
by GetTriggerUnit-
by GetTriggerUnit-
What is it?
- JIS is an indexing system that set the custom value of every unit entering the map automaticly. When a unit die or is removed, it custom value is recycled and re-used.
- It can store a maximum of 8190 unit at a time on a
- It's leakless, lagless and MUI of course.
- It can store a maximum of 8190 unit at a time on a
- It's leakless, lagless and MUI of course.
How does it work?
-Simply use the custom value of a unit
-Do not set the custom value of a unit, it's done automaticly
-When a unit die, it automaticly recycle it value.
Why use this one instead of another?
At start, I have made this one for the ones that can't / do not , want to use NewGen. It work like anyother system indexing system, without any requirement.
Code-Do not set the custom value of a unit, it's done automaticly
-When a unit die, it automaticly recycle it value.
Why use this one instead of another?
At start, I have made this one for the ones that can't / do not , want to use NewGen. It work like anyother system indexing system, without any requirement.
JASS:
//--------------------------------------------------------------------------------------------+
// JIS - Jass Indexing Snippet |
// |
// What is it? |
// - JIS is an indexing system that set the custom value of every unit entering the |
// map automaticly. When a unit die or is removed, it custom value is recycled and |
// re-used. |
// - It can store a maximum of 8190 unit at a time on a map. |
// - It's leakless, lagless and MUI of course. |
// |
// How to use? |
// - Simply use "Custom value of unit" Jass(GetUnitUserData) |
// - Do not set the custom value, the value locking part is not done yet. |
// |
// Why use it? |
// - To avoid sereval units to have the custom value. In a spell, if you use the |
// Mui count, 2 units may end-up with the same value. If there's many spells/systems |
// using custom values running at a same time, it can bug. With this, simply use |
// custom value without setting it. If you set it, it might bug. |
// |
// How to Implement? |
// - Create a new trigger called JSI, paste all this script code in, and create a |
// global variable called JIS_Recycle of type boolean and array |
// |
//--------------------------------------------------------------------------------------------+
function JIS_OnInit takes nothing returns nothing
local integer count = 0
local integer start = 0
local group g = CreateGroup()
local unit u
loop
set start = start + 1
set udg_JIS_Recycle[start] = false
exitwhen start == 8190
endloop
call GroupEnumUnitsInRect(g, GetPlayableMapRect(), null)
loop
set u = FirstOfGroup(g)
exitwhen u == null
set count = count + 1
set udg_JIS_Recycle[count] = true
call SetUnitUserData(u, count)
call GroupRemoveUnit(g, u)
endloop
call DestroyGroup(g)
endfunction
function JIS_OnCreate takes nothing returns nothing
local integer count = 0
loop
set count = count + 1
if udg_JIS_Recycle[count] == false then
call SetUnitUserData(GetTriggerUnit(), count)
set udg_JIS_Recycle[count] = true
return
endif
exitwhen count == 8190
endloop
endfunction
function JIS_Filter takes nothing returns boolean
return (GetUnitUserData(GetFilterUnit()) == GetForLoopIndexA())
endfunction
function JIS_OnRemove takes nothing returns nothing
local group g
local unit u
set bj_forLoopAIndex = 0
loop
set g = CreateGroup()
set bj_forLoopAIndex = bj_forLoopAIndex + 1
if udg_JIS_Recycle[bj_forLoopAIndex] == true then
call GroupEnumUnitsInRect(g, GetPlayableMapRect(), Condition(function JIS_Filter))
if CountUnitsInGroup(g) == 0 then
set udg_JIS_Recycle[bj_forLoopAIndex] = false
endif
endif
call DestroyGroup(g)
exitwhen bj_forLoopAIndex == 8190
endloop
call DestroyGroup(g)
endfunction
// Init function
function InitTrig_JIS takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerAddAction(t, function JIS_OnInit)
call TriggerRegisterTimerEventSingle(t, 0.00)
set t = CreateTrigger()
call TriggerRegisterEnterRectSimple(t, GetPlayableMapRect())
call TriggerAddAction(t, function JIS_OnCreate)
set t = CreateTrigger()
call TriggerRegisterTimerEventPeriodic(t, 0.25)
call TriggerAddAction(t, function JIS_OnRemove)
endfunction