• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Creep Respawn On Death

Status
Not open for further replies.
Level 6
Joined
Feb 10, 2005
Messages
223
Hello everyone,

I want to ask you people how to make a creep respawn within a certain area (for example if you got multiple areas with level 1-10, 10-20,20-30 creeps) after a certain time after its death (like ehh, 20 secs?) and so it will still drop certain items if I want too. So like the creep normally drops ehh lets say 5 gold, than after its respawned it will still drop 5 gold when he dies.

If there is already a post about this please link me, cause I couldnt find an appropiate one.

Yours sincerely,

Nazghul_Master
 
Level 15
Joined
Mar 31, 2004
Messages
860
I could link you to several systems at Wc3c but it is down.

Here's one system you could use and adapt (based on johnfn's, used in my KNIGHTS map).

An initialisation trigger to store custom vars to units on the map:
JASS:
function Trig_Init_Actions takes nothing returns nothing

   local unit p //will be used to loop through each of the creeps, along with
   local group g=GetUnitsOfPlayerAll(Player(PLAYER_NEUTRAL_AGGRESSIVE)) //this - the unit group of EACH creep (minus the ones already looped through, you'll see what I mean)
   local integer eachUnit=0 //and this - the number that represents each creep individually.

//init the creep structure
   loop
//this whole loop is the jass substitute for a For Each Unit In Group loop in GUI
         set p=FirstOfGroup(g) //sets p to the first unit in the group so that we can deal with it
         exitwhen (p==null) //if there are no more units, we're done with the loop so exit out of it
         set eachUnit = (eachUnit + 1) //but assuming there still are, increment the unit counter by one so it remains unique for the selected unit
         set udg_Location_of_monster[eachUnit] = GetUnitLoc(p) //set up 1 part of our array of locations corresponding to each unit
         set udg_Type_of_monster[eachUnit] = p //set up the array of creep types with the unit type of p
         call SetUnitUserData( p, eachUnit ) //set the custom value of the unit to eachUnit so that it is easily accessible later on

         call GroupRemoveUnit(g,p) //now that we've added it to the arrays, we don't need it in the group any more , so we get rid of it
    endloop    
    call DestroyGroup( g)
    set g = null

endfunction

//===========================================================================
function InitTrig_Init takes nothing returns nothing
    set gg_trg_Init = CreateTrigger(  )
    call TriggerRegisterTimerEventSingle( gg_trg_Init, 0.01 ) //run this trigger as the map initializes
    call TriggerAddAction( gg_trg_Init, function Trig_Init_Actions )
endfunction

And a trigger that is called when a unit dies:

JASS:
function Trig_Respawn_Monster_Actions takes nothing returns nothing
    local integer dyingUnitsCV
set dyingUnitsCV = GetUnitUserData(GetDyingUnit())
    // Set here because if i just used custom value of the dying unit below the wait, it could be a different dying unit.
    call TriggerSleepAction( 60.00 ) // This wait could be as long as you want it to be before the creeps respawn.
    call CreateNUnitsAtLoc( 1, GetUnitTypeId(udg_Type_of_monster[dyingUnitsCV]), Player(PLAYER_NEUTRAL_AGGRESSIVE), udg_Location_of_monster[dyingUnitsCV], bj_UNIT_FACING )


    call SetUnitUserData( GetLastCreatedUnit(), dyingUnitsCV) //set the CV back to the unit because it's lost when the unit dies
endfunction

