• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Need help with NPC Revive System

Status
Not open for further replies.
Level 8
Joined
Jul 17, 2004
Messages
283
I've got 6 gnolls placed in a specific area in my map. I want to add them to some kind of revive system where if one dies, after 12 seconds, they will revive instantly at the location they were initially standing at.

I figured I'd have to create a new unit in place of the dying unit, as opposed to reviving it.

I don't want to just make separate triggers for each individual respawn. I want to add them all to some kind of index, since they're all sharing the same revive wait time. How can I do this?

Note: I'm also interested how I would go about having different revive wait times for some of the units inside the index, as opposed to them all just sharing the same revive wait time.
 
Level 25
Joined
Sep 26, 2009
Messages
2,378
If I understood it correctly (you want to respawn only one unit in 12 seconds), then it is something like this:

Code:
Trigger: Map ini
Events
    Map initialization
Conditions
Actions
    set Ind = 0
    set bj_wantDes...
    Pick every unit in map matching (unit-type = unit-type of your gnoll) and do actions
        Actions
            Gnoll_Unit[Ind] = picked unit
            Gnoll_Loc[Ind] = position of picked unit
            set Ind = Ind + 1
-----------------------------------
Trigger: Gnoll Dies
Events
    Unit Dies
Conditions
    Unit-type is that of a gnoll
Actions
    For each int Loop from 1 to 6 do:
        If (conditions)
            dying unit == Gnoll_Unit[Loop]
        Then
            set Index = Loop
            set Loop = 6
            Start 12 second Gnoll_timer as one-shot timer
            Turn off this trigger
        Else
----------------
Trigger: Revive
Events
    Gnoll_timer expires
Conditions
Actions
    Create 1 gnoll at Gnoll_Loc[Index]
    set Gnoll_Unit[Index] = last created unit

For the case, where you want to respawn them all on their own timers, then just make the Gnoll_timer a timer array and when one dies, fire "Gnoll_timer[Loop]", when it expires, revive that gnoll, which has same index as the timer.
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
For me, I would use a Hashtable for this.
At Map init, save all location of each affected unit by this system, then at Unit Dies trigger, load all necessary variables (initialLoc, etc), then run a timer (indexing), after timer's done, create unit, repeat the process.
 
Level 8
Joined
Jul 17, 2004
Messages
283
Worked like a charm. Thank you!

For anyone who would like to use this system, I posted it below. Keep in mind leaks are not cleaned. You'll have to adjust the system for your map and clean leaks yourself. (Thanks to deathismyfriend for his awesome indexing system. I use his as a template.)

  • Gnolls Initialize
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set NPC[1] = <Gnoll 01>
      • Set NPC[2] = <Gnoll 02>
      • Set NPC[3] = <Gnoll 03>
      • Set NPC[4] = <Gnoll 04>
      • Set NPC[5] = <Gnoll 05>
      • Set NPC[6] = <Gnoll 06>
      • Set NPC_Loc[1] = (Position of <Gnoll 01>)
      • Set NPC_Loc[2] = (Position of <Gnoll 02>)
      • Set NPC_Loc[3] = (Position of <Gnoll 03>)
      • Set NPC_Loc[4] = (Position of <Gnoll 04>)
      • Set NPC_Loc[5] = (Position of <Gnoll 05>)
      • Set NPC_Loc[6] = (Position of <Gnoll 06>)
  • Gnolls Revive
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Gnoll
    • Actions
      • Set Revive_MaxIndex = (Revive_MaxIndex + 1)
      • Set Revive_DeadUnit[Revive_MaxIndex] = (Triggering unit)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Revive_MaxIndex Equal to 1
        • Then - Actions
          • Trigger - Turn on Gnolls Revive Loop <gen>
        • Else - Actions
  • Gnolls Respawn Loop
    • Events
      • Time - Every 0.04 seconds of game time
    • Conditions
    • Actions
      • For each (Integer Revive_Int) from 1 to Revive_MaxIndex, do (Actions)
        • Loop - Actions
          • Set Revive_Timer[Revive_Int] = (Revive_Timer[Revive_Int] + 1.00)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Revive_Timer[Revive_Int] Equal to 100.00
            • Then - Actions
              • For each (Integer A) from 1 to 6, do (Actions)
                • Loop - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • Revive_DeadUnit[Revive_Int] Equal to NPC[(Integer A)]
                    • Then - Actions
                      • Unit - Create 1 Gnoll for Neutral Hostile at NPC_Loc[(Integer A)] facing (Random angle) degrees
                      • Set NPC[(Integer A)] = (Last created unit)
                    • Else - Actions
              • -------- Time to recycle! --------
              • Set Revive_DeadUnit[Revive_Int] = Revive_DeadUnit[Revive_MaxIndex]
              • Set Revive_DeadUnit[Revive_MaxIndex] = No unit
              • Set Revive_Timer[Revive_Int] = Revive_Timer[Revive_MaxIndex]
              • Set Revive_Timer[Revive_MaxIndex] = 0.00
              • Set Revive_MaxIndex = (Revive_MaxIndex - 1)
              • Set Revive_Int = (Revive_Int - 1)
            • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Revive_MaxIndex Equal to 0
        • Then - Actions
          • Trigger - Turn off (This trigger)
        • Else - Actions
 
Last edited:
Status
Not open for further replies.
Top