• 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] help gold gain and alive

Status
Not open for further replies.
Level 2
Joined
Jun 19, 2011
Messages
14
guys help me!

A player gain gold every 2 seconds when he is alive. Then stop gaining gold when he is dead.

help please

sorry, I do not know how to write English I'm using google translator.

sonofjay(thanks for understanding)
 
Last edited:
You need a boolean array first.
Whenever the hero dies, just set Boolean[(Player number of (Triggering player))] = true
This boolean tracks whether the hero is dead or not.

When the hero is revived, set this boolean to false.

Then, every 2 seconds, add the gold like this:

  • Trigger
    • Events
      • Game - Every 2.00 seconds of game-time
    • Conditions
    • Actions
      • For each (Integer A) from 1 to NUMBER_OF_PLAYERS_IN_YOUR_MAP, do (Actions)
        • Loop - Actions
          • If (Conditions) then do (Then - Actions) else do (Else - Actions)
            • If - Conditions
              • DeadHero[Player((Integer A))] Equal to True
            • Then - Actions
              • Player - Add 2 to Player((Integer A))'s gold
            • Else - Actions
DeadHero is the name of the boolean array I used here.
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
You don't have to loop through all players (less efficient)

When you can just add the money to a Player Group variable ?

  • Player Group - Pick every player in PlayerGroupUnitAlive and do (Actions)
    • Loop - Actions
      • Player - Add 1000 to (Picked player) Current gold
Of course, when the unit dies, remove the Player owning the Unit from the Player Group, if the unit is revived back, add the Owning Player of the Unit to the Player Group.

It works more efficient I think since it doesn't need loop, which you will have a maximum loop of 12 (for 12 players).

Looping 12 actions is less efficient than just a single-time action. Not to mention you are doing this periodically for 2 seconds per event.
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
So looping is more efficient, cool...

But, if you loop, you will loop to every player (no matter his gold needs to be added or not)

If you have a Player Group, it will only pick the Player that needs to be added gold only, sounds more reasonable ?

Instead of picking all 12 players, the system just pick a selected player from the group (let's say just 4 of them, instead of 12 (Looping))
 
Level 2
Joined
Jun 19, 2011
Messages
14
thanks for the help of all, PROBLEM SOLVED!
  • Protetor
    • Events
      • Map initialization
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 10, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Player((Integer A))) slot status) Equal to Is playing
              • ((Player((Integer A))) controller) Equal to User
            • Then - Actions
              • Unit - Create 1 Protetor for (Player((Integer A))) at (Center of Players Start <gen>) facing Default building facing degrees
            • Else - Actions
:goblin_good_job::goblin_good_job::goblin_good_job::goblin_good_job::goblin_good_job:
 
Status
Not open for further replies.
Top