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

[Trigger] Checking active unit

Status
Not open for further replies.
Level 18
Joined
Aug 23, 2008
Messages
2,319
I've got a trigger for a turn-based battle system. Problem is: I need to check which unit is active. For this turn-based I use the Integer A loop, which makes it annoying to check who actually is the active unit. This is the trigger part that's necessary:

  • ATB Gauge
    • Events
      • Time - Every 0.25 seconds of game time
    • Conditions
    • Actions
      • For each (Integer A) from 1 to (Number of units in AllyBattleGroup), do (Actions)
        • Loop - Actions
          • Set AllyATB__BattleUnit[(Integer A)] = (AllyATB__BattleUnit[(Integer A)] + (AttSPEED__Character[(Integer A)] / 10))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • AllyATB__BattleUnit[(Integer A)] Greater than or equal to 100
            • Then - Actions
              • Trigger - Turn off (This trigger)
              • -------- Battle Menu --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • <PROBLEM HERE>
                • Then - Actions
                  • Dialog - Show BattleMenu[1] for Player 1 (Red)
                  • Dialog - Change the title of BattleMenu[1] to
                  • Dialog - Create a dialog button for BattleMenu[1] labelled Attack
                  • Set BattleMenu__Attack = (Last created dialog Button)
                  • Dialog - Create a dialog button for BattleMenu[1] labelled Steal
                  • Set BattleMenu__Zidane_Steal = (Last created dialog Button)
                  • Dialog - Create a dialog button for BattleMenu[1] labelled Skill
                  • Set BattleMenu__Zidane_Skill = (Last created dialog Button)
                  • Dialog - Create a dialog button for BattleMenu[1] labelled Item
                  • Set BattleMenu__Item = (Last created dialog Button)
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Clicked dialog button) Equal to BattleMenu__Attack
                    • Then - Actions
                      • Set Active__Character[1] = 1
                      • Trigger - Turn on Next Target <gen>
                      • Trigger - Turn on Previous Target <gen>
                      • Trigger - Turn on Pick Target <gen>
                    • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Clicked dialog button) Equal to BattleMenu__Zidane_Steal
                    • Then - Actions
                      • Set Active__Character[1] = 1
                      • Trigger - Turn on Next Target <gen>
                      • Trigger - Turn on Previous Target <gen>
                      • Trigger - Turn on Pick Target <gen>
                    • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Clicked dialog button) Equal to BattleMenu__Zidane_Skill
                    • Then - Actions
                      • Set Active__Character[1] = 1
                      • Trigger - Turn on Next Target <gen>
                      • Trigger - Turn on Previous Target <gen>
                      • Trigger - Turn on Pick Target <gen>
                    • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Clicked dialog button) Equal to BattleMenu__Item
                    • Then - Actions
                      • Set Active__Character[1] = 1
                      • Trigger - Turn on Next Target <gen>
                      • Trigger - Turn on Previous Target <gen>
                      • Trigger - Turn on Pick Target <gen>
                    • Else - Actions
                • Else - Actions
              • Set AllyATB__BattleUnit[1] = 0
              • Trigger - Turn on (This trigger)
            • Else - Actions
The Pick Target trigger activates the right command, so no worrying there. The point is the '<PROBLEM HERE>' part in the If/Then/Else command. At that point I need to check the unit(-type) of the unit with 'AllyATB_BattleUnit[Integer A] = 100'.

So let's say Unit1 (AllyATB_BattleUnit[1]) is the unit which has AllyATB_BattleUnit[Integer A] = 100. Then I need to check what unit(-type) Unit1 is. Any idea's? Maybe it's just me, because I'm still not very advanced with Integer A loops xD
 
Level 9
Joined
May 27, 2006
Messages
498
Got problems with teh ATB thingy again, eh?

You want to check the unit's unit-type? Why not just use:
  • (Unit-type of(Unit1)) Equal to Blah
Or i just misunderstood... :eek:

