• 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.

[Trigger] respawn does not work

Status
Not open for further replies.
Level 12
Joined
Jan 13, 2008
Messages
559
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • (Unit-type of (Triggering unit)) Equal to Copper Ore
    • Then - Actions
      • Wait (Random real number between 300.00 and 500.00) seconds
      • Set temp_CreepSpawnLoc = (Position of (Triggering unit))
      • Unit - Remove (Triggering unit) from the game
      • Unit - Create 1 Copper Ore for Neutral Passive at temp_CreepSpawnLoc facing (Random real number between 0.00 and 360.00) degrees
      • Custom script: call RemoveLocation(udg_temp_CreepSpawnLoc)
    • Else - Actions
This works just fine if I use a wait with 120 to 180 seconds but 300 to 500 doesnt. I set the decay time for structures to 50000 seconds inthe gameplay constants (the copper is a structure) and yet it wont respawn.
What am I missing?
 
Level 12
Joined
Jan 13, 2008
Messages
559
do you mean like this:
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • (Unit-type of (Triggering unit)) Equal to Copper Ore
    • Then - Actions
      • Custom script: local location udg_temp_CreepSpawnLoc
      • Wait (Random real number between 300.00 and 500.00) seconds
      • Game - Display to (All players) for 22222.00 seconds the text: asdfsadfsdf
      • Set temp_CreepSpawnLoc = (Position of (Triggering unit))
      • Unit - Remove (Triggering unit) from the game
      • Unit - Create 1 Copper Ore for Neutral Passive at temp_CreepSpawnLoc facing (Random real number between 0.00 and 360.00) degrees
      • Custom script: call RemoveLocation(udg_temp_CreepSpawnLoc)
      • Set TempUnit = (Last created unit)
      • Custom script: call UnitRemoveAbility(udg_TempUnit, 'Afih')
      • Custom script: call UnitRemoveAbility(udg_TempUnit, 'Afio')
      • Custom script: call UnitRemoveAbility(udg_TempUnit, 'Afiu')
      • Custom script: call UnitRemoveAbility(udg_TempUnit, 'Afin')
      • Custom script: call UnitRemoveAbility(udg_TempUnit, 'Afir')
    • Else - Actions
 
Level 16
Joined
Mar 25, 2016
Messages
1,327
First store the location to a local variable. Then wait and create a unit at this location.
Remove the used location (you only have to remove loc as it's the same as udg_temp_CreepSpawnLoc).
Null the local variable at the end. Local declarations must be at the beginning of a function.
You can use normal GUI remove ability actions here (except you are removing special abilities like move).
  • Trigger
    • Events
      • Unit - A unit Dies
    • Conditions
    • Actions
      • Custom script: local location loc = GetUnitLoc(GetTriggerUnit())
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit-type of (Triggering unit)) Equal to Footman
        • Then - Actions
          • Wait 452.00 seconds
          • Game - Display to (All players) the text: asdfsdf
          • Unit - Remove (Triggering unit) from the game
          • Custom script: set udg_temp_CreepSpawnLoc = loc
          • Unit - Create 1 Footman for Player 1 (Red) at temp_CreepSpawnLoc facing Default building facing degrees
          • -------- do whatever you want with the unit --------
        • Else - Actions
      • Custom script: call RemoveLocation(loc)
      • Custom script: set loc = null
 
Level 12
Joined
Jan 13, 2008
Messages
559
ah okay thank you. Btw another question and maybe you can help me.
  • Set numberOfTeams = (Real((Substring((Entered chat string), 5, (Length of (Entered chat string))))))
i want to recognize when a player types "-pve2" or "-pve 2" but with my trigger it only recognizes the number if I write "-pve2". "-pve 2" just returns 0 for the number. Why? when I replace 5 with 6 it works for "-pve 2" but not "-pve2" anymore..hmm
 
