• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Leaver gold redistribution

Status
Not open for further replies.

Gojira2000

G

Gojira2000

I can't seem to fix this trigger (not made by me) were when an ally leaves, his gold is split evenly and then redistributed to his allies every three minutes

It only seems to only give the remaining gold to to the player red on the first team 1 (or purple if red has left and so on) and player blue for team 2 (or teal if blue has left)

I really don't know how to fix this please help, any help will be greatly appreciated, thanks
 
Level 5
Joined
Jan 5, 2012
Messages
116
I use this trigger to split the leaver's gold to the other players. Not sure if it's correct way to do it, but seems to be doing the job well.

  • SplitControlledPlayerMoney
    • Events
      • Player - Player 1 (Red)'s Current gold becomes Greater than 0.00
      • Player - Player 2 (Blue)'s Current gold becomes Greater than 0.00
      • Player - Player 3 (Teal)'s Current gold becomes Greater than 0.00
      • Player - Player 4 (Purple)'s Current gold becomes Greater than 0.00
      • Player - Player 5 (Yellow)'s Current gold becomes Greater than 0.00
      • Player - Player 6 (Orange)'s Current gold becomes Greater than 0.00
      • Player - Player 7 (Green)'s Current gold becomes Greater than 0.00
      • Player - Player 8 (Pink)'s Current gold becomes Greater than 0.00
      • Player - Player 9 (Gray)'s Current gold becomes Greater than 0.00
      • Player - Player 10 (Light Blue)'s Current gold becomes Greater than 0.00
      • Player - Player 11 (Dark Green)'s Current gold becomes Greater than 0.00
    • Conditions
      • (((Triggering player) slot status) Not equal to Is playing) or (((Triggering player) controller) Equal to Computer)
    • Actions
      • Set y = 0
      • Player Group - Pick every player in (All players matching ((((Picked player) slot status) Equal to Is playing) and ((((Picked player) controller) Not equal to Computer) and (((Team number of (Picked player)) Equal to (Team number of (Triggering player))) and ((Picked player) Not equal to (Trigg and do (Set y = (y + 1))
      • If (y Equal to 0) then do (Skip remaining actions) else do (Do nothing)
      • Set y = (((Triggering player) Current gold) / y)
      • Player Group - Pick every player in (All players matching ((((Picked player) slot status) Equal to Is playing) and ((((Picked player) controller) Not equal to Computer) and (((Team number of (Picked player)) Equal to (Team number of (Triggering player))) and ((Picked player) Not equal to (Trigg and do (Player - Add y to (Picked player) Current gold)
      • Player - Set (Triggering player) Current gold to 0
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,190
I can't seem to fix this trigger
What trigger? I see no trigger...

To re-distribute gold its simply a mater of doing the following steps.
1. Get the amount of gold to re-distribute. In this case get the dropper's gold.
2. Resolve the force of players you want to split the gold with. In this case check all players for those still active and add them to a force (player group).
3. Get the amount of gold to give to each player by dividing the result of 1 with the number of players in the result of 2.
4. Add gold to appropriate players. Add the gold result from 3 to all the players from result 2.
5. Conserve wealth to prevent loss due to rounding (otherwise gold could disappear, unfair!). Add to some player from the result of 2 (either random, or maybe the first) the amount of gold resulting from the result of 1 "modulus" (this operation returns the remainder of a division operation) the number of players in the result of 2.

Razwerd, I do not see where you perform step 5 in that trigger. The result would be players gaining units of gold less than the number of players would not share them as the result is always 0. Additionally large player number and small gold income increments would result in massive loss of wealth (as much as 48% of what is earned for 23 gold increments with 12 players!). This is why performing step 5 is so important.
 
Level 28
Joined
Mar 25, 2008
Messages
2,955
This one's from my TD map.
It works.

  • Verlassen Trigger
    • 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
      • Player - Player 5 (Yellow) leaves the game
      • Player - Player 6 (Orange) leaves the game
      • Player - Player 7 (Green) leaves the game
      • Player - Player 8 (Pink) leaves the game
      • Player - Player 9 (Gray) leaves the game
    • Conditions
    • Actions
      • Set tmpgrp = (Units in (Playable map area) owned by (Triggering player))
      • Unit Group - Pick every unit in tempgrp and do (Actions)
        • Loop - Actions
          • Player - Add (Point-value of (Picked unit)) to (Triggering player) Current gold
          • Unit - Kill (Picked unit)
      • Set tmpgrp_rest = (All players matching ((((Matching player) controller) Equal to User) and (((Matching player) slot status) Equal to Is playing)))
      • Player Group - Pick every player in tmpgrp_rest and do (Actions)
        • Loop - Actions
          • Player - Add (((Triggering player) Current gold) / (Number of players in tempgrp_rest) to (Picked player) Current gold
      • Set QuittersGold = ((Triggering player) Current gold)
      • Leaderboard - Remove (Triggering player) from (Last created leaderboard)
      • Player Group - Remove (Triggering player) from Defenders
      • Game - Display to (All players) the text: ((Name of (Triggering player)) + has left the game)
      • Game - Display to (All players) the text: ((All players receive + ((String((QuittersGold / (Number of players in tempgrp_rest) + gold)) + from the leaving player)
      • Player - Set (Triggering player) Current gold to 0
      • Custom script: call DestroyGroup(udg_tempgrp)
You can remove the first Pick Unit Group if not needed
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,190
I don't really understand what that means, gold disappears?!
What else do you think would happen to the integer remainder from integer division? It must go somewhere and in your case it is in the waste bin since you do not give it to anyone.

And can I split the lost gold among players?
No since it is fractional and gold is integer as such incompatible. One way is to bias it towards a player so that all the gold is paid out instantly. Another way involves a gold accumulator which persistently keeps track of the amount of remainder gold so that it is not lost (although it will not be instantly paid out but is limited to at most N-1 gold not paid out where N is player number).

The accumulator approach works by adding the value in the accumulator to the amount earned (would replace step 1 from my list). As such the remainder gets recycled through another division operation. Since the remainder from the earned amount division added to the remainder from the previous division might be larger than the dividend the result is that the total remainder is reduced and converted into equal payout. At the end you need to set the accumulator to the remainder from the division of the new step 1 so that it can be repeated next income.

Squiggy, your system also does not conserve currency. Since it is an once off event you should chose a player to give the division remainder to.
 
Level 28
Joined
Mar 25, 2008
Messages
2,955
Isn't the currency 'Gold'?

Aren't you overcomplicating this a bit?
I do appreciate your effort but even if the player leaving had 1000 gold, split by 3 remaining players, one of them would gain +1 more than the other two if I remember correctly.
You'd have to implement a system which keeps track of the exact comma values in Real instead of Integer and set the leaver's gold to zero, then split his 'real property' throughout the other players.
And even then, you'd have to deal with the rounding that comes with Real -> Integer.
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,190
Aren't you overcomplicating this a bit?
Currency computations are among the hardest in computing.

I do appreciate your effort but even if the player leaving had 1000 gold, split by 3 remaining players, one of them would gain +1 more than the other two if I remember correctly.
No, all 3 of them would gain 333 gold and 1 gold would be destroyed permanently.

This is because this action...
  • Add (((Triggering player) Current gold) / (Number of players in tempgrp_rest) to (Picked player) Current gold
Starts by getting the current gold (1,000) and dividing it by 3. The result of this integer division is 333 which is the amount of gold added to the appropriate players. This is repeated 3 times in total for different players with each getting exactly 333 gold.

You never get the division remainder and do anything with it before removing all the gold so it is simply lost. In your case this is insignificant (a loss of 0.1% people will usually never notice and if they had more than 1,000 gold it would be even lower) however in the case of Razwerd it could reach as much as 100% loss (individual units of gold with 2 players!) as his is runs for significantly smaller sums of gold.

You'd have to implement a system which keeps track of the exact comma values in Real instead of Integer and set the leaver's gold to zero, then split his 'real property' throughout the other players.
And even then, you'd have to deal with the rounding that comes with Real -> Integer.
Or you do what I said and either bias the result to a single player or use an accumulator to keep track of the remainder for subsequent division operations.

Biasing one of the recipients has the advantage in that is forces all gold to be immediately paid out. No gold is stuck in limbo as it is always paid out as soon as it is earned. To make it more fair your could bias players based on some ordering (round robin style) or even random (averages out mostly).

The accumulator has the advantage that in total it assures that all payment is fair. The disadvantage is that currency can be stuck for extended periods (between distributions of the same type) and that currency will even become permanently stuck if no further distributions occur.

This is why I would advise Squiggy uses a biasing implementation as droppers are rare but Razwerd uses an accumulator implementation since he redistributes when any gold is earned (eg every mine worker returns, or every unit that gets killed).
 
Level 28
Joined
Mar 25, 2008
Messages
2,955
No, all 3 of them would gain 333 gold and 1 gold would be destroyed permanently.
My bad.

My point is that I've never seen someone playing wc3 with a calculator and checking for the amount of gold he receives upon a Player leaving.. and crying because he receives two bucks less.

Don't take this badly but I never advised to use Razwerd's solution ;)
 
Level 5
Joined
Jan 5, 2012
Messages
116
I think I understand now, I'll try to fix it. However, there are really 4 players in the map so the remainder should be a small number, not very noticeable or impactful on the game. Gojira2000 still hasn't said if we helped him make a system or not, please do.
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
I really dont think people give a shit in any kind of map on any kind of competition level if they receive like 0.25 gold less(for 4 players if fifth leaves). You cant use sub 1 gold in shops anyways, and even if two another players were to leave, you would only be up by 1 gold, so thats waste of time to implement something for 1 gold per game at most. Even with 12 players and everyone but you leaves, it is like 2 gold
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,190
My point is that I've never seen someone playing wc3 with a calculator and checking for the amount of gold he receives upon a Player leaving.. and crying because he receives two bucks less.
In your case it is trivial. A few gold out of thousands no one will miss even if it is still incorrect and surprisingly easy to correct. On the other hand if you are distributing gold in units of 10 or other equally small units the error would be unacceptable and result in significant gold loss from that source.

I really dont think people give a shit in any kind of map on any kind of competition level if they receive like 0.25 gold less(for 4 players if fifth leaves). You cant use sub 1 gold in shops anyways, and even if two another players were to leave, you would only be up by 1 gold, so thats waste of time to implement something for 1 gold per game at most. Even with 12 players and everyone but you leaves, it is like 2 gold
If you are constantly handing out gold in units of 10 or so to all players then you will build up significant error over time, possibility amount to hundreds of gold.

In reality it takes only half a minute to implement or less. The trade off for time ratio is certainly well worth it. It is simply a mater of a couple more actions for the sake of correctness.
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,190
didnt read the whole thread, but the OP post seems to hint that he hands the gold out at once, so 0.5 gold max(for 2 players) loss anyways.
I can't seem to fix this trigger (not made by me) were when an ally leaves, his gold is split evenly and then redistributed to his allies every three minutes
He stated he wants it to run every 3 minutes in the first sentence of his post. Which means losses could build up over time. A gold accumulator is trivial to implement and result in no gold loss in the long run, something well worth it in my opinion.
 

Gojira2000

G

Gojira2000

Thanks guys for the help! will try out all that was suggested later when i get the time

all will be repped
 
Status
Not open for further replies.
Top