I'm running a trigger that will modify player resources and add bonus's if they get a certain amount of score. Is there anyway to apply triggers to any player so the trigger works as
-if "any player" achieves blah blah blah
-add 50 minerals to player that activated this trigger/(gets the score required)
I'm sick of creating 50 triggers of the same damn thing when if I could apply the trigger for any player would fix the problem in seconds. I've seen this in starcraft broodwar maps, but I can't find anything about this in starcraft 2
Please post your exact code causing the problem. It will be easier to explain the concept of multiplayer programming with a specific example.
In most simple cases, you can use the (Triggering Player) function to retrieve the player who caused the event to fire.
Example for a trigger displaying a greeting message for the player who entered "hello" in the chat:
greetingEventsGame-PlayerAnyPlayertypesachatmessagecontaining"hello",matchingExactlyLocalVariablesConditionsActionsDebug-Display(Combine("hello and welcome ",(Nameofplayer(Triggeringplayer))))asdebugoutputusingType01,andDodisplayitinthegamewindow
^ If player 1 types "hello", Triggering Player will return 1 and therefore the game will display "hello and welcome <name of player 1>. If player 3 enters the chat message, Triggering Player will return 3 and so forth.
I have 8 different levels of minerals you can get. I want level 1 to be 50 minerals and if the score is between 0-2500 it will constantly stay at 50 minerals fr the player with that score. I can't find anything in the trigger editor in variables or something with events that would allow me to do this. Everything asks for one specified player. Seriously who the hell put this editor together.
you are using EventPlayer without player Event, how should that work. maybe you should clarify what you want to do. as i understand it you want to give a periodic income to a player based on his kills (which are saved in a bank).
you also create a variable Killeds that is never used again. why?
so now add a "for loop" from 1 to NumberofPlayers. inside the loop add a new action to set the variable killeds, but change eventplayer to "selected integer". now add an if then else and pull your trigger condition into the if. again, change eventplayer to the loop int (selected integer). change your condition to use the variable. now put your action into the "then" and you are done.
First of, you can right click on the trigger root node in the right window and click on "copy as text" and post the trigger in the forums without having to take an image.
I also recommend switching back to the simple view because its easier to understand for beginners.
Second, the solution to your specific problem is a loop. Whenever you want to repeat a specific task for multiple players on a global level, you should use a "for each player" or "pick each player" loop. I recommend using a "for each player" loop because you will run into problems using "pick each player" only (This is beyond the scope of this question though).
To understand how this works we need to remember some facts:
- Players are just integers (Numbers between 0 and 15 in this case)
- A player based loop will take a player group as parameter (a player group is a container storing players/integers) and loop through all entries of the container one by one
- There a native function returning various defined player groups, such as "Active Players", "All Players" and so forth, but you can also create your own groups and add specific players to them.
For your specific problem, a solution using player groups and loops could look approximately like this:
So, lets say there are 2 players in the game currently playing (Slots 5 and 8). The "Active Players" function will then return a player group in the following form: (5,8)
The loop will now use the specified loop variable (current player in the above example) and set it to the first player of the player group (current player = 5).
Then we check our conditions normally, using 5 as player index.
After that, the loop will set current player to 8 and run the checks again. Once it looped through all entries of the group it will exit.