Quick Question Respawn Trigger

Status
Not open for further replies.
Level 11
Joined
Aug 6, 2009
Messages
697
I tried making a respawn trigger that gives the dead unit a 30 second timer, then when the 30 second timer expires it revives the unit in the position it died in.
I haven't worked with hashtables for 6 months so i kind of forgot them.
This doesn't work, can someone find the problem please?

Trigger 1:
  • Respawn
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Dying unit)) Equal to Saibaman
    • Actions
      • Set RespawnDyingUnit = (Dying unit)
      • Custom script: set udg_ID = GetHandleId (udg_RespawnDyingUnit)
      • Set RespawnTimer = 30.00
      • Hashtable - Save Handle Of(Position of (Dying unit)) as 0 of ID in RespawnHash
      • Hashtable - Save RespawnTimer as 1 of ID in RespawnHash
      • Unit Group - Add RespawnDyingUnit to RespawnGroup
Trigger 2:
  • RespawnLoop
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in RespawnGroup and do (Actions)
        • Loop - Actions
          • Custom script: set udg_ID = GetHandleId(GetEnumUnit())
          • Set LocRespawn = (Load 0 of ID in RespawnHash)
          • Set RespawnTimer = (Load 1 of ID from RespawnHash)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • RespawnTimer Greater than 0.00
            • Then - Actions
              • Hashtable - Save (RespawnTimer - 1.00) as 1 of (Key (Picked unit)) in RespawnHash
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • RespawnTimer Equal to 0.00
                • Then - Actions
                  • Hero - Instantly revive (Picked unit) at LocRespawn, Hide revival graphics
                  • Unit Group - Remove (Picked unit) from RespawnGroup
                  • Hashtable - Clear all child hashtables of child ID in RespawnHash
                • Else - Actions
 
use triggering unit instead of dying unit

put these in the else block instead of another if block
  • Hero - Instantly revive (Picked unit) at LocRespawn, Hide revival graphics
    • Unit Group - Remove (Picked unit) from RespawnGroup
    • Hashtable - Clear all child hashtables of child ID in RespawnHash
dont load the location everytime the periodic trigger runs only load it when reviving the unit

this
  • Hashtable - Save (RespawnTimer - 1.00) as 1 of (Key (Picked unit)) in RespawnHash
should be ID but since u dont use JNGP u dont need the custom script either

try to put some messages in there to see were it goes wrong
 
You don't need all of that, just a simple local variable and you're done;
  • Revive Timer
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Saibaman
    • Actions
      • Custom script: local unit u = GetTriggerUnit()
      • Custom script: local real x = GetUnitX(u)
      • Custom script: local real y = GetUnitY(u)
      • Wait 30.00 seconds
      • Custom script: call ReviveHero(u, x, y, false)
      • Custom script: set u = null
Here's a test map.
 

Attachments

@deathismyfriend, defskull

Waits are great when it comes to effects and other things that doesn't affect gameplay. Especially short waits. Long waits should be avoided because they don't take lag/waiting for players into consideration (i.e. they can expire a heck lot quicker than you intended them to do).

Actually, wait game-time would work decently.

This doesn't work, can someone find the problem please?

Your problem is this:

  • RespawnTimer Equal to 0.00
You are using real as a data type. Real is not exact; so 30.0 - 1.0 - 1.0 - 1.0... etc will not be exactly equal to 0.00.

You should use less than or equal to (or just put it in the else block, like deathismyfriend suggested).

  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
  • If - Conditions
    • RespawnTimer Greater than 0.00
  • Then - Actions
    • Hashtable - Save (RespawnTimer - 1.00) as 1 of (Key (Picked unit)) in RespawnHash
  • Else - Actions
    • Hero - Instantly revive (Picked unit) at LocRespawn, Hide revival graphics
    • Unit Group - Remove (Picked unit) from RespawnGroup
    • Hashtable - Clear all child hashtables of child ID in RespawnHash
 
