HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

The Creep Respawn System

03-12-2006, 03:06 PM#1
Doomknight
Vex, I was wondering if you can show us how to make that creep respawn system you used for your demo maps?

I tried isolating the trigger, but I didn't know how.
03-12-2006, 06:35 PM#2
Vexorian
I had a function for that let me look for it
03-12-2006, 07:05 PM#3
Vexorian
Collapse JASS:
function CreepRespawn_CampLength takes nothing returns real
    return 500.0
    // Area a camp takes
endfunction

function CreepRespawn_WaitTime takes nothing returns real
    return 30.0
    // Wait time before respawning a camp (seconds)
endfunction

function CreepRespawn_Effect takes unit u returns nothing
    call DestroyEffect( AddSpecialEffectTarget( "Abilities\\Spells\\Human\\MassTeleport\\MassTeleportCaster.mdl", u, "origin"))
endfunction

function CreepRespawn_OnDeath takes nothing returns nothing
 local unit u=GetTriggerUnit()
 local string uk=GetAttachmentTable(u)
 local integer ki=GetTableInt("[CreepRespawn]",uk)
 local string k
 local integer typeid = GetUnitTypeId(u)
 local group camp
 local real x
 local real y
 local real f
 local rect r=bj_mapInitialPlayableArea
    if (ki==0) then
    else
        set k=I2S(ki)
        set x =GetTableReal(k,"sx")
        set y =GetTableReal(k,"sy")
        set f =GetTableReal(k,"sf")
        set camp=GetTableGroup(k,"camp")

        call GroupRemoveUnit(camp,u)
        loop
            exitwhen FirstOfGroup(camp)==null
            call TriggerSleepAction(1)
        endloop
        call PolledWait(CreepRespawn_WaitTime())
        if IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO) then
            call SetUnitOwner( u, Player(1), false)
            call ReviveHero( u, x, y, true)
            call SetUnitOwner( u, Player(12), false)
            call GroupAddUnit(camp,u)
        else
            
            call SetTableInt("[CreepRespawn]",uk,0)
            set u=CreateUnit( Player(12), typeid, x,y,f )
            //By the magic of tables we just need to assign the old table for the new unit
            call SetTableInt("[CreepRespawn]",GetAttachmentTable(u),ki)
            call CreepRespawn_Effect(u)
            call GroupAddUnit(camp,u)
        endif
    endif
 set camp=null
 set u=null
 set r=null
endfunction

function CreepRespawn_Setup_Filter takes nothing returns boolean
    return IsUnitOwnedByPlayer( GetFilterUnit(), Player(12) ) and IsUnitInGroup(GetFilterUnit(),bj_groupRemoveGroupDest)
endfunction

function CreepRespawn_Setup takes nothing returns trigger
 local trigger t = CreateTrigger()
 local boolexpr B=Condition(function CreepRespawn_Setup_Filter)
 local group r=CreateGroup()
 local group aux=CreateGroup()
 local group aux2=CreateGroup()
 local group c
 local unit u
 local string uk
 local string k
 local integer ki
    call GroupEnumUnitsOfPlayer(r,Player(12), null)
    set bj_groupRemoveGroupDest=r
    loop
        set u=FirstOfGroup(r)
        exitwhen u==null
        call GroupRemoveUnit(r,u)
        set c=CreateGroup()
        set bj_groupAddGroupDest=c
        call GroupClear(aux)
        loop
            call GroupClear(aux2)
            call GroupEnumUnitsInRange(aux2,GetUnitX(u),GetUnitY(u),CreepRespawn_CampLength(),B)
            call GroupAddGroup(aux2,aux)
            call GroupRemoveUnit(aux,u)
            call GroupRemoveUnit(r,u)
            call GroupAddUnit(c,u)
            set uk=GetAttachmentTable(u)
            set ki=NewTableIndex()
            set k=I2S(ki)
            call SetTableInt("[CreepRespawn]",uk,ki)
            call SetTableReal(k,"sx", GetUnitX(u) )
            call SetTableReal(k,"sy", GetUnitY(u) )
            call SetTableReal(k,"sf", GetUnitFacing(u) )
            call SetTableObject(k,"camp",c)
            set u=FirstOfGroup(aux)
            exitwhen u==null
        endloop
    endloop
 call DestroyGroup(r)
 call DestroyGroup(aux)
 call DestroyGroup(aux2)
 call DestroyBoolExpr(B)
 set B=null
 set r=null
 set aux=null
 set aux2=null
 call TriggerRegisterPlayerUnitEvent( t, Player(12), EVENT_PLAYER_UNIT_DEATH,null )
 call TriggerAddAction( t, function CreepRespawn_OnDeath )
 return t
endfunction
03-12-2006, 07:09 PM#4
Doomknight
Thanks a million, man
03-12-2006, 07:49 PM#5
Doomknight
Bah, noob question: How would I implement it into my map?


When I enter it directly, WE reports many errors. What should I do to turn it into something that the WE says is Ok?
03-13-2006, 11:32 AM#6
Vexorian
requires either the caster system or CSCache module.

Also after adding it to the custom script section you have to call ExecuteFunc("CreepRespawn_Setup") on an initialization trigger
03-13-2006, 02:27 PM#7
Doomknight
Awesome. It is now up and working with players 7 and 12.
03-13-2006, 03:18 PM#8
emjlr3
not downing Vex at all, obviously, but that seems like a bit much to just revive creeps ( with needing those big ol triggers and the caster system), have you looked at my Begginers Demo Map in the resource section?
03-13-2006, 06:22 PM#9
Vexorian
It does not just revive creeps. It revives creep camps - the difference is that it will wait till a creep camp is dead before reviving any of the creeps that belong to that creep camp.

That script is seriously small anyways

And caster system is my standard and in this case is only used for tables/gamecache.

Any creep reviving system would be lame if it didn't use gamecache it would end up reviving creeps on the points where their last incarnation died instead of reviving them on the position they were preplaced.
03-14-2006, 05:02 AM#10
FriendlyWarlord
Quote:
Any creep reviving system would be lame if it didn't use gamecache it would end up reviving creeps on the points where their last incarnation died instead of reviving them on the position they were preplaced.

Couldn't help noticing the thread, after making a creep respawn system with GUI. At initialization it makes an invisible building for each creep, and when a creep dies, the building starts training a new unit. It was hugely more elaborate than that, but that's the gist of it. I'd bet Vex's is a lot more efficient though
03-15-2006, 11:49 PM#11
Ares_WarBlade
I'm a total triggering noob so bear with me if I sound completely igorant. (I admit I am.) I downloaded your caster system Vex, I brought the required variables and whatnot in with no problems. I put this script on my map but I keep getting this message: "The trigger 'Respawn' must have an initialization function called 'InitTrig_Respawn.' Well, when I go:

Trigger:
Collapse Events
Map Initialization
Collapse Actions
Custom script: call ExecuteFunc("InitTrig_respawn")

I get a fatal error whenever I try to test the map. x_x

Is there an FAQ on how to use this stuff somewhere?
03-16-2006, 12:31 AM#12
Vexorian
you are so wrong it actually scares me.
  • The functions I posted go to the Custom Script section (bellow the caster system) NOT to a trigger (unless you know what you are doing and it seems you do not.
  • Use call ExecuteFunc("CreepRespawn_Setup") don't change the contents that will cause a crash.
03-16-2006, 01:15 AM#13
Ares_WarBlade
Rofl, Okay, I see what I did. I didn't see how long the readme was because of the misshapen way my trigger editor was at. I got it working fine now, thanks!