(i got a bit confused with this btw: AllyATB_BattleUnit[Integer A] = 100, what the hell does it do if it has to check the unit's type?)

Edit:
Oh, i think i got it. You want to get the unit with the highest attack speed, to determine which has to attack first... But i have no idea how to get the highest integer value from group of integers ;/
 
Level 18
Joined
Aug 23, 2008
Messages
2,319
With the Integer A, I can't check the array of AllyATB_BattleUnit. Let's say that Unit2 (AllyATB_BattleUnit[2]) is the first to get to 100. Then I need to check which of the units in the Integer A loop is the 1 with AllyATB_BattleUnit = 100. How do I make the condition only for Unit2 in this example and not for another unit?

Note that this is just an example. If the unit array of Integer A is Unit1, I need it to work for Unit1, and not for Unit2 anymore.
 
Level 9
Joined
May 27, 2006
Messages
498
Answer -> my post edit.

I saw somewhere a GetClosestUnit jass script by Poot or someone, dont remember now. I think you could use it as a base to work on and to get some ideas maybe.

(Btw, dont blame me for lack of creativeness, im right after a math test and my brain is dying...)

Edit:
Oh, its by DiscipleOfLife actually: http://www.hiveworkshop.com/forums/f413/getclosestunit-s-59254/
 
Level 18
Joined
Aug 23, 2008
Messages
2,319
It's not closest, it's just checking the unit that reaches 100. At that moment, an action can be chosen and the actions available depend on which unit reached the 100. So all I actually need is how to check which of the units is the unit with 100 when any of them reaches 100.

PS: I need a GUI solution. JASS is not my thing '^^
 
Level 9
Joined
May 27, 2006
Messages
498
I know you want to declare the highest integer value. I linked the GetClosesUnit script as it does almost the same - compares values and gets the lowest. You could work on it a bit, learn from it and use to make your own trigger.

Also, its important if there is more than one unit that can reach the 100 at a time.
 
Level 18
Joined
Aug 23, 2008
Messages
2,319
Once a unit reaches 100, he can perform an action, and then it will be set to 0 again.
It's very unlikely that 2 units will have 100 at the same time. If I can calculate it right, the chance that would happen would be about 1 on 500000.

But about the link you gave me. Is that easily usable/editable if you know no crap about JASS?
 
Level 9
Joined
May 27, 2006
Messages
498
You already have a condition AllyATB__BattleUnit[(Integer A)] Greater than or equal to 100, so there should be no problem of that sort...
Or the problem is somewhere else and this 1% of my brain which is still active cant see it.

Doubt it, if you have completely no knowledge about jass then better dont touch it... :p I was having on mind that you could look up at some math (argh) equalations in the script to have an inspiration/base idea, but now i see its not the matter.

Edit:
So far i understood the following:
-You have an integer value.
-You set it to the modified "attack speed" of unit.
-If its greater than 100, it passes forward.
And now crap. I dont understand more. You want to get a unit-type using the integer variable, right?
 
Level 18
Joined
Aug 23, 2008
Messages
2,319
Yes, that's Integer A. But Integer A contains max 4 different units. If Unit1 of the 4 reaches 100, then only the actions of Unit1 should be available. If it's another unit, then those unit's actions should be available. That's why I need to check which number Integer A is of the array of the unit who reaches 100.
 
Level 9
Joined
May 27, 2006
Messages
498
Set Variable = (Integer A) inside the loop
And it will store the current integer a value. As it loops from 1 to max 4, if the unit1 failed at the conditions, the second loop will begin with value of 2. And so on.

So mainly you could just use ShowDialog[(Integer A)], if i understood right, then you have four versions of the dialog?
 
Level 18
Joined
Aug 23, 2008
Messages
2,319
But will the variable you say only effect the 1 that matches the condition? because I'd think that that variable would still take 1-4.

PS: There are actually about 10 different types, but there are max 4 of them in a battle, and these units can be changed to any type in any order. But that's not a problem.
 
Level 9
Joined
May 27, 2006
Messages
498
1. You said that only one of the four units can have the 100 at a time. So the rest have no chance to trig.
2. If you're still not sure enough, add Skip remaining actions at the end of the if/then/else inside the loop, it'll make wc3 forget about the rest of the actions. (of course, you would have to turn the trigger on and set the variable to 0 before this action)
 
Level 18
Joined
Aug 23, 2008
Messages
2,319
The Integer A is for all 4 units. 'AllyATB__BattleUnit[(Integer A)] Greater than or equal to 100' checks if any of the 4 units (Integer 1-4) are 100 or higher, so if I'd check with Integer A, it would still effect all 4 even if the command is in the condition, right?

I think I got an idea. Do you think it would work to check a second time who got 100+ there? I mean:

  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • AllyATB__BattleUnit[1] Greater than or equal to 100
    • Then - Actions
      • Set Ally_BattleUnit[1] = ActiveCharacter
      • PREVIOUSLY CALLED ACTIONS
    • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • AllyATB__BattleUnit[2] Greater than or equal to 100
        • Then - Actions
          • Set Ally_BattleUnit[2] = ActiveCharacter
          • PREVIOUSLY CALLED ACTIONS
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • AllyATB__BattleUnit[3] Greater than or equal to 100
            • Then - Actions
              • Set Ally_BattleUnit[3] = ActiveCharacter
              • PREVIOUSLY CALLED ACTIONS
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • AllyATB__BattleUnit[4] Greater than or equal to 100
                • Then - Actions
                  • Set Ally_BattleUnit[4] = ActiveCharacter
                  • PREVIOUSLY CALLED ACTIONS
                • Else - Actions
It's something that just came to mind. Just to double-check: This trigger will check 1 by 1 if a unit has reached 100 and then set it to a variable ActiveCharacter. If I'm right, keeping the first command with Integer A would cause only the amount of units on the battlefield to get their ATB raised, and thus never will trigger Ally_BattleUnit[4] if there are only 3 or less units on the battlefield. Is that correct, or am I missing something?
 
Actually it can work with ur first trigger.
Because u have AllyATB__BattleUnit[4] aswell as AttSPEED_Character[4]
Each one of AllyATB__BattleUnit[n] will increase and is being checked.
However, it's not like the AllyATB__BattleUnit[n] will be mixed after each 0.25second.
Means,
AllyATB__BattleUnit[1] will increase until 100
AllyATB__BattleUnit[2] will increase until 100
AllyATB__BattleUnit[3] will increase until 100
AllyATB__BattleUnit[4] will increase until 100.
With that in mind you can just asign a unit to each of those 4 BattleUnit.
Just create a new variable called AllyATB_Unit[array] or something and make it a Unit variable.
When the 4 units are created u asign each of them to a AllyATB_Unit[].

Now, because the Loop will always go from 1 to 4 in that order u can check which unit has reached the 100.
  • ATB Gauge
    • Events
    • Conditions
    • Actions
      • For each (Integer A) from 1 to (Number of units in AllyBattleGroup), do (Actions)
        • Loop - Actions
          • Set AllyATB__BattleUnit[(Integer A)] = (AttSPEED_Character[(Integer A)] / 10)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • AllyATB__BattleUnit[(Integer A)] Greater than or equal to 100
            • Then - Actions
              • Trigger - Turn off (This trigger)
              • -------- Battle Menu --------
              • Set ActiveUnit = AllyATB_Unit[(Integer A)]
              • -------- Do Rest --------
            • Else - Actions
 
Level 18
Joined
Aug 23, 2008
Messages
2,319
Bu then we go back to a previous question: Will the Integer A in 'Set ActiveUnit = AllyATB_Unit[(Integer A)]' only be the unit that reached 100, or will it take all 4 units? The reason I ask is because there's no command anywhere that reduces 1-4 to only 1 of the 4, so I'd assume nothing changed there. But if I'm wrong, please tell me. (There's nothing I'd rather here right now then that the Integer A if reduced to only 1 of the 4 units ^^)
 
Level 9
Joined
May 27, 2006
Messages
498
Look, Integer A loops four times here. It loops with the value of 1, then with value of 2, next 3, and so on, to the last number you entered. It is doing them in the order from lowest to greatest, one by one. The time it takes to loop one value varies depending on whether you included a wait action in your loop or not. If the loop 1 is in progress, the wc3 wont start looping the second one, until its finished.

If the AllyATB__BattleUnit[2] (example of one of integer a possible values) passed the condition, the integer a is going to be equal to the value 2 through whole if/then/else block. It just cant change during it.
 
If the first person reachs 100 it will trigger the Dialog box. Until then the Trigger is turned off, means Yes it will still check the other 3 ones, BUT because the trigger is off their points won't be increased and therefore the 100points condition throws them out.

But i am not sure if the dialog boxes clickactions works in the same trigger.
If not, make a new trigger with the clickaction and turn the trigger atb trigger on in this one.
 
Status
Not open for further replies.
Top