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).