• 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.

Random player pvp trigger

Status
Not open for further replies.
Level 3
Joined
Dec 2, 2018
Messages
11
Im making an individual TD and every X rounds i want to start this "pvp" where players start sending units to other players

I have regions p1a,p2a,p3a... and p1b,p2b,p3b... where A is start of the path and B are the buildings to send units

Thats ok, i can do that. But how do i make to fight a random player?
 
Level 3
Joined
May 26, 2022
Messages
9
I think there is a function that lets you get a random player from a player group:
  • Set TempPlayer = (Random player from (All players controlled by a User player))
I don't get the full picture of what are you trying to achieve but I suppose you are saying you need random N players to fight another random N players? If that's the case, say, I need random 3 attacking players and random 3 defending players, I would do something like this:
  • Actions
    • Set TempForce = (All players)
    • For each (Integer A) from 1 to 3, do (Actions)
      • Loop - Actions
        • Set TempPlayer = (Random player from TempForce)
        • Player Group - Add TempPlayer to RandomAtackingPlayers
        • Player Group - Remove TempPlayer from TempForce
    • For each (Integer A) from 1 to 3, do (Actions)
      • Loop - Actions
        • Set TempPlayer = (Random player from TempForce)
        • Player Group - Add TempPlayer to RandomDefendingPlayers
        • Player Group - Remove TempPlayer from TempForce
    • Player Group - Pick every player in RandomAtackingPlayers and do (Actions)
      • Loop - Actions
        • Do nothing
    • Player Group - Pick every player in RandomDefendingPlayers and do (Actions)
      • Loop - Actions
        • Do nothing
    • Custom script: call DestroyForce( udg_TempForce )
Hope this could help.
 
Level 3
Joined
Dec 2, 2018
Messages
11
I think that works if is 2 teams right? what about a ffa? idk if i explain right but for example

choose random player
p1 start sending units to p3, so all units p1 train spawn in p3 base
p2 start sending units to p4, same here
p3 start sending units to p1, same here
p4 start sending units to p3, same here

here is the map if you want to see what im trying to say
 

Attachments

  • Dungeon Defense TD.w3x
    346.6 KB · Views: 22
Level 3
Joined
May 26, 2022
Messages
9
It's still not that clear to me. But I could deduce you are trying to say you want it be random FFA (like random player A sends units to random player B). If that's the case,

You could do something like this to get randomized array of players PlayerTargets:
  • Actions
    • Set TempForce = (All players controlled by a User player)
    • For each (Integer A) from 1 to (Number of players in TempForce), do (Actions)
      • Loop - Actions
        • Set TempPlayer = (Random player from TempForce)
        • Set PlayerTargets[(Integer A)] = TempPlayer
        • Player Group - Remove TempPlayer from TempForce
    • Custom script: call DestroyForce(udg_TempForce)
Then, you use the advantage that the global variable PlayerTargets is an array. By the way I did it, the index of the array serves the player number of your players:
  • PlayerTargets[ PLAYER_NUMBER ] = SOME_PLAYER
From here, when I say player target, I'm referring to the value above.

For example, when a player finishes training a unit, you spawn that unit to the RegionA of the player target of that player.
  • Events
    • Unit - A unit Finishes training a unit
  • Conditions
  • Actions
    • Set TempPlayer = PlayerTargets[(Player number of (Owner of (Trained unit)))]
    • Set TempInt = (Player number of TempPlayer)
    • -------- Units trained will spawn at this region: --------
    • Set TempLoc = (Center of RegionA[TempInt])
    • Unit - Move (Trained unit) instantly to TempLoc
    • Custom script: call RemoveLocation( udg_TempLoc )
    • -------- Units trained will move at this region: --------
    • Set TempLoc = (Center of RegionB[TempInt])
    • Unit - Order (Trained unit) to Move To TempLoc
    • Custom script: call RemoveLocation( udg_TempLoc )
Note that this is given by the idea that you did this:
  • Actions
    • Set RegionA[1] = P1A <gen>
    • Set RegionA[2] = P2A <gen>
    • Set RegionA[3] = P3A <gen>
    • Set RegionA[4] = P4A <gen>
    • Set RegionA[5] = P5A <gen>
    • Set RegionA[6] = P6A <gen>
    • Set RegionA[7] = P7A <gen>
    • Set RegionA[8] = P8A <gen>
    • Set RegionB[1] = P1B <gen>
    • Set RegionB[2] = P2B <gen>
    • Set RegionB[3] = P3B <gen>
    • Set RegionB[4] = P4B <gen>
    • Set RegionB[5] = P5B <gen>
    • Set RegionB[6] = P6B <gen>
    • Set RegionB[7] = P7B <gen>
    • Set RegionB[8] = P8B <gen>
Note that I'm not sure if this would work perfectly as you wanted it to be. I'm just pointing out my suggestion based on your input to me.
 

Attachments

  • Dungeon Defense TD.w3x
    346.7 KB · Views: 7
Last edited:
Level 45
Joined
Feb 27, 2007
Messages
5,578
It's possible to randomize player-vs-player pairs (so 1 sends to 3 and 3 sends to 1, for example) or a loop of players (1 sends to 3, 3 sends to 2, 2 sends to 6, 6 sends to 5, 5 sends to 4, 4 sends to 1). The former cares about even numbers but you could make a triad like the latter for any odd groups.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,285
If you want unique pairs the solution is to have a list of all players and then pick and remove 2 elements from that list, forming pairs. Some sort of handling is needed for odd players, possibly taking a fraction of all sends from everyone and sending their sends randomly to everyone.

A player group holding all participating players can be used as a list of players. Pick a random player from it and then remove that player from the list. Repeat twice to get both players for a pair. Repeat while player group has 2 or more players in it.
 
Level 3
Joined
Dec 2, 2018
Messages
11
Idk if is working xD I tried to modify the trigger to test it with computer but dont know how to do it

In case i wanted something like pick 2 random players and make them fight

p1 send units to p2 and p2 to p1
p8 to p3 and p3 to p8
p4 to p5 and p5 to p4....
If p7 is alone, then turn on "special wave" for this player (this create units like a normal wave)

How do i make it?
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,285
I already mentioned how to make the pairs. Add all players to a player group, pick a random player from that player group and then remove that player from the player group. Repeat a total of 2 times and you have a pair of players. This process can be repeated to get many pairs until there are no more players left in the player group.

When you have a pair you need a system to route where their units go. Simplest would be an array that maps one player index to their target player. This can be set up mutually for each pair selected using the above described logic.
 
Status
Not open for further replies.
Top