muzzel
New Member
- Reaction score
- 1
I created a creep revivel system for an orpg which revives dying creeps at the spot where they originally were placed, but im not sure whether its performant and doesnt cause laggs or something else.
The Idea: Save the positions of the creeps in an array and save the index as customvalue. After death, create a new unit at the same spot.
I also thought about attaching the position as a struct, but I dont know which way is faster/better.
My Code:
Please comment
The Idea: Save the positions of the creeps in an array and save the index as customvalue. After death, create a new unit at the same spot.
I also thought about attaching the position as a struct, but I dont know which way is faster/better.
My Code:
JASS:
scope creeprevive initializer Init
globals
real array creepX[2000]
real array creepY[2000]
real array creepFace[2000]
endglobals
private function ReviveTime takes unit creep returns real
return 20.00
endfunction
private function SetCV takes unit creep, integer i returns nothing
call SetUnitUserData(creep, i)
endfunction
private function GetCV takes unit creep returns integer
return GetUnitUserData(creep)
endfunction
private function Conditions takes nothing returns boolean
return ((GetOwningPlayer(GetFilterUnit()) == Player(9)) and (IsUnitType(GetFilterUnit(), UNIT_TYPE_HERO) == false))
endfunction
private function SetupConditions takes nothing returns boolean
return true
endfunction
private function Actions takes nothing returns nothing
local unit creep = GetDyingUnit()
local unit newCreep
local integer creepType = GetUnitTypeId(creep)
local real posX = creepX[GetCV(creep)]
local real posY = creepY[GetCV(creep)]
local real face = creepFace[GetCV(creep)]
local integer cv = GetCV(creep)
call TriggerSleepAction(ReviveTime(creep))
set newCreep = CreateUnit(Player(0), creepType, posX, posY, face)
call SetCV(newCreep, cv)
set creep = null
endfunction
private function SetupActions takes nothing returns nothing
local group all
local integer i = 0
local unit tempunit
set all = GetUnitsInRectAll(GetPlayableMapRect())
loop
set tempunit = FirstOfGroup(all)
exitwhen tempunit == null
call SetCV(tempunit, i)
set creepX<i> = GetLocationX(GetUnitLoc(tempunit))
set creepY<i> = GetLocationY(GetUnitLoc(tempunit))
set creepFace<i> = GetUnitFacing(tempunit)
set i = i + 1
call GroupRemoveUnit(all, tempunit)
endloop
endfunction
private function Init takes nothing returns nothing
local trigger t = CreateTrigger()
local trigger setup = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_DEATH)
call TriggerAddCondition(t, Condition(function Conditions))
call TriggerAddAction(t, function Actions)
call TriggerRegisterTimerEventSingle(setup, 3.00)
call TriggerAddCondition(setup, Condition(function SetupConditions))
call TriggerAddAction(setup, function SetupActions)
endfunction
endscope
</i></i></i>
Please comment