• 🏆 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!

[Solved] Need help with multiple life system

Status
Not open for further replies.
Level 4
Joined
Mar 15, 2020
Messages
32
Hey, I'm working on this RPG map and having a bit of trouble making a multiple life system work. I'm pretty inexperienced and trying to learn as much as possible on my own. Alas I've reached a dead end. I'm almost positive the issue is with the Variable and not the trigger itself, unless I'm missing something obvious.

Currently the Variable is classified as an Integer/Array Ticked/Size:1/Initial Value:3

I'm planning on setting the initial value (being lives) after a vote at the start of the game for difficulty. Currently it's set to 3 for testing purposes.

I've attached an image of the trigger, any help would be greatly appreciated.
 

Attachments

  • Having trouble.png
    Having trouble.png
    57.3 KB · Views: 31
Level 13
Joined
Jul 15, 2007
Messages
763
Don't use Dying Unit after a wait, it's a global variable in disguise, use Triggering Unit instead as that's local and will still refer to the unit dying.

To clarify; if your hero A dies, dying unit will refer to hero A, but if a unit B dies 0.01 sec later, then dying unit will refer to that unit for all triggers that want to use dying unit.
 
Level 4
Joined
Mar 15, 2020
Messages
32
Came across another problem, the revival system works great for Player 1 (Red) But every other player instantly loses their hero when they die. I've attacheda copy of the map and screen shot of the trigger/variable. Could use some help.

Still need Help.png
 

Attachments

  • Variable.png
    Variable.png
    9.7 KB · Views: 17
  • Dev 1.w3m
    325 KB · Views: 17
Level 28
Joined
Feb 18, 2014
Messages
3,579
  • Hero Revival
    • Events
      • Unit - A unit Dies
    • Conditions
      • ((Triggering unit) is A hero) Equal to TRUE
    • Actions
      • Set Integer = (Integer + 1)
      • Set Hero[Integer] = (Triggering unit)
      • Set Player_Index = (Player number of (Owner of (Triggering unit)))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ReviveCount[Player_Index] Equal to 0
        • Then - Actions
          • Wait 5.00 seconds
          • Unit - Remove Hero[Integer] from the game
          • Game - Display to (All players) the text: Test
        • Else - Actions
          • Set ReviveCount[Player_Index] = (ReviveCount[Player_Index] - 1)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ReviveCount[Player_Index] Equal to 2
            • Then - Actions
              • Game - Display to (All players) the text: Text 1
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • ReviveCount[Player_Index] Equal to 1
                • Then - Actions
                  • Game - Display to (All players) the text: Text 2
                • Else - Actions
                  • Game - Display to (All players) the text: Text 3
          • -------- Create Revive Timer --------
          • Countdown Timer - Start Timer[Integer] as a Un coup timer that will expire in 30.00 seconds
          • Countdown Timer - Create a timer window for Timer[Integer] with title Timer
          • Set Window[Integer] = (Last created timer window)
          • Countdown Timer - Hide Window[Integer]
          • Countdown Timer - Show Window[Integer] for (Owner of (Triggering unit))
          • Wait 30.00 seconds
          • -------- Revive the Hero --------
          • Set Recycle = (Recycle + 1)
          • Countdown Timer - Destroy Window[Recycle]
          • Hero - Instantly revive Hero[Recycle] at (Center of (Playable map area)), Show revival graphics
          • Camera - Pan camera for (Owner of Hero[Recycle]) to (Center of (Playable map area)) over 0.00 seconds
          • Unit - Set mana of Hero[Recycle] to 100.00%
          • Selection - Clear selection for (Owner of Hero[Recycle])
          • Selection - Add Hero[Recycle] to selection for (Owner of Hero[Recycle])
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Recycle Equal to Integer
            • Then - Actions
              • Set Integer = 0
              • Set Recycle = 0
            • Else - Actions
 
Last edited:

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,537
Also, does your game use 1 Hero per player?

Because if that's the case then I'd recommend keeping track of these Heroes as variables. This will also make it very easy to use Generic Events instead of Player-Specific Events.

If you're doing things right then you generally only need 1 Trigger to work for all of your Players.

Here's some trigger examples of what I mean:

Variables:
Player_Hero = Unit (Array, Size 1) <-- Note that Size should generally stay at 1, it's rare that you need to change it

If your Heroes are pre-placed on the map then this method is fairly simple for assigning the variable to the Heroes:
  • Setup Heroes Map Start
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set VariableSet Player_Hero[1] = Player 1's Hero
      • Set VariableSet Player_Hero[2] = Player 2's Hero
      • Set VariableSet Player_Hero[3] = Player 3's Hero
      • Set VariableSet Player_Hero[4] = Player 4's Hero
      • etc...
