HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Creep respawn system (i did search)

06-22-2006, 09:31 PM#1
ElvenTitz
I''ve searched nearly the whole forum but failed to find a good working creep respawn system without leaks etc, well i personally use simple jass script in my map that detects the even when a unit dies, store it type and point in local varibles then waits and recreates them at the point the unit died.
Well it was the only thing i was able to do, but in fact - i want more from respawn in my map, but im unable to do that by myself. I've searched the whole forum but the systems i found are either too complixated (like vex's one that require to install whole caster system that i dont need at all or contains leaks / dont do thouse simple things that i need). Oh, and local varibles wont last long enought, something happens to them and they stop work (either they are cleared or something), dont know, im not that good with jass and stuff.
Ok - i need from caster system to do a few things -
Respawn a unit of ceretain type in original point 180 seconds after his death. - various unit types has various respawn delay. (also it should repawn the unit where it was staying when the map been created, not the place it died)
thats all what i want from the system.
Well, any kind of help would be appreticated.
Again, im sorry if this question was answered alredy but i searched and failed to find any solution.
add- i wronged myself, by creeps i meant units that are actually under player 12 controll, but its irrelevant anyways. And i dont need to respawn all units, only of certain unit types with different delays for every unit type.
06-22-2006, 11:59 PM#2
PipeDream
Here's a generic set of functions for non leaking unit events with respawning as an example.

Collapse JASS:
globals
    gamecache udg_gc
endglobals

function GC takes nothing returns gamecache
    return udg_gc
endfunction

function HtoI takes handle h returns integer
    return h
    return 0
endfunction

function ItoTA takes integer i returns triggeraction
    return i
    return null
endfunction

function ItoU takes integer i returns unit
    return i
    return null
endfunction

function killta takes nothing returns nothing
    call TriggerRemoveAction(GetTriggeringTrigger(),ItoTA(GetStoredInteger(GC(),I2S(HtoI(GetTriggeringTrigger())),"ta")))
endfunction

function OnUnitEvent_cb takes nothing returns nothing
    local trigger t = GetTriggeringTrigger()
    local string key = I2S(HtoI(t))
    local boolean repeat = GetStoredBoolean(GC(),key,"repeat")
    local string callback = GetStoredString(GC(),key,"callback")
    call ExecuteFunc(callback)
    if(not repeat) then
        call ExecuteFunc("killta")
        call FlushStoredMission(GC(),key)
        call DestroyTrigger(t)
    endif
    set t = null
endfunction

function OnUnitEvent takes unit u, unitevent e, string f, boolean repeat returns nothing
    local trigger t = CreateTrigger()
    local string key = I2S(HtoI(t))
    local triggeraction ta = TriggerAddAction(t,function OnUnitEvent_cb)
    call StoreString(GC(),key,"callback",f)
    call StoreInteger(GC(),key,"ta",HtoI(ta))
    call StoreBoolean(GC(),key,"repeat",repeat)
    call StoreInteger(GC(),key,"unit",HtoI(u))
    call TriggerRegisterUnitEvent(t,u,e)
    set t = null
    set ta = null
endfunction

function OnUnitDeath takes unit u, string f returns nothing
    call OnUnitEvent(u,EVENT_UNIT_DEATH,f,false)
endfunction

//Since we don't have a list / array standard yet attach data to trigger
function CreateRespawningUnit takes player p, integer unitid, real x, real y, real facing, real delay returns nothing
    local unit u = CreateUnit(p,unitid,x,y,facing)
    local string key = I2S(HtoI(u))
    call StoreInteger(GC(),key,"respawn_player",GetPlayerId(p))
    call StoreInteger(GC(),key,"respawn_unitid",unitid)
    call StoreReal(GC(),key,"respawn_x",x)
    call StoreReal(GC(),key,"respawn_y",y)
    call StoreReal(GC(),key,"respawn_facing",facing)
    call StoreReal(GC(),key,"respawn_delay",delay)
    call OnUnitDeath(u,"Respawn_cb")
    set u = null
endfunction

function Respawn_cb takes nothing returns nothing
    local trigger t = GetTriggeringTrigger()
    local string tkey = I2S(HtoI(t))
    local unit u = ItoU(GetStoredInteger(GC(),tkey,"unit"))
    local string ukey = I2S(HtoI(u))
    local integer p = GetStoredInteger(GC(),ukey,"respawn_player")
    local integer unitid = GetStoredInteger(GC(),ukey,"respawn_unitid")
    local real x = GetStoredReal(GC(),ukey,"respawn_x")
    local real y = GetStoredReal(GC(),ukey,"respawn_y")
    local real facing = GetStoredReal(GC(),ukey,"respawn_facing")
    local real delay = GetStoredReal(GC(),ukey,"respawn_delay")
        set t = null
    call FlushStoredMission(GC(),ukey)
    set u = null
    call PolledWait(delay)    //Lazy but just fine for 180 seconds
    call CreateRespawningUnit(Player(p),unitid,x,y,facing,delay)
endfunction

Not installing a system* because you don't need everything is silly. The cost to importing the whole thing is tiny and you will discover all sorts of things you never knew you would need. Then, later, you can strip it down when you have a better sense of what is possible.