Level 16
Joined
Mar 25, 2016
Messages
1,327
"-pve2": number starts at position 5, "-pve 2" at 6. That's why it works like you said.
First of all: use integer instead of real (i guess you only want integers)
Either use 2 triggers or a trigger with an If-block to decide which of the two versions was used.
 
Level 12
Joined
Jan 13, 2008
Messages
559
i changed the trigger a bit and made a creep respawn system but it does not set the locals for some reason...i have not much experience with custom scripts but from what I know it should work?
On start of the map, i pick every unit from player 11 and set its custom value..so this part is working.
  • respawn mine monsters
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Owner of (Triggering unit)) Equal to Player 11 (Dark Green)
    • Actions
      • Custom script: local location loc = udg_TempLoc
      • Custom script: local integer cValue = 0
      • Custom script: local integer uid = 0
      • Set TempLoc = creep_respawn_locations[(Custom value of (Triggering unit))]
      • Cinematic - Ping minimap for (All players) at TempLoc for 1.00 seconds
      • Set tmp_integer = (Custom value of (Triggering unit))
      • Custom script: set loc = udg_TempLoc
      • Custom script: set cValue = udg_tmp_integer
      • Custom script: set uid = GetUnitTypeId(GetTriggerUnit())
      • Wait (Random real number between 240.00 and 300.00) seconds
      • Wait 10.00 seconds
      • Custom script: set udg_TempLoc = loc
      • Custom script: set udg_temp_unitType = uid
      • Unit - Create 1 temp_unitType for Player 11 (Dark Green) at TempLoc facing (Random real number between 0.00 and 360.00) degrees
      • Cinematic - Ping minimap for (All players) at TempLoc for 1.00 seconds
      • Custom script: set udg_tmp_integer = cValue
      • Unit - Set the custom value of (Last created unit) to tmp_integer
      • Custom script: call RemoveLocation(udg_TempLoc)
      • Custom script: call RemoveLocation(loc)
      • Custom script: set loc = null
 
Level 16
Joined
Mar 25, 2016
Messages
1,327
First line: local location loc = udg_TempLoc remove "= udg_TempLoc remove"
It does not need to be initialized at the beginning (the value is never used).
Remove the third last action: Custom script: call RemoveLocation(udg_TempLoc)
Both location variables reference the same part in the memory. You only need to remove it once. (you could also remove the second last action, but loc is shorter than udg_TempLoc, so you usually remove the shorter one)

Before the waits: set udg_TempLoc to null, so when using "call RemoveLocation(udg_TempLoc)" in another trigger, you do not accidently destroy the location.

Add debug messages.
 
Level 12
Joined
Jan 13, 2008
Messages
559
thanks. apparently there is already a mistake in the register trigger
  • register mine creeps
    • Events
      • Time - Elapsed game time is 1.00 seconds
    • Conditions
    • Actions
      • Set temp_UnitGroup = (Units owned by Player 11 (Dark Green))
      • Unit Group - Pick every unit in temp_UnitGroup and do (Actions)
        • Loop - Actions
          • Unit - Set the custom value of (Picked unit) to creep_respawn_value
          • Set TempLoc = (Position of (Picked unit))
          • Set creep_respawn_locations[creep_respawn_value] = TempLoc
          • Set creep_respawn_value = (creep_respawn_value + 1)
          • Custom script: call RemoveLocation(udg_TempLoc)
      • Custom script: call DestroyGroup(udg_temp_UnitGroup)
when TempLoc gets pinged (in the respawn trigger), its pinging somewhere else on the map but I am sure the register creeps trigger is correct..hm
 
Level 16
Joined
Mar 25, 2016
Messages
1,327
You must not use TempLoc here. Save it immediatly to creep_respawn_locations and do not remove the location.
You removed the location, so its null, which causes the game to use 0,0 as location.

You have one location (position of picked unit). A location is a reference variable, that points towards a certain part in the memory. Let's give this part the id 5.
You set TempLoc = Position of (Picked Unit), so TempLoc also has id 5.
You set creep_respawn_locations = TempLoc, so creep_respawn_locations also has id 5.