But maybe you pick your Hero through an Altar, here's how you can assign the Player_Hero variable in that case:
  • Setup Heroes Altar
    • Events
      • Unit - A unit Finishes training a unit
    • Conditions
      • ((Triggering unit) is A Hero) Equal to True
    • Actions
      • Set VariableSet Player_Hero[(Player number of (Triggering player))] = (Trained unit)
Maybe you use a Region + Circle of Power setup (You see this in a lot of rpg maps, you move your wisp to the circle and pick your hero that way).
Whatever the case, your goal is to set Player_Hero[(Player number of (Your player))] = The Chosen Hero.

Using the Player's number as the Index [The number in the brackets] can make your life much much easier.

Here's an example of a Generic trigger taking advantage of this. When Players 1, 2, 3 or 4 press ESCAPE it kills that player's respective hero.
  • Kill Your Hero
    • Events
      • Player - Player 1 (Red) skips a cinematic sequence
      • Player - Player 2 (Blue) skips a cinematic sequence
      • Player - Player 3 (Teal) skips a cinematic sequence
      • Player - Player 4 (Purple) skips a cinematic sequence
    • Conditions
    • Actions
      • Unit - Kill Player_Hero[(Player number of (Triggering player))]
That's a hell of a lot better than creating 4 separate triggers, each one tailored specifically to a given player.
 
Level 4
Joined
Mar 15, 2020
Messages
32
The more I try this the more I feel like an Idiot, sorry. It's till not working for me, if the hero dies it just gets deleted which tells me that
  • Revive_Count[Player_Index] Equal to 0
is always showing as 0 even tho I have the value of it set to 3 by default. Would I have to set it with a trigger ingame? am I just dumb? Gonna list the Variables I made and their configuration;

Player _Index = Integer (Initial Value 0)
Hero = Unit (Array, Size 1)
Revive_Count = Integer (Array, Size 1, Initial Value 3)
Integer = Integer (Initial Value 0)
Recycle = Integer (Initial Value 0)


  • Hero Revival New System
    • Events
      • Unit - A unit Dies
    • Conditions
      • ((Triggering unit) is A Hero) Equal to True
    • Actions
      • Set VariableSet Integer = (Integer + 1)
      • Set VariableSet Hero[Integer] = (Triggering unit)
      • Set VariableSet Player_Index = (Player number of (Owner of (Triggering unit)))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Revive_Count[Player_Index] Equal to 0
        • Then - Actions
          • Wait 5.00 seconds
          • Unit - Remove Hero[Integer] from the game
          • Game - Display to (All players) the text: ((Name of (Owner of Hero[Integer])) + |cffff0000has failed in their quest.|r)
          • Sound - Play QuestFailed <gen>
        • Else - Actions
          • Set VariableSet Revive_Count[Player_Index] = (Revive_Count[Player_Index] - 1)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Revive_Count[Player_Index] Equal to 2
            • Then - Actions
              • Game - Display to (Player group((Owner of Hero[Integer]))) the text: |cffffff00You have ...
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Revive_Count[Player_Index] Equal to 1
                • Then - Actions
                  • Game - Display to (Player group((Owner of Hero[Integer]))) the text: |cffd45e19You have ...
                • Else - Actions
                  • Game - Display to (Player group((Owner of Hero[Integer]))) the text: |cffff0000You have ...
          • -------- -----Revive Timer----- --------
          • Countdown Timer - Start Revival_Timer[Integer] as a One-shot timer that will expire in 30.00 seconds
          • Countdown Timer - Create a timer window for Revival_Timer[Integer] with title ((Name of (Triggering unit)) + Revives in:)
          • Set VariableSet Revival_Timer_Window[Integer] = (Last created timer window)
          • Countdown Timer - Hide Revival_Timer_Window[Integer]
          • Countdown Timer - Show Revival_Timer_Window[Integer] for (Owner of (Triggering unit))
          • Wait 30.00 seconds
          • -------- -----Revive Hero----- --------
          • Set VariableSet Recycle = (Recycle + 1)
          • Countdown Timer - Destroy Revival_Timer_Window[Recycle]
          • Hero - Instantly revive Hero[Integer] at (Center of Hero Spawn <gen>), Show revival graphics
          • Camera - Pan camera for (Owner of Hero[Integer]) to (Center of Hero Spawn <gen>) over 0.00 seconds
          • Unit - Set mana of Hero[Integer] to 100.00%
          • Selection - Clear selection for (Owner of Hero[Integer]).
          • Selection - Add Hero[Integer] to selection for (Owner of Hero[Integer])
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Recycle Equal to Integer
            • Then - Actions
              • Set VariableSet Recycle = 0
              • Set VariableSet Integer = 0
            • Else - Actions
