Working on a project, and right now I am staring at my Income trigger, with no idea what to do.
What I have working is that each player on a 5 player team receives 1 mineral every 3 seconds. That's simple, duh. However, I also want to be able to redistribute income based on any different number of players.
For a team that starts with 5 players, and then all of them quit except 1 player, I want him/her to earn 5 minerals every 3 seconds. If the game starts with 5 players, this works naturally, the last player remaining gains the income of those who quit, adding up to 5 minerals per 3 seconds.
However, if the game starts with only 1 player, I want him to gain 5 minerals per 3 seconds. The way that I allowed for this was: modify minerals: add ((5) / ((Number of Allies of Player X..) + 1)) This trigger works for this scenario, but it makes it so that when a team starts with 5 players and any number of them quit, it both increases the income of all the players, and redistributes the income of those who quit, giving the remaining players more than they should have.
The only way I can think of for solving this problem is having triggers for every number of players on a team with conditions for those respective numbers. That seems a bit cumbersome. Does anybody have a better solution?
There's an event Player leaves game which you could use. Every time that event is triggered, you update variables that flag whether a particular player is in the game or not. Then based on the amount of players remaining, you can redistribute the resources.
I will look at this one. There are some complications, but a new idea could lead to a solution.
The following should do what you want to do. It will give as much money as it can to each player that it can in a fair form (so not favoring any player). Any money that couldn't be distributed (for example distributing 5 minerals over 2 players will not work, you will have 1 mineral remaining) will be carried over to the next distribution.
Teams = (Empty player group) <Player Group>
MoneyNotGivenYet = 0 <Integer>
Money Per Turn
Note: You will need to add the players to the player group variable "Teams" yourself, do check if the slots are actually occupied by players or not. Here I set it up for 2 teams, namely Teams and Teams.
Trigger Money Per Turn
General - If (Conditions) then do (Actions) else do (Actions)
TeamMembers > 0
Variable - Set MoneyPerPlayer = ((MoneyPerTeam + MoneyNotGivenYet[Team]) / TeamMembers)
Player Group - Pick each player in Teams[Team] and do (Actions)
Player - Modify player (Picked player) Minerals: Add MoneyPerPlayer
Variable - Set MoneyNotGivenYet[Team] = ((MoneyPerTeam + MoneyNotGivenYet[Team]) - (MoneyPerPlayer * TeamMembers))
Note: Super important that you use Integers and use the exact order of the brackets I put in my triggers. In integer maths 5/2 = 2 (and not 2.5 and not 3). This means that if you have 2 players in a team they will get 2 minerals the first 3 seconds and 3 minerals the next 3 seconds (then it continues 2-3-2-3, ...). If you ever want to give a different amount then 5 minerals to the team, then it will still work.
Thanks for the really in-depth guide here. It looks like it should work, but I am having one problem. In the trigger Money Per Turn, in the Variable - Set TeamMembers line, I am trying to change it from (Number of players in (Allies of Player 1)) to (Number of players in (Teams[Team])), but when I select 'Allies' to change it, I'm not seeing any variables that I can select.
Perhaps I'm incorrectly setting up the Teams variable, but I can't figure it out.
Edit: Also, I like how this works, and I want to apply it to many other things. Is there any way to set up a variable like the Teams variable, that I can use for a similar For loop, that will simply put out each player? As in rather than putting out the value of each team, it will put out the value of each player, and allow me to modify their properties etc.?
Okay, so it turns out that the MoneyNotGiven variable isn't doing its job. I think I have it set up properly, it just doesn't work.
Let me check that I understand how it's supposed to work. The initial value is zero, and it is always added to the MoneyPerPlayer. At the end of the loop, it revises itself based on its own previous value (included in the calculations), the MoneyPerTeam, and subtracted the amount of money that was distributed last turn. This revision will increase MoneyNotGiven until the MoneyPerPlayer is high enough to reduce it back to zero.
I tested it with all different numbers of players (using computers). 1 player is 5 minerals per 3 seconds, 2 players is 2 minerals per 3 seconds, and 3 or more players is 1 mineral per 3 seconds.
So, essentially, it is adjusting for the number of players properly, but not carrying over the MoneyNotGiven per that last Set Variable action.
In the example, the MoneyNotGivenYet variable seems to be of size 1. Maybe try changing it to the number of teams in the map?
EDIT: RandomNoExit mentioned that his code only applies for 2 teams. Maybe there were other variables/code that you didn't extend for more players/teams?
I thought of changing the size of MoneyNotGiven. But then I looked back up at the variable that actually defines the number of teams, and it's listed as an array of size  as well, to hold the two teams. I figured it made sense that that and MoneyNotGiven should be the same. I guess I will try changing it.
The code would seem to suggest that the empty player group variable Teams and the MoneyNotGiven variable are the only ones that need to be large enough to accommodate both teams, as they are the only ones that need to last through more than one run of the loop. The other ones get changed every time the loop runs, and apply to both teams one at a time, for different values.
Sorry for the late response. I hadn't logged in for a couple of days.
The good news is that I found the problem :).
Each time the trigger runs (so every 3 seconds), it "forgets" the values of the local variables. This means that every tick the "MoneyNotGivenYet" variable is reset to 0 causing it to not carry over any money.
In order to fix this problem, create a new GLOBAL variable called "MoneyNotGivenYet" and replace all local variables of "MoneyNotGivenYet" by this. In the end you should delete the local variable completely to make sure you didn't accidentally forget to change it somewhere (as it will give a warning if you still have it somewhere in your code).
Let me know if you still have problems, otherwise I can upload the map I have where it seems to works. Also note I changed my original post.
Thank you so much! I can hardly complain about when you respond when you've so generously provided me with this trigger.
It works perfectly, it's simple, and it's organized. Hopefully I'll be able to stop asking for so much help soon, because assistance like yours not only provides an immediate solution, it also teaches me a lot.
I essentially ant to do the same thing, I have 2 teams one made of 7 players one of 1. Each player has a hero each and when all heroes are dead for a particular team its victory for the other team. (not really sure how to explain this lol.) But if people leave after there hero dies I dont want that money to be apart of the distribution, but if there hero was alive then distribute, another problem is, when they leave the hero then dies which kills everything else owned by that player.SO I think this is more complex sadly :( I want the income to be 2 minerals each for the team of 7 (the team of 1 gets 5 minerals each time no matter what) I think i want the same as Wrtah bu t i am not sure, RandomNoExt maybe we could test my map to test the balancability of this idea, but either way I would have no idea how to implement this,
The solution I posted above is in the right direction to solve part of your problem you listed.
Each time interval you will need to set the MoneyPerTeam variable to be 2 * (number of players in the team with alive heroes + players that left with a living hero) and then distribute among the people with living heroes in the team.
You'll also need to replace all arrays by simple variables since you'll only need to do this for 1 team. This of course means that the outer loop of "General - For each integer Team from 0 to 1 with increment 1, do (Actions)" will not be present in your solution.
As a side note: Giving an advantage of leaving over dying means that people will leave as soon as they see that they are about to die. If people don't leave they will get flamed at by other players. (Except if there is a good reason for them to stay until the end of game.)