In the end you have two variables that point towards the same part in the memory (id 5).
Using RemoveLocation() frees up the part in the memory, which is referenced by the parameter.
Thus call RemoveLocation(udg_TempLoc) will free up the part with id 5. This makes both creep_respawn_locations and TempLoc have a null value, as they both point towards the part in the memory that was freed up.

You need to keep in mind, that not the variables leak, but the referenced part in the memory, if it is not freed up. Using RemoveLocation() you can free up this part. It does not do anything with the variable itself.
 
Level 12
Joined
Jan 13, 2008
Messages
559
ahh, I see. I didn't know it's just a reference. Now it works but only 2 times, then the location is somewhere else again. So I kill a unit, it respawns correct, i kill it again, respawns correct and then kill it again and it doesnt respawn anymore and the location is again somewhere random (it pings). I guess I have to take a better look at the respawn trigger..something is wrong there. Maybe I shouldnt remove the location or set it null.
 
Level 16
Joined
Mar 25, 2016
Messages
1,327
Ah yeah sure. It's the same there. You should not remove a location, if it is the same reference as the creep_respawn_locations variable, so you should remove all remove_locations in your trigger. A simple rule (not always right though): Whenever you create a location you also need to remove it when you no longer need it.
TempLoc=creep_respawn_locations does not create a location, as it already exists (in creep_respawn_locations obviously)
TempLoc=Point(0,0) creates a location and should be removed when you no longer need it

In your initialization trigger you create a lot of locations, but since they are needed for the entire game, you do not remove them.

Local reference variables must always be nulled. There is no exception to it (atleast I don't know anything about it).

If you use:
TempLoc=Point(0,0) you create a location and TempLoc points towards this location.
call RemoveLocation(udg_TempLoc) will destroy the location (referenced part in the memory), but the variable still points to the part in the memory.
Before this part can be used again, it must not be referenced by anything. Because of this you need to null variables (so they no longer reference this part in the memory).
You do not need to do this with global variables, as they will no longer point towards this part in the memory, if you use them another time.
So basically a global variable will have one reference leak (it is not a leak by definition, as it can be removed), when it is not used (as it still points towards the last used part in the memory by the variable). You could prevent it by nulling the variable, but one reference leak per global is neglectable.
The difference with local variables is, that the same variable (loc in this case) is used multiple times (whenever the trigger runs). If you do not null it, you will have one reference leak (leak by definition, cannot be removed) per execution of the trigger.
 
Level 12
Joined
Jan 13, 2008
Messages
559
i see. thanks for the help/explanation. Things are much more clear now. I changed the trigger a bit and everything works fine now :)
  • respawn mine monsters
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Owner of (Triggering unit)) Equal to Player 11 (Dark Green)
    • Actions
      • Custom script: local location loc
      • Custom script: local integer cValue = 0
      • Custom script: local integer uid = 0
      • Set tmp_integer = (Custom value of (Triggering unit))
      • Custom script: set cValue = udg_tmp_integer
      • Custom script: set loc = udg_creep_respawn_locations[cValue]
      • Custom script: set uid = GetUnitTypeId(GetTriggerUnit())
      • Wait (Random real number between 240.00 and 300.00) seconds
      • Custom script: set udg_RespawnLoc = loc
      • Custom script: set udg_temp_unitType = uid
      • Unit - Create 1 temp_unitType for Player 11 (Dark Green) at RespawnLoc facing (Random real number between 0.00 and 360.00) degrees
      • Custom script: set udg_tmp_integer = cValue
      • Unit - Set the custom value of (Last created unit) to tmp_integer
      • Custom script: set loc = null
 
Level 16
Joined
Mar 25, 2016
Messages
1,327
Looks good now. You do not necessarily need RespawnLoc. You can also do it with TempLoc. Just null it after you have used it (so you do not accidently remove it when you use RemoveLocation(udg_TempLoc) in another trigger). But that's of course only if you want to reduce the variables you use.
 
Status
Not open for further replies.
Top