HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Trigger for when a player leaves

12-28-2005, 09:11 PM#1
Undead_Lives
I have two questions with my trigger (I am NOT using JASS btw) that basically says this:
When a player leaves, give the rest of his team sharing of his income (this is a lot of long If, Then, Else (Multiple Functions) triggers (depending on how many players on that player's team are left)) then, share units and sight with the rest of the player's team and finally display the text that the player has left (to everyone).

My first question is how do i take the current gold of the player and divert it (right now all i have is incoming gold)?
My second question is how do i set the player's name (ex. Undead_Lives) in the text to say "_____ has left the game"?

And a final quick question, is there an easier way to divert gold without the numerous If, Then, Else (Multiple Functions)?
12-28-2005, 11:13 PM#2
Starcraftfreak
1) Player - Current Gold

2) Player - Player Name

Now the question is, where do you find them, right? 1) is an integer value, so whenever you can select an integer value, you shall find it. 2) is a string. Just use it in String concatenation.

As for your logic issue, please post your trigger. You can do so easily by right-clicking in the function list and selecting "Copy as Text". Please use the trigger tags as described here: http://www.wc3campaigns.net/showthread.php?t=78403
12-29-2005, 12:42 AM#3
Undead_Lives
first, i'd like to say thanks for the help
second, i figured my first question on my own :D
the way i did it was as follows:
Player - Add ((Player 2 (Blue) Current gold) / 4) to Player 3 (Teal)
etc.
third, im not understanding what your saying with strings, could you please tell me exactly what i need to put in the text box? is it "Player2$"?

and finally, here is my code.

Trigger:
Player2 leaves
Collapse Events
Player - Player 2 (Blue) leaves the game
Conditions
Collapse Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Player 3 (Teal) slot status) Equal to Is playing
(Player 4 (Purple) slot status) Equal to Is playing
(Player 5 (Yellow) slot status) Equal to Is playing
(Player 6 (Orange) slot status) Equal to Is playing
Collapse Then - Actions
Player - Add ((Player 2 (Blue) Current gold) / 4) to Player 3 (Teal) Current gold
Player - Add ((Player 2 (Blue) Current gold) / 4) to Player 4 (Purple) Current gold
Player - Add ((Player 2 (Blue) Current gold) / 4) to Player 5 (Yellow) Current gold
Player - Add ((Player 2 (Blue) Current gold) / 4) to Player 6 (Orange) Current gold
Player - Divert 25% of the Gold income of Player 2 (Blue) to Player 3 (Teal)
Player - Divert 25% of the Gold income of Player 2 (Blue) to Player 4 (Purple)
Player - Divert 25% of the Gold income of Player 2 (Blue) to Player 5 (Yellow)
Player - Divert 25% of the Gold income of Player 2 (Blue) to Player 6 (Orange)
Collapse Else - Actions
Do nothing
Game - Grant shared vision and full shared unit control of Player 2 (Blue) units with his/her allies
Game - Display to (All players) for 30.00 seconds the text: $Player2 has left t...

NOTE: i have 65 total If, Then, Else (Multiple Functions) Actions, to compensate for the following variables
how many players are still playing
if the player is unused
if the player has left.
I know that it had to be exact, so i made it exact.
However, I could not include them all since i maxed out the 50000 characters max by over 2000 characters. lol.
12-29-2005, 01:38 AM#4
Murder1833
There wouldn't be need for that. We call it variables and integers.
12-29-2005, 04:15 AM#5
Undead_Lives
then please, explain more than just "use integers and variables".
12-29-2005, 06:17 AM#6
aaero
How about this for problem #1 (you need to provide more information for problem #2. Where does it say the player name? In a leaderboard in the top right?):

Variables:
PlayerCount (integer)
GoldDistributed (integer)

Trigger:
Collapse 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
(etc for all players)
Conditions
Collapse Actions
Set PlayerCount = (Number of players in (All players matching (((Picked player) slot status) Equal to Is playing)))
Set GoldDistributed = (((Triggering player) Current gold) / PlayerCount)
Collapse Player Group - Pick every player in (All players matching (((Matching player) slot status) Equal to Is playing)) and do (Actions)
Collapse Loop - Actions
Player - Set (Picked player) Current gold to (((Picked player) Current gold) + GoldDistributed)
Player - Divert (100 / PlayerCount)% of the Gold income of (Triggering player) to (Picked player)

That will really clean things up for you. You could nitpick this code a bit as far as efficiency, but honestly it won't run very often and you'll never tell the difference if your computer can run warcraft.