I've attached an updated version of the map, Sorry for being such a hassle.
 

Attachments

  • Lordaeron Pre Alpha.w3m
    326.9 KB · Views: 19
Level 28
Joined
Feb 18, 2014
Messages
3,579
Setting Initial Value 3 for ReviveCount will ONLY work for Player 1 (Red). You will have to set it with triggers instead.
  • Player Group - Pick every player in (All players) and do (Set ReviveCount[(Player number of (Picked player))] = 3)
Anyway, I made another test map using Uncle's method, it's pretty much the same except that I'm reviving the hero on a different trigger instead of using wait..
  • Initialization
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- Variables --------
      • Set Hero[1] = Paladin 0000 <gen>
      • Set Hero[2] = Blademaster 0002 <gen>
      • Set Hero[3] = Death Knight 0003 <gen>
      • Set Hero[4] = Keeper of the Grove 0004 <gen>
      • Set Hero[5] = Blood Mage 0005 <gen>
      • Set Hero[6] = Farseer 0006 <gen>
      • -------- Respawn Regions --------
      • Set Respawn[1] = (Center of Red <gen>)
      • Set Respawn[2] = (Center of Blue <gen>)
      • Set Respawn[3] = (Center of Teal <gen>)
      • Set Respawn[4] = (Center of Purple <gen>)
      • Set Respawn[5] = (Center of Yellow <gen>)
      • Set Respawn[6] = (Center of Orange <gen>)
      • -------- Set Revive Count --------
      • Player Group - Pick every player in (All players) and do (Set ReviveCount[(Player number of (Picked player))] = 3)
  • Hero Revival
    • Events
      • Unit - A unit Dies
    • Conditions
      • ((Triggering unit) is A hero) Equal to TRUE
    • Actions
      • Set Player_Index = (Player number of (Owner of (Triggering unit)))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ReviveCount[Player_Index] Equal to 0
        • Then - Actions
          • Wait 5.00 seconds
          • Unit - Remove (Triggering unit) from the game
          • Game - Display to (All players) the text: ((Name of (Owner of (Triggering unit))) + has failed the quest)
        • Else - Actions
          • Set ReviveCount[Player_Index] = (ReviveCount[Player_Index] - 1)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ReviveCount[Player_Index] Equal to 2
            • Then - Actions
              • Game - Display to (All players) the text: ((Name of (Owner of (Triggering unit))) + has 2 lives left)
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • ReviveCount[Player_Index] Equal to 1
                • Then - Actions
                  • Game - Display to (All players) the text: ((Name of (Owner of (Triggering unit))) + has 1 lives left)
                • Else - Actions
                  • Game - Display to (All players) the text: ((Name of (Owner of (Triggering unit))) + has 0 lives left)
          • -------- Revive Timer --------
          • Countdown Timer - Start Timer[Player_Index] as a One shot timer that will expire in 5.00 seconds
          • Countdown Timer - Create a timer window for Timer[Player_Index] with title Revive Timer :
          • Set Window[Player_Index] = (Last created timer window)
          • Countdown Timer - Hide Window[Player_Index]
          • Countdown Timer - Show Window[Player_Index] for (Owner of (Triggering unit))
  • Revive Hero Red
    • Events
      • Time - Timer[1] expires
    • Conditions
    • Actions
      • Countdown Timer - Destroy Window[1]
      • Hero - Instantly revive Hero[1] at Respawn[1], Show revival graphics
Just repeat the Revive Hero Red trigger for each player and change the index. Also, make sure you set the "Size" of Timer variable to the max amount of players.
 

Attachments

  • Hero Revival.w3x
    22.7 KB · Views: 22
Last edited:
Level 4
Joined
Mar 15, 2020
Messages
32
Setting Initial Value 3 for ReviveCount will ONLY work for Player 1 (Red). You will have to set it with triggers instead.
  • Player Group - Pick every player in (All players) and do (Set ReviveCount[(Player number of (Picked player))] = 3)