i always forget about the lag / waiting for players thing with waits. thx for that note. mybe ill remember it one of these times lol. i personally always use timers tho i like the accuracy. i wonder y reals are so inaccurate that when u subtract 1.0 from them that it wont be exactly 0.00 lol but thats y u always use greater than or equal to or less than or equal to to avoid bugs like this. also using integers is easier anyways so y not use them lol
 
You don't need all of that, just a simple local variable and you're done;
  • Revive Timer
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Saibaman
    • Actions
      • Custom script: local unit u = GetTriggerUnit()
      • Custom script: local real x = GetUnitX(u)
      • Custom script: local real y = GetUnitY(u)
      • Wait 30.00 seconds
      • Custom script: call ReviveHero(u, x, y, false)
      • Custom script: set u = null
Here's a test map.

This isn't MUI though?
 
defskull said:
Waits with local variable is forgiven.

Perhaps I was not clear enough...?

Themerion said:
...Long waits should be avoided because they don't take lag/waiting for players into consideration (i.e. they can expire a heck lot quicker than you intended them to do).

Please allow me to elaborate:

In the worst caste scenario, the "waiting for players"-dialog will show up 1 second after wait started. Let's imagine that it lasts for 29 seconds or more. Now the wait will expire as soon as the dialog disappears, that is, after 1 second of game time (instead of 30...)

That would be incredibly unfair in this case, since it would cause someone's hero to respawn almost instantly.
 
defskull said:
By the power vested in me, themerion, do him a test map using either Indexing or Hashtable method, your call.

Sure, if there are further problems. I already pointed out what was wrong with the initial hashtable approach, and believe it should work when working around the reals. If that is not the case, I expect the author to post in this thread again.
 
Alright guys, sorry that I haven't replied, I've been busy with exams and studying. Okay so, I put some debug messages in the functions and all the messages showed so it worked. However, the unit still doesn't revive? Perhaps it's too late to revive the unit?

Edit:
Alright so I ended up doing something different, turns out the "revive hero" function doesn't like to work with hashtables.
So I decided to just create the hero and give it the xp.

  • Respawn
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Dying unit)) Equal to Saibaman
    • Actions
      • Game - Display to (All players) for 30.00 seconds the text: Working Functions0
      • Set RespawnDyingUnit = (Dying unit)
      • Custom script: set udg_ID = GetHandleId (udg_RespawnDyingUnit)
      • Set RespawnTimer = 30.00
      • Set RespawnXP = (Hero experience of (Dying unit))
      • Hashtable - Save Handle Of(Position of (Dying unit)) as 0 of ID in RespawnHash
      • Hashtable - Save RespawnTimer as 1 of ID in RespawnHash
      • Hashtable - Save RespawnXP as 2 of ID in RespawnHash
      • Unit Group - Add RespawnDyingUnit to RespawnGroup
  • RespawnLoop
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in RespawnGroup and do (Actions)
        • Loop - Actions
          • Custom script: set udg_ID = GetHandleId(GetEnumUnit())
          • Set LocRespawn = (Load 0 of ID in RespawnHash)
          • Set RespawnTimer = (Load 1 of ID from RespawnHash)
          • Set RespawnXP = (Load 2 of ID from RespawnHash)
          • Game - Display to (All players) for 30.00 seconds the text: Working Functions1
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • RespawnTimer Greater than 0.00
            • Then - Actions
              • Game - Display to (All players) for 30.00 seconds the text: Working Functions2
              • Hashtable - Save (RespawnTimer - 1.00) as 1 of (Key (Picked unit)) in RespawnHash
            • Else - Actions
              • Game - Display to (All players) for 30.00 seconds the text: Working Functions3
              • Unit - Create 1 Saibaman for Player 7 (Green) at LocRespawn facing Default building facing degrees
              • Hero - Set (Last created unit) experience to RespawnXP, Hide level-up graphics
              • Unit Group - Remove (Picked unit) from RespawnGroup
              • Hashtable - Clear all child hashtables of child ID in RespawnHash
-Solved
 
Status
Not open for further replies.
Back
Top