• 🏆 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] Numbers Problem (finding a formula)

Status
Not open for further replies.
Level 7
Joined
Dec 17, 2005
Messages
337
I've been busting my brain trying to think of a formula and trigger that can do this:

If player 1 and 2 are playing, set player 2 as player 1's enemy
if player 2 isn't playing, set player 3 as player 1's enemy
etc...

It has to do this for every player (up to 8 players), setting the next player in line (1,2,3,4...) as the enemy for the player just before him. The problem I have is making it so that player 8 searches for enemies from player 1 and up instead of player 9 to infinity.

I've currently got something where:

  • Remove Unplaying
    • Events
      • Player - Player 1 (Red) leaves the game
      • Player - Player 2 (Blue) leaves the game
      • Player - Player 3 (Teal) leaves the game
      • Player - Player 4 (Purple) leaves the game
      • Player - Player 5 (Yellow) leaves the game
      • Player - Player 6 (Orange) leaves the game
      • Player - Player 7 (Green) leaves the game
      • Player - Player 8 (Pink) leaves the game
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 8, 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) + 1))) slot status) Equal to Is playing
            • Then - Actions
              • Set PlayersEnemy[(Integer A)] = (Player(((Integer A) + 1)))
            • Else - Actions


I know this must be confusing but all I really need in simplicity is a formula that makes searching go in a circle from 1-8 and back to 1 instead of going to 9.
 
Last edited:
Level 22
Joined
Dec 31, 2006
Messages
2,216
So you want everyone to treat each other as enemies?
This should do it:
  • Actions
    • For each (Integer A) from 1 to 8, do (Actions)
      • Loop - Actions
        • Set Player[0] = (Player((Integer A)))
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • (Player[0] slot status) Equal to Is playing
          • Then - Actions
            • For each (Integer B) from 1 to 8, do (Actions)
              • Loop - Actions
                • Set Player[1] = (Player((Integer B)))
                • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                  • If - Conditions
                    • (Player[1] slot status) Equal to Is playing
                    • (Player[0] is an enemy of Player[1]) Equal to False
                    • Player[0] Not equal to Player[1]
                  • Then - Actions
                    • Player - Make Player[0] treat Player[1] as an Enemy
                    • Player - Make Player[1] treat Player[0] as an Enemy
                  • Else - Actions
          • Else - Actions
 
Level 7
Joined
Dec 17, 2005
Messages
337
Hurm how to explain this better. I only want one person to treat one person as "his" enemy or in better words, "target".

This trigger is for figuring out to whom you are "attacking". (I will be using this player variable in a different trigger)

Player 1 would by default be attacking blue, but if blue isn't playing, he will send creeps to player 3. However, player 8 is sending creeps to player 1. If this were as simple as a Tower Wars I wouldn't have a problem (where you can just teleport the creeps somewhere else if nobody is playing in that zone)

Lets say player 1 red were to activate a specific trigger, i want it only to affect his "target", but his target could be changing due to leavers or unused slots.

Thanks
 
Level 22
Joined
Dec 31, 2006
Messages
2,216
Ahh. I see.

This should work (I hope)
  • Actions
    • For each (Integer A) from 1 to 8, do (Actions)
      • Loop - Actions
        • Set Player[0] = (Player((Integer A)))
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • (Player[0] slot status) Equal to Is playing
          • Then - Actions
            • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
              • If - Conditions
                • (Integer A) Equal to 8
              • Then - Actions
                • For each (Integer B) from 1 to 8, do (Actions)
                  • Loop - Actions
                    • Set Player[1] = (Player((Integer B)))
                    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                      • If - Conditions
                        • (Player[1] slot status) Equal to Is playing
                      • Then - Actions
                        • Set PlayerTarget[(Integer A)] = Player[1]
                        • Custom script: exitwhen true
                      • Else - Actions
                • Else - Actions
                  • For each (Integer B) from ((Player number of (Player[0]) + 1) to 8, do (Actions)
                    • Loop - Actions
                      • Set Player[1] = (Player((Integer B)))
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (Player[1] slot status) Equal to Is playing
                        • Then - Actions
                          • Set PlayerTarget[(Integer A)] = Player[1]
                          • Custom script: exitwhen true
                        • Else - Actions
          • Else - Actions
 
Level 7
Joined
Dec 17, 2005
Messages
337
I will need to test this later when i have found somebody to host the map but +rep anyways cause thats super complicated (at least for me)

Actually looking at it, there is only one problem that i foresee.
When it reviews players for the targets it says
  • For each (Integer B) from ((Player number of (Player[0]) + 1) to 8, do (Actions)
It will stop after player 8. But if it was only player 4 and players 1-3 left, player 4 would never consider players 1-3 as enemies. Or am i just reading this wrong
 

peq

peq

Level 6
Joined
May 13, 2007
Messages
171
If you want a loop starting at player n+1 you you could use something like this

  • For each IntegerA from 1 to 7 do
    • Loop - Actions
      • Set PlayerNumber = Modulo(IntegerA + n, 8)
(with playernumbers from 0 to 7)

So for example with n = 6 you would have
Modulo(6+1, 8) = 7
Modulo(6+2, 8) = 0
Modulo(6+3, 8) = 1
Modulo(6+4, 8) = 2
Modulo(6+5, 8) = 3
Modulo(6+6, 8) = 4
Modulo(6+7, 8) = 5
 
Status
Not open for further replies.
Top