I am attempting to use triggers to distribute 5 minerals every 3 seconds across any number of players 1 through 5. I want them all to receive an equal share of the 5 minerals, and for none of it to be lost.
I got recommended a beautiful trigger by somebody else, and here it is:
Note: Not listed here is the variable array Teams, and the moving of players into two separate Teams, but it has been done correctly. That I have been able to verify.
My problem is that the MoneyNotGivenYet variable he recommended is designed to eventually distribute the minerals that can't be distributed as the numbers do not divide evenly. As in, when 5 minerals is distributed across 2 players, they can only receive 2 minerals every 3 seconds. This variable would make it so that it alternates 2 minerals, then 3 minerals, then 2 minerals, then 3 minerals, giving them, on average, the proper amount.
However, for whatever reason, it isn't working. Does anybody have any idea what the problem is?
Doesn't look like the math in that code corresponds to your written statement of how it should work.
First, I'd do an integer arithmethic function: intBaseMoneyPerPlayer = (MoneyPerTeam / TeamMembers) and add that to each player's minerals
Second, I'd take the remainder of the last function (using modulus) and then select unique random players to give 1 each to.
If you don't like the random approach, then you'd need flags on each player to record who got an "extra piece" last cycle (or "extra piece" sum) and to favor those who did not get an extra piece last time (or lower numbers in case of sum). In any case, you'll still have to pick a player arbitrarily in some cases, and distribution theory says both methods will work out to "about the same" after a large sample set.
Mathematically, it ought to work. The MoneyNotGivenYet will continue to add upon itself until it is finally large enough to give each player additional minerals, and it will increase MoneyPerPlayer until that is higher enough to return MoneyNotGivenYet back to zero.
Whatever reason it doesn't work, I'm not sure.
I'd like to try your idea, but I have absolutely no idea what you mean by modulus.
it doesn't work because "money not given yet" is reset to a value of 0 every time the trigger runs....
Ill make a working example for you....
There you go .... that should do exactly what you want it to do...... any problems send me a pm
the bit at the end is just some debug out puts so you can see what its doing and play around with it a bit.... i generally go a bit overboard on my output messages but they come in handy when something stops working as intended
Sorry I misspoke...meant "modulo" function. Use google - 'tis our friend. Looks like SouLCarveRR hooked you up anyway :) I'm actually not sure his code will work for you either (doesn't seem to match up with what you want exactly), but perhaps that's my misunderstanding.
Oh I see, you're not assigning all available minerals on each loop, you're carrying the leftovers over to the next loop. I guess I thought you wanted to distribute all minerals each loop, which you could do following my algorithm. If the current code is what you want, awesome.
Your code would definitely be more optimal for, say, a team of three or four players... Where it will take three or four loops to distribute their additional mineral. But, I also just don't like the idea of distributing randomly, and I'm fine with the way this code averages out to exactly 5 minerals per 3 seconds.
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
Hey all.
I am attempting to use triggers to distribute 5 minerals every 3 seconds across any number of players 1 through 5. I want them all to receive an equal share of the 5 minerals, and for none of it to be lost.
I got recommended a beautiful trigger by somebody else, and here it is:
Note: Not listed here is the variable array Teams, and the moving of players into two separate Teams, but it has been done correctly. That I have been able to verify.
My problem is that the MoneyNotGivenYet variable he recommended is designed to eventually distribute the minerals that can't be distributed as the numbers do not divide evenly. As in, when 5 minerals is distributed across 2 players, they can only receive 2 minerals every 3 seconds. This variable would make it so that it alternates 2 minerals, then 3 minerals, then 2 minerals, then 3 minerals, giving them, on average, the proper amount.
However, for whatever reason, it isn't working. Does anybody have any idea what the problem is?
@deleted_7920358: Go
Doesn't look like the math in that code corresponds to your written statement of how it should work.
First, I'd do an integer arithmethic function: intBaseMoneyPerPlayer = (MoneyPerTeam / TeamMembers) and add that to each player's minerals
Second, I'd take the remainder of the last function (using modulus) and then select unique random players to give 1 each to.
If you don't like the random approach, then you'd need flags on each player to record who got an "extra piece" last cycle (or "extra piece" sum) and to favor those who did not get an extra piece last time (or lower numbers in case of sum). In any case, you'll still have to pick a player arbitrarily in some cases, and distribution theory says both methods will work out to "about the same" after a large sample set.
Happy coding :)
@jcraigk: Go
Mathematically, it ought to work. The MoneyNotGivenYet will continue to add upon itself until it is finally large enough to give each player additional minerals, and it will increase MoneyPerPlayer until that is higher enough to return MoneyNotGivenYet back to zero.
Whatever reason it doesn't work, I'm not sure.
I'd like to try your idea, but I have absolutely no idea what you mean by modulus.
@deleted_7920358: Go
it doesn't work because "money not given yet" is reset to a value of 0 every time the trigger runs....
Ill make a working example for you....
There you go .... that should do exactly what you want it to do...... any problems send me a pm
the bit at the end is just some debug out puts so you can see what its doing and play around with it a bit.... i generally go a bit overboard on my output messages but they come in handy when something stops working as intended
@deleted_7920358: Go
Sorry I misspoke...meant "modulo" function. Use google - 'tis our friend. Looks like SouLCarveRR hooked you up anyway :) I'm actually not sure his code will work for you either (doesn't seem to match up with what you want exactly), but perhaps that's my misunderstanding.
@SouLCarveRR: Go
Worked perfectly!! Thanks man. This has been biting me in the ass for quite some time.
@jcraigk: Go
It definitely looks confusing, but I understand the theory behind it. Thanks for your help, though!
@deleted_7920358: Go
Oh I see, you're not assigning all available minerals on each loop, you're carrying the leftovers over to the next loop. I guess I thought you wanted to distribute all minerals each loop, which you could do following my algorithm. If the current code is what you want, awesome.
@jcraigk: Go
Your code would definitely be more optimal for, say, a team of three or four players... Where it will take three or four loops to distribute their additional mineral. But, I also just don't like the idea of distributing randomly, and I'm fine with the way this code averages out to exactly 5 minerals per 3 seconds.