- Joined
- Aug 7, 2013
- Messages
- 1,338
Hi,
I would like to make two functions via a text macro.
The functions are mirrors of one another, and essentially deal with withdrawing or depositing gold/money. However, while it should be a simple switch of +/-, it doesn't appear it's that easy, even though technically these are two functions which should be mirrors...
Here is the function for withdrawing gold. I would like to make a text macro based off it that produces two functions: one for withdrawing gold, and one for depositing gold.
(also, hints to make this function more readable without using more variables)
I would like to make two functions via a text macro.
The functions are mirrors of one another, and essentially deal with withdrawing or depositing gold/money. However, while it should be a simple switch of +/-, it doesn't appear it's that easy, even though technically these are two functions which should be mirrors...
Here is the function for withdrawing gold. I would like to make a text macro based off it that produces two functions: one for withdrawing gold, and one for depositing gold.
(also, hints to make this function more readable without using more variables)
JASS:
function vaultWithdrawMain takes nothing returns boolean
local button b = GetClickedButton()
local player p = GetTriggerPlayer()
local integer pid = GetPlayerId(p)
local Dialog d = dialogTable[GetHandleId(GetClickedDialog())]
local PlayerData pd = playerDatum[pid]
local integer playerGold = GetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD)
local integer vaultGold = pd.vaultGold
call d.setMsg(d.msg + GOLD + I2S(vaultGold))
if b == d.getButton(BTTN_ONE_HUNDRED) then
if vaultGold >= ONE_HUNDRED then
call DisplayTimedTextToPlayer(p, 0, 0, NPC_TEXT_DURATION, VAULT_HEADER + " Withdrew " + GOLD + I2S(ONE_HUNDRED) + " gold|r, with " + GOLD + I2S(vaultGold - ONE_HUNDRED) + " gold|r now in your vault.")
call SetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD, playerGold + ONE_HUNDRED)
set pd.vaultGold = pd.vaultGold - ONE_HUNDRED
endif
elseif b == d.getButton(BTTN_FIVE_HUNDRED)
if vaultGold >= FIVE_HUNDRED then
call DisplayTimedTextToPlayer(p, 0, 0, NPC_TEXT_DURATION, VAULT_HEADER + " Withdrew " + GOLD + I2S(FIVE_HUNDRED) + " gold|r, with " + GOLD + I2S(vaultGold - FIVE_HUNDRED) + " gold|r now in your vault.")
call SetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD, playerGold + FIVE_HUNDRED)
set pd.vaultGold = pd.vaultGold - FIVE_HUNDRED
endif
elseif b == d.getButton(BTTN_ALL_GOLD)
call SetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD, playerGold + vaultGold)
set pd.vaultGold = 0
DisplayTimedTextToPlayer(p, 0, 0, NPC_TEXT_DURATION, VAULT_HEADER + " Withdrew " + GOLD + I2S(vaultGold) + " gold|r, with " + GOLD + I2S(0) + " gold|r now in your vault.")
endif
set b = null
set p = null
return false
endfunction