Anyway, I made another test map using Uncle's method, it's pretty much the same except that I'm reviving the hero on a different trigger instead of using wait..
  • Initialization
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- Variables --------
      • Set Hero[1] = Paladin 0000 <gen>
      • Set Hero[2] = Blademaster 0002 <gen>
      • Set Hero[3] = Death Knight 0003 <gen>
      • Set Hero[4] = Keeper of the Grove 0004 <gen>
      • Set Hero[5] = Blood Mage 0005 <gen>
      • Set Hero[6] = Farseer 0006 <gen>
      • -------- Respawn Regions --------
      • Set Respawn[1] = (Center of Red <gen>)
      • Set Respawn[2] = (Center of Blue <gen>)
      • Set Respawn[3] = (Center of Teal <gen>)
      • Set Respawn[4] = (Center of Purple <gen>)
      • Set Respawn[5] = (Center of Yellow <gen>)
      • Set Respawn[6] = (Center of Orange <gen>)
      • -------- Set Revive Count --------
      • Player Group - Pick every player in (All players) and do (Set ReviveCount[(Player number of (Picked player))] = 3)
  • Hero Revival
    • Events
      • Unit - A unit Dies
    • Conditions
      • ((Triggering unit) is A hero) Equal to TRUE
    • Actions
      • Set Player_Index = (Player number of (Owner of (Triggering unit)))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ReviveCount[Player_Index] Equal to 0
        • Then - Actions
          • Wait 5.00 seconds
          • Unit - Remove (Triggering unit) from the game
          • Game - Display to (All players) the text: ((Name of (Owner of (Triggering unit))) + has failed the quest)
        • Else - Actions
          • Set ReviveCount[Player_Index] = (ReviveCount[Player_Index] - 1)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ReviveCount[Player_Index] Equal to 2
            • Then - Actions
              • Game - Display to (All players) the text: ((Name of (Owner of (Triggering unit))) + has 2 lives left)
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • ReviveCount[Player_Index] Equal to 1
                • Then - Actions
                  • Game - Display to (All players) the text: ((Name of (Owner of (Triggering unit))) + has 1 lives left)
                • Else - Actions
                  • Game - Display to (All players) the text: ((Name of (Owner of (Triggering unit))) + has 0 lives left)
          • -------- Revive Timer --------
          • Countdown Timer - Start Timer[Player_Index] as a One shot timer that will expire in 5.00 seconds
          • Countdown Timer - Create a timer window for Timer[Player_Index] with title Revive Timer :
          • Set Window[Player_Index] = (Last created timer window)
          • Countdown Timer - Hide Window[Player_Index]
          • Countdown Timer - Show Window[Player_Index] for (Owner of (Triggering unit))
  • Revive Hero Red
    • Events
      • Time - Timer[1] expires
    • Conditions
    • Actions
      • Countdown Timer - Destroy Window[1]
      • Hero - Instantly revive Hero[1] at Respawn[1], Show revival graphics
Just repeat the Revive Hero Red trigger for each player and change the index. Also, make sure you set the "Size" of Timer variable to the max amount of players.

This seems to work great but there's 1 problem, My Map utilizes a Tavern System and from my testing it seems the system @Uncle posted while working flawlessly on preset heroes, The Player_hero variable doesn't update with the tavern heroes. the trigger works perfectly up to the point where the timer is finished and the hero is revived, indicating to me at least the variable isn't saving the hero trained from the tavern. I've double checked this by making a simple trigger, checking if the variable had a hero in it and the hero didn't get a level up. It's a head scratcher because I can't think why Uncles method of setting the variable wouldn't work. I've tried changing it from "A unit trains a unit" to "a unit sells a unit" with "sold unit is a hero" but that still doesn't work. Frustration!!
  • Test Trigger
    • Events
      • Time - Elapsed game time is 30.00 seconds
    • Conditions
    • Actions
      • Hero - Set Player_Hero[1] Hero-level to 25, Show level-up graphics
 
Level 4
Joined
Mar 15, 2020
Messages
32
I've managed to fix it! It's a bit more messy but it works (I hope...) Had to manually make a trigger for each player for setting up the variable, which isn't too bad I still need to test it with other players to see if it works, but it seems to work just fine for Player1

  • Hero Setup
    • Events
      • Unit - A unit Sells a unit
    • Conditions
      • ((Sold unit) is A Hero) Equal to True
      • (Owner of (Sold unit)) Equal to Player 1 (Red)
    • Actions
      • Set VariableSet Player_Hero[1] = (Sold unit)
 
Level 28
Joined
Feb 18, 2014
Messages
3,579
I've managed to fix it! It's a bit more messy but it works (I hope...) Had to manually make a trigger for each player for setting up the variable, which isn't too bad I still need to test it with other players to see if it works, but it seems to work just fine for Player1

  • Hero Setup
    • Events
      • Unit - A unit Sells a unit
    • Conditions
      • ((Sold unit) is A Hero) Equal to True
      • (Owner of (Sold unit)) Equal to Player 1 (Red)
    • Actions
      • Set VariableSet Player_Hero[1] = (Sold unit)
I guess you"re using (Player number of (Triggering player) in the array, right ? If yes then it does not work that way because Triggering player refer to the owner of the Selling unit which is Neutral Passif or whomever owns the tavern. So instead of making a trigger for each player, you can do this :
  • Set VariableSet Player_Hero[(Player number of (Owner of (Sold unit)))] = (Sold unit)
 
Status
Not open for further replies.
Top