Let me explain some stuff you might be confused about. Player count is just a count of the number of players currently in the game. The first thing we do is set that to be accurate. Gold distributed is another variable we use to store how much gold everyone will be getting. It's an integer, which means it's an even number (no decimals). It will be truncated, so if there were 5 players and a player drops who had 7 gold, the 4 remaining will each get 1. If he had 8, they'd all get 2 of course.

Once we know the number of players left and the amount of gold we'll be giving them, we do a loop to loop through every active player. We increase that players gold and divert some income from the player who dropped to the current player in the loop.

Ask questions if you have any more, someone will help you out if I'm not around :).

EDIT: I didn't take care of sharing vision / sight, but if you have a good understanding of what I'm doing it will be very easy to do.
12-29-2005, 07:28 AM#7
Anitarf
One thing to correct on aaero's post: the condition in the "all players matching..." parts. You have to use "matching player" in there, not "picked player".

Also, I think you need two conditions to be true, the player must still be playing and he must also be an ally of the leaving player (I suppose there are more teams), aaero missed that one. You can easily do that with an "and" condition which allows you to use two conditions instead of one. Then just use the player slot status comparison and the "boolean - player is an ally of player" comparison to filter out the right players for gold sharing.

You might also want to set the leaving player's gold to 0 after you share it, I'm not sure if it can affect anything, but better be safe.

Other than that, aaero's trigger gets the job done nicely. It's shortness should really motivate you to learn to use variables and variable arrays. :)
12-29-2005, 04:11 PM#8
aaero
Anitarf is right on with his reply, as is usual when he's correcting me :)

I went ahead and corrected the original trigger to say Matching Player instead of Picked Player where necessary: here's the difference.

Picked Player:
When you do a Pick all Players in Player Group, this refers to the Player that is currently "picked". Pick all Players will loops through every player in the group (ie with All Players first it's Player 1, then Player 2, then Player 3).

Matching Player:
This is for All Players Matching Condition. It's actually kind of hard to explain, but I'll try my best using the example.

Player Group - Pick every player in (All players matching (((Matching Player) slot status) Equal to Is playing)) and do (Actions)

In this example, it's saying pick every Player where that Player is currently playing. You use Matching Player for the condition to show this.
12-29-2005, 07:33 PM#9
Anitarf
The short story is, use "matching player" in the pick-every-player conditions, and "picked player" in the actions.

A longer explanation: what the action "Pick all Players in Player Group matching condition" does is, it loops through all the players in the group, and if the condition is true, it picks that player and does it's loop actions. However, when checking the conditions, the player isn't "picked" yet, so you can't use "picked player" in the condition, because it won't refr to the player that the conditions are being checked for. That player is the "matching player", and if the condition is met he becomes the picked player for the actions of the loop to use.
12-31-2005, 06:50 PM#10
Undead_Lives
Well, thanks a lot for the help guys.

As for my second question, i think i solved it in the following trigger
thanks again, i have used the trigger

EDIT: i dont think i set the triggering player's gold to zero since there is already a diverting of his gold income, otherwise that part would be a waste.

EDIT2: so this is wat the end result is:
Trigger:
Playerleaves
Collapse Events
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 8 (Pink) leaves the game
Player - Player 9 (Gray) leaves the game
Player - Player 10 (Light Blue) leaves the game
Player - Player 11 (Dark Green) leaves the game
Player - Player 12 (Brown) leaves the game
Conditions
Collapse Actions
Game - Grant shared vision and full shared unit control of (Triggering player) units with his/her allies
Game - Display to (All players) for 15.00 seconds the text: ((Name of (Triggering player)) + has left the game)
Set Playercount = (Number of players in (All players matching ((((Matching player) slot status) Equal to Is playing) and (((Triggering player) is an ally of (Matching player)) Equal to True))))
Set Golddistributed = (((Triggering player) Current gold) / Playercount)
Collapse Player Group - Pick every player in (All players matching ((((Matching player) slot status) Equal to Is playing) and (((Triggering player) is an ally of (Matching player)) Equal to True))) and do (Actions)
Collapse Loop - Actions
Player - Set (Picked player) Current gold to (((Picked player) Current gold) + Golddistributed)
Player - Divert (100 / Playercount)% of the Gold income of (Triggering player) to (Picked player)


NOTE: these are the full parts that got cut off
-Set Playercount = (Number of players in (All players matching ((((Matching player) slot status) Equal to Is playing) and (((Triggering player) is an ally of (Matching player)) Equal to True))))
-Player Group - Pick every player in (All players matching ((((Matching player) slot status) Equal to Is playing) and (((Triggering player) is an ally of (Matching player)) Equal to True))) and do (Actions) .