//===========================================================================
function InitTrig_Respawn_Monster takes nothing returns nothing
    set gg_trg_Respawn_Monster = CreateTrigger(  )
    call TriggerRegisterPlayerUnitEventSimple( gg_trg_Respawn_Monster, Player(PLAYER_NEUTRAL_AGGRESSIVE), EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddAction( gg_trg_Respawn_Monster, function Trig_Respawn_Monster_Actions )
endfunction

Change the 60 to however long you want to wait (ie 20).
As for how much money they drop, you can define that in the unit editor for each units as normal.
 
Level 6
Joined
Feb 10, 2005
Messages
223
Do I just copy that in the trigger editor? Nothing to do elsewards? I just made my own little trigger which goes something like this:


triggerjw6.jpg


P.S. I forgot how to trigger most parts, since I stopped triggering for some point, I was kinda advanced but at the point where I had to use variables I lost it and stopped. So that's why I kinda 'de-learned' triggering.
 

Attachments

  • trigger.JPG
    trigger.JPG
    15.1 KB · Views: 255
Level 6
Joined
Feb 10, 2005
Messages
223
So to make it clear I just got to copy what U just stated? And if so, how can I convert a trigger to custom text? Sorry that I sound noobish btw

P.S. could you maybe just make the trigger work ingame FOR me? I know it takes more time and if more people ask you got no spare time, but please? I seriously suck at triggers like that hehe
 
Level 11
Joined
Jul 12, 2005
Messages
764
Two-line trigger:
  • Wait x seconds
  • Create unit at (Position of Triggering unit) ..
-> this will create the newest breed where the other died, and not where they should camp..

I wrote a script that does not require global variables, or multiple triggers, as it uses game cache (modified handle vars if you like..). Simply create a trigger called CreepRespawn, convert it to custom script, and replace the text you see there with this one. Then, set the respawn duration time in the second line of the script. You don't have to do anything else. It works flawlessly, i tested it.

Pros:
-Requires 1 trigger only
-Does not use global variables
-Does not uses the units' custom value
-Uses coordinates instead of locations --> leak free
-Revives creeps at their initial locations
-Also stores the initial facing of the creeps

Cons:
-I don't know if JASS would be a con, but some people don't like it

JASS:
constant function CreepRespawnDelay takes nothing returns real
    return 20.0    //The respawn duration in seconds -- set this!
endfunction


//---Creep Respawn System---
function CR_H2I takes handle h returns integer
    return h
    return 0
endfunction

function SetCreepRespawnPoints takes nothing returns nothing
    local group g = CreateGroup()
    local unit u = null
    call GroupEnumUnitsOfPlayer(g,Player(12),null)
    loop
        set u = FirstOfGroup(g)
        call GroupRemoveUnit(g,u)
        exitwhen u == null
        call StoreReal(InitGameCache("CR"), I2S(CR_H2I(u)), "RespawnX", GetUnitX(u))
        call StoreReal(InitGameCache("CR"), I2S(CR_H2I(u)), "RespawnY", GetUnitY(u))
        call StoreReal(InitGameCache("CR"), I2S(CR_H2I(u)), "RespawnFacing", GetUnitFacing(u))
    endloop
    call DestroyGroup(g)
    set g = null
endfunction

function RespawnCreeps takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local real x = GetStoredReal(InitGameCache("CR"), I2S(CR_H2I(u)), "RespawnX")
    local real y = GetStoredReal(InitGameCache("CR"), I2S(CR_H2I(u)), "RespawnY")
    local real f = GetStoredReal(InitGameCache("CR"), I2S(CR_H2I(u)), "RespawnFacing")
    call TriggerSleepAction(CreepRespawnDelay())
    set u = CreateUnit(Player(12), GetUnitTypeId(u), x, y, f)
    call StoreReal(InitGameCache("CR"), I2S(CR_H2I(u)), "RespawnX", x)
    call StoreReal(InitGameCache("CR"), I2S(CR_H2I(u)), "RespawnY", y)
    call StoreReal(InitGameCache("CR"), I2S(CR_H2I(u)), "RespawnFacing", f)
    set u = null
endfunction

//===========================================================================
function InitTrig_CreepRespawn takes nothing returns nothing
    call SetCreepRespawnPoints()
    set gg_trg_CreepRespawn = CreateTrigger()
    call TriggerRegisterPlayerUnitEvent(gg_trg_CreepRespawn, Player(12), EVENT_PLAYER_UNIT_DEATH, null)
    call TriggerAddAction(gg_trg_CreepRespawn, function RespawnCreeps)
endfunction
 
  • Like
Reactions: Rui
Level 11
Joined
Jul 12, 2005
Messages
764
So to make it clear I just got to copy what U just stated? And if so, how can I convert a trigger to custom text? Sorry that I sound noobish btw
OK i see... Create a trigger, rename it FIRST, then go to one of the menus (i can't remember which), and click "Convert to custom text". Delete the text you see there, and paste my script into the blank field. Fair enough??
 
Level 6
Joined
Feb 10, 2005
Messages
223
(sorry for double posting but I had to to show the post)

In the attachment you can see what error I get, but for people who cant read it:

Line 81: Expected a variable name
Line 82: Expected a name
Line 83: Expected a name
 

Attachments

  • picture.JPG
    picture.JPG
    233.5 KB · Views: 222
Level 6
Joined
Feb 10, 2005
Messages
223
I dont want it! I just want it to happen when I see a creep, I attack him, and he walks from his 'start point' towards me, and I kill him, he gets respawned at his original start point. With your trigger tht works fine, but for some reason it summons 'extra units' aswell! So it wont only summon the unit on his original start point, it will summon extra units TOO! It's not like this:

Unit dies - wait X seconds - respawn it at start point - Unit dies - wait x seconds etc.

but its more like

Unit dies - wait X seconds - respawn it at start point - Unit dies - wait x seconds - respawn it a start point + spawn 2 extra units

So I think there is something wrong with your JASS

EDIT: sorry, I forgot to remove my ollder version :$
 
Last edited:
Level 11
Joined
Jul 12, 2005
Messages
764
My trigger works. What do you think, i uploaded a WE-crashing trigger just to disturb you? It's not my problem that you cannot implement it. Is it really that hard? Just for the noobs:
-Create a trigger
-Rename it to CreepRespawn
-Convert it to custom text
-Replace everything with my script
4 steps man.. Don't attack me because you can't do that.
Also, learn to use the save button!
 

jak

jak

Level 1
Joined
Jun 26, 2007
Messages
3
Well im having a problem. i take your script and put in a trigger that was changed to custom script, but every time i try to save it keeps telling me that i have errors. so i ignor that and just go on to testing the map. Yet another problem arises. I cant PLAY the MAP!!
do you know what might be causing these problems?
 

jak

jak

Level 1
Joined
Jun 26, 2007
Messages
3
Well srry bout that, and here are the errors i get.

expected end of line:

loop set u = FirstOfGroup(g)



Unexpected exit when:
call StoreReal(InitGameCache("CR"), I2S(CR_H2I(u)), "RespawnX", GetUnitX(u))


Expected a code statement:

call StoreReal(InitGameCache("CR"), I2S(CR_H2I(u)), "RespawnX", GetUnitX(u))


expected a code expression:

set u = null endfunction

expected end of line:

call SetCreepRespawnPoints() set gg_trg_CreepRespawn = CreateTrigger()


expected a function name:

call InitTrig_CreepRespawn( )





by the way i used the creep system you attached to the other post and it work just fine so thank you for that.
 
Level 9
Joined
Jun 26, 2007
Messages
659
not the same: (end of line required after loop)
loop set u = FirstOfGroup(g)
Code:
    loop
        set u = FirstOfGroup(g)

not the same: (end of line required before endfunction)
set u = null endfunction
Code:
    set g = null
endfunction

not the same: (you've understand that return aren't randomly use now i think)
call SetCreepRespawnPoints() set gg_trg_CreepRespawn = CreateTrigger()
Code:
    call SetCreepRespawnPoints()
    set gg_trg_CreepRespawn = CreateTrigger()

and these point can maybe fix other ones!
first try this ;)
 
Last edited:
Level 3
Joined
Jul 8, 2006
Messages
26
This Works!

Thanks, Paskovich!
I've been looking for a working Creep Respawn trigger for a long time, and now I finaly have one that doesn't slow my map down like it takes half a minute for a second to pass (I have made one myself for a map, but all creeps respawn at the same time, and it took a LOT of patience to do. This I can use on any map). If you come up with a good trigger for level-based respawning (i.e a level one creep respawns in X seconds, a level 2 creep in 2X seconds, a level 3 creep in 3X seconds and so on), then post it here!
 
Status
Not open for further replies.
Top