• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[Solved] How to loop actions?

Status
Not open for further replies.
Level 2
Joined
Apr 22, 2013
Messages
10
I was making a action in world editor that says "Leader-board - Change the value for Player 1 (Red) in (Last Created Leader-board) to (Lives -1)

So the question is, how do i repeat it?, because when a unit enters a region, it activates it but can't be activated again:vw_wtf:

pgoHvug.png
 
Last edited:
Level 25
Joined
Sep 26, 2009
Messages
2,387
Your trigger doesn't fire only once. It fires all the time, as long as any unit of player 12 enters the region. The problem why you think it fires only once is because the leaderboard shows value "Lives - 1". So if Lives == 10, then your leaderboard will show number 9 there (10-1) all the time. You do not change the value inside variable Lives. You only use it as a part of calculation.
Hence you get the same value and you thought the trigger fires only once.
There are some other things. Look at the order of your other actions - you first remove the unit from the game and then you use it to damage another unit.

I changed the trigger a bit:
  • Untitled Trigger 001
    • Events
      • Unit - A unit enters End Region <gen>
    • Conditions
      • (Owner of (Triggering unit)) Equal to Player 12 (Brown)
    • Actions
      • Unit - Remove (Triggering unit) from the game
      • Set Lives = (Lives - 1)
      • Unit - Set life of Lives 0005 <gen> to (Real(Lives))
      • Leaderboard - Change the value for Player 1 (Red) in (Last created leaderboard) to Lives
First of all, you can see that I modify the value in variable "Lives" by decreasing the value by 1. I also modify health of Lives 0005 to the value saved in the variable Lives (I presume they should have same value). Then I also update the leaderboard with the value.
Lives variable is an integer variable, but health of the Lives 0005 unit is in reals. To be able to use the integer variable where reals value is needed, youi can use the "Conversion" function - "Conversion - Convert integer to real".

That will solve the issue at hand, but not the "for all players" part.
What you probably want is an MPI system (Multi Player Instanceable system) - that means a system which works for each player.
This is what I presume:
- Each player has his own Lives 000X unit
- Each player has his own Lives.

What you will need to do is get a Unit array and change the Lives variable into array. Remove the "player equal to..." condition from your trigger.

Every MPI system uses "Player' number" (e.g. Player 1 (red)'s number is 1, Player 2 (Blue)'s is number 2, etc.) as an index for the arrays. Since each player has different number, you can never overwrite data of one player by datas of different player.

  • Untitled Trigger 001
    • Events
      • Unit - A unit enters No region
    • Conditions
    • Actions
      • Set Player_Index = (Player number of (Triggering player))
      • Unit - Remove (Triggering unit) from the game
      • Set Lives[Player_Index] = (Lives[Player_Index] - 1)
      • Unit - Set life of LivesUnit[Player_Index] to (Real(Lives[Player_Index]))
      • Leaderboard - Change the value for (Player(Lives[Player_Index])) in (Last created leaderboard) to Lives[Player_Index]
What this trigger does is that it first gets the players number of the player whose unit entered the region (= the triggering player) and save that value into PLayer_Index.
Then in each array it will use the Player_Index as an index.
Last but not least, I changed who you show the modified value. Now you don't show it to Player 1 (Red), but to the player who fired the trigger.

Do note this important thing:
You need to initialize your Lives and LivesUnit arrays with values and units - for example at map initialization, else nothing is there. So something like this:
  • Untitled Trigger 002
    • Events
      • Map initialization
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 12, do (Actions)
        • Loop - Actions
          • Set Lives[(Integer A)] = 10
      • Set LivesUnit[1] = Lives 0005 <gen>
      • Set LivesUnit[2] = Lives 0004 <gen>
      • Set LivesUnit[3] = Lives 0008 <gen>
      • Set LivesUnit[4] = Lives 0015 <gen>
      • Set LivesUnit[5] = Lives 0014 <gen>
      • etc.
 
1 thing I noticed is that you remove the unit before dealing the damage. Remove the unit last, because if you remove the unit, (Entering Unit) becomes null. I think.

Another thing is that, the unit is dealing 1.00 damage to Lives, so I'm assuming that's for a [tower] defense map? Depending on the armor-type of Lives 0005, that might give incorrect values, so either reduce the life by 1 hp by using Set Life, or set the attack type to Chaos and damage type to Universal. Keep in mind that a unit of yours/you ally's being damage when you're not looking will prompt a 'you are under attack!' sound, which can be annoying to some players.

Also, if you use Entering Unit/Triggering unit more than once, store it in a variable and refer to that variable instead.
 
Status
Not open for further replies.
Top