• 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 to Randomly Pick Player

Status
Not open for further replies.
Level 2
Joined
Nov 27, 2012
Messages
7
Hello, I'm working on a remake of a Starcraft original map and need help with this trigger.

At the start of the game, a player is randomly picked to be "The Thing". I'm mainly stuck on how to "randomly" pick a player for this.

I've attached a picture of what I'm trying to do.
 

Attachments

  • Randomly Select Player Picture.png
    Randomly Select Player Picture.png
    1,012.5 KB · Views: 116
Level 12
Joined
Sep 11, 2011
Messages
1,176
Hello, I'm working on a remake of a Starcraft original map and need help with this trigger.

At the start of the game, a player is randomly picked to be "The Thing". I'm mainly stuck on how to "randomly" pick a player for this.

I've attached a picture of what I'm trying to do.

  • Pick Random Player
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set tempPlayerGroup = (All players matching ((((Matching player) slot status) Equal to Is playing) and (((Matching player) controller) Equal to User)))
      • Player Group - Pick every player in tempPlayerGroup and do (Actions)
        • Loop - Actions
          • Set PlayerCount = (PlayerCount + 1)
          • Game - Display to (All players) the text: (String(PlayerCount))
      • Custom script: call DestroyForce (udg_tempPlayerGroup)
      • Set The_Thing = (Player((Random integer number between 1 and PlayerCount)))
      • Game - Display to (All players) the text: (Name of The_Thing)
- tempPlayerGroup is a Player Group variable.
- The_Thing is a Player variable.
- PlayerCount is an Integer Variable.

now you can do anything to The_Thing.
i made the message to check if the random picking is working or not, you can delete them.
 
Level 2
Joined
Nov 27, 2012
Messages
7
I've finally managed to find and add most of the triggers you've told me too.

The custom script you gave me, had a error, disabling the trigger not allowing me to save though.

I'd also like to ask and see if everything I did is correct. I'll attach a screen shot.
 

Attachments

  • Random Select Trigger.png
    Random Select Trigger.png
    15.4 KB · Views: 124
Level 12
Joined
Sep 11, 2011
Messages
1,176
I've finally managed to find and add most of the triggers you've told me too.

The custom script you gave me, had a error, disabling the trigger not allowing me to save though.

I'd also like to ask and see if everything I did is correct. I'll attach a screen shot.

your Player Group variable should be tempPlayerGroup not TempPlayerGroup. if you want to make it TempPlayerGroup, then the custom script should also be the same TempPlayerGroup. get it ?
custom script are case sensitive, you need to be careful.

the PlayerCount should use an arithmetic function
  • Set PlayerCount = (PlayerCount + 1)
anyway, you don't need to upload a picture.
just right-click on the title of the trigger above the events and choose Copy As Text.
then paste it here using [Trigger]PASTE IT HERE[/Trigger]
 
Level 2
Joined
Nov 27, 2012
Messages
7
Ok, so the trigger isn't working :/

  • Randomly Pick The Thing
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set TempPlayerGroup = (All players matching ((((Matching player) slot status) Equal to Is playing) and (((Matching player) controller) Equal to User)))
      • Player Group - Pick every player in TempPlayerGroup and do (Actions)
        • Loop - Actions
          • Set PlayerCount = (PlayerCount + 1)
          • Game - Display to (All players) the text: (String(PlayerCount...
      • Custom script: call DestroyForce (udg_TempPlayerGroup)
      • Set The_Thing = (Player((Random integer number between 1 and PlayerCount)))
      • Unit - Create 1 Form Changer for (Matching player) at (Center of Spawn Thing Selector <gen>) facing Default building facing degrees
      • Unit Group - Pick every unit in (Units owned by The_Thing of type Sanity) and do (Unit - Kill (Picked unit))
I added a few things at the bottom, because they're needed as well.
 
Try changing the event to "Time - Elapsed game time is 0.00 seconds" (or 0.5 seconds or something). I don't think players are flagged as playing at map init. (not 100% positive, but it is worth a try)

EDIT: Nevermind. It returned true. What part isn't working? Do the messages show up? Also, make sure your trigger is enabled. In the screenshot it wasn't.
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
It should be just like this;
  • Random Player
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set TempPlayerGroup = (All players matching ((((Matching player) controller) Equal to User) and (((Matching player) slot status) Equal to Is playing)))
      • Set TempPlayer = (Random player from TempPlayerGroup)
      • -------- TempPlayer IS THE RANDOM PLAYER --------
      • Game - Display to (All players) the text: (The name of random player is + (Name of TempPlayer))
      • Custom script: call DestroyForce(udg_TempPlayerGroup)
Remember, we have a function Random Player From Player Group

If you said it's not working, probably you're testing the map, alone ?
Because the condition filters any other player other than actual player (Human player) instead of AI.

Test map is here.
 

Attachments

  • Random Player.w3x
    12.4 KB · Views: 63
Status
Not open for further replies.
Top