| 07-29-2006, 09:10 AM | #1 |
I'm trying to surpass the maximum gold of the game of 1,000,000 when recieving income or killing units. Any time that player gold exceeds 1,000,000, add every penny to an integer variable. Gold will be recovered by looping 10k gold out of the bank when a player gold falls below 200k. The loop should end when a player's bank is empty, or when they reach 800k gold. Adding the gold to a variable works fine in both cases where gold will exceed the maximum, but when subtracting it, it somehow goes negative. My math looks good and I can't seem to figure out why it doesn't end the loop when it's supposed to. The following two triggers are just to add the gold to the bank. This all works correctly, and doesn't seem to be causing the problem. Calling the bank value always shows the correct value. JASS://When a unit dies, find the difference between bounty (pointvalue is equivalent) and remaining to bank. local integer inta = GetPlayerState(GetOwningPlayer(GetKillingUnit()), PLAYER_STATE_RESOURCE_GOLD) local integer intb = GetUnitPointValue(GetDyingUnit()) local integer intc = inta + intb if (intc >= 1000000) then set udg_Bank[GetConvertedPlayerId(GetOwningPlayer(localunit))] = udg_Bank[GetConvertedPlayerId(GetOwningPlayer(localunit))] + (intc - 1000000) endif JASS://When the income rolls in, find the difference between total gold+income and maximum gold, add remaining to bank. local integer Total local integer Diff if (GetPlayerSlotState(Player(0))==PLAYER_SLOT_STATE_PLAYING) then set Total = (udg_Income[1] + GetPlayerState(Player(0), PLAYER_STATE_RESOURCE_GOLD)) if (Total > 1000000) then set Diff = (Total - 1000000) set udg_Bank[1] = (Diff + udg_Bank[1]) endif call SetPlayerState(Player(0), PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(Player(0), PLAYER_STATE_RESOURCE_GOLD) + udg_Income[1]) call ConditionalTriggerExecute(gg_trg_ShowStatsRed) endif Now here is where the problem lies. For some reason Bank may fall below 9999, and even go a couple ten thousands negative. It should stop after falling below 10,000, or when a player reached 800,000. Any help will be greatly appreciated. JASS://When a player's gold falls below 200k, add the bank until it falls below 10k, or until the player's gold reaches 800k. function AddTotalBack takes nothing returns nothing if (udg_Bank[GetConvertedPlayerId(GetTriggerPlayer())] > 9999) then loop call SetPlayerState(GetTriggerPlayer(), PLAYER_STATE_RESOURCE_GOLD, (GetPlayerState(GetTriggerPlayer(), PLAYER_STATE_RESOURCE_GOLD) + 10000)) set udg_Bank[GetConvertedPlayerId(GetTriggerPlayer())] = (udg_Bank[GetConvertedPlayerId(GetTriggerPlayer())] - 10000) exitwhen (udg_Bank[GetConvertedPlayerId(GetTriggerPlayer())] <= 9999) or (GetPlayerState(GetTriggerPlayer(), PLAYER_STATE_RESOURCE_GOLD)>=800000) endloop endif endfunction function InitTrig_AddTotalBack takes nothing returns nothing set gg_trg_AddTotalBack = CreateTrigger( ) call TriggerRegisterPlayerStateEvent(gg_trg_AddTotalBack, Player(0), PLAYER_STATE_RESOURCE_GOLD, LESS_THAN_OR_EQUAL, 200000.) call TriggerRegisterPlayerStateEvent(gg_trg_AddTotalBack, Player(1), PLAYER_STATE_RESOURCE_GOLD, LESS_THAN_OR_EQUAL, 200000.) call TriggerRegisterPlayerStateEvent(gg_trg_AddTotalBack, Player(2), PLAYER_STATE_RESOURCE_GOLD, LESS_THAN_OR_EQUAL, 200000.) call TriggerRegisterPlayerStateEvent(gg_trg_AddTotalBack, Player(3), PLAYER_STATE_RESOURCE_GOLD, LESS_THAN_OR_EQUAL, 200000.) call TriggerRegisterPlayerStateEvent(gg_trg_AddTotalBack, Player(4), PLAYER_STATE_RESOURCE_GOLD, LESS_THAN_OR_EQUAL, 200000.) call TriggerRegisterPlayerStateEvent(gg_trg_AddTotalBack, Player(5), PLAYER_STATE_RESOURCE_GOLD, LESS_THAN_OR_EQUAL, 200000.) call TriggerAddAction(gg_trg_AddTotalBack, function AddTotalBack) endfunction |
| 07-29-2006, 12:05 PM | #2 |
I would just change the maxium gold value in Gameplay constants. |
| 07-29-2006, 07:44 PM | #3 |
How do I go about that? I checked the gameplay constants and the only gold options I see are the maximum gold for a gold mine and gold tax rates. |
| 07-29-2006, 07:54 PM | #4 |
The)TideHunter( is thinking of Gold Mine - Maximum Gold This contant, however, is for being able to change the max gold for the gold mines not player gold. |