*Disclaimer: I don't know what's in Vex's caster system. One of these days...
06-23-2006, 05:13 AM#3
ElvenTitz
@PipeDram
Thank you, but couldnt you make yourself a little more clear and add a trigger that calls to these functions.
06-23-2006, 05:54 AM#4
PipeDream
Set udg_gc to your game cache. if you don't know what that means add to your initialization:
Collapse JASS:
set udg_gc = InitGameCache("attachedvars.w3v")
The function you want to use is CreateRespawningUnit, and you use it just like CreateUnit with an extra delay parameter (units are seconds) on the end. If this still doesn't make sense, it's time to hit the books
http://www.wc3campaigns.net/forumdisplay.php?f=426
http://www.wc3campaigns.net/forumdisplay.php?f=650
06-23-2006, 08:27 AM#5
ElvenTitz
What are other functions for ? I have simple jass skills but i dont understand -.-
I get that create respawn unit will create a unit that i want, but how would i getunitloc that wont expire in 180 seconds ? I guess the other functions you gave me are for this purpose, but help me ,how to use them ?
Please, make a simple trigger with unit death event that will show how all this functions work together. How would it be on original place?
I mean how to activate the whole thing?

How Do i split getunitloc in two reals x and y anyways. sry for question that might sound too simple.
06-23-2006, 08:59 AM#6
PipeDream
<merged double post>

There are several natives for this purpose. You can find them in common.j which you can extract from War3Patch.mpq with tools such as winmpq or mpqmaster.
This would be a good place to start: http://www.wc3campaigns.net/showthread.php?t=83337
06-23-2006, 09:01 AM#7
ElvenTitz
Wow, it works but it only respawn unit at the location they died, i think i just call this function incorrectly.
add - yes, i found thouse natives, but i cant get how to make them respawn at their original location.
add-
Here what i do :
call CreateRespawningUnit( Player(11), GetUnitTypeId(GetDyingUnit()), GetLocationX(GetUnitLoc(GetDyingUnit())),GetLocationY(GetUnitLoc(GetDyingUnit())) , GetUnitFacing(GetDyingUnit()), I2R(180) )
however it dosnt wait, it respawns unit immidatly !
to prevent further question, please, post a simple trigger that show how it supposted to work.
06-23-2006, 12:12 PM#8
Freakazoid
There is an Creep respawn system in my RPG system, made in GUI. You can also use this one.

Collapse JASS:
function Trig_Revive_Creeps_Actions takes nothing returns nothing
    local integer CUSTOM
    set CUSTOM = GetUnitUserData(GetDyingUnit())
    call TriggerSleepAction( udg_Hostile_Revive_Time )
    call CreateNUnitsAtLoc( 1, udg_Creep_Types[CUSTOM], Player(PLAYER_NEUTRAL_AGGRESSIVE), udg_Creep_Positions[CUSTOM], bj_UNIT_FACING )
    call SetUnitUserData( GetLastCreatedUnit(), CUSTOM )
endfunction

//===========================================================================
function InitTrig_Revive_Creeps takes nothing returns nothing
    set gg_trg_Revive_Creeps = CreateTrigger(  )
    call TriggerRegisterPlayerUnitEventSimple( gg_trg_Revive_Creeps, Player(PLAYER_NEUTRAL_AGGRESSIVE), EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddAction( gg_trg_Revive_Creeps, function Trig_Revive_Creeps_Actions )
endfunction

But it doesn't work on the heroes correctly.

But you also need this trigger.

Collapse JASS:
function Trig_Store_Creeps_Func003A takes nothing returns nothing
    set udg_Creep_Types[udg_LoopCreep] = GetUnitTypeId(GetEnumUnit())
    set udg_Creep_Positions[udg_LoopCreep] = GetUnitLoc(GetEnumUnit())
    call SetUnitUserData( GetEnumUnit(), udg_LoopCreep )
    set udg_LoopCreep = ( udg_LoopCreep + 1 )
endfunction

function Trig_Store_Creeps1_Actions takes nothing returns nothing
    set udg_LoopCreep = 0
    call ForGroupBJ( GetUnitsOfPlayerAll(Player(PLAYER_NEUTRAL_AGGRESSIVE)), function Trig_Store_Creeps_Func003A )
    call DestroyGroup(bj_lastCreatedGroup)
endfunction

//===========================================================================
function InitTrig_Store_Creeps takes nothing returns nothing
    set gg_trg_Store_Creeps = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Store_Creeps, function Trig_Store_Creeps_Actions )
endfunction

06-23-2006, 12:16 PM#9
ElvenTitz
Well, thank you for help, i've done it and it works now. I didnt use anything in this topic but i still give people reps for effort.
06-23-2006, 12:29 PM#10
PipeDream
No, no goddamn triggers. The whole point of this was to completely abstract away the trigger. It's a completely transparent interface which you use exactly like CreateUnit. You only have to write one line:
Collapse JASS:
call CreateRespawningUnit(Player(11),'hfoo',100,0,36,180)
That's *all* the code and *all* the data. FINITO.

Freakazoid's system is nice too, and could be adapted for your purposes. He takes a top down approach. BTW Freak you want to use PolledWait/Wait game time instead of TriggerSleepAction() to avoid abuses with pause, lag, and who knows what else.

<edited to add the delay on the end. But you knew that, since you tested it.>
06-23-2006, 01:01 PM#11
ElvenTitz
@pd
if i will exact same string you presented above - it wont work coz compilation error saying - not enought arguments or something like that. And where should i add it anyways.
@freakazoid
i see the only problem in your system that if you make Hostile_Revive_Time too big you local CUSTOM's value will be lost. Or im wrong?