In my mud, you get rewarded for scalping and handing in humanoid mobs. Depending on their difficulty, these scalps are worth different amounts of currency.
As there are different denominations, to the base of 16, calculating the total sum isn't that easy. Gold coins, silver coins, bronze coins and copper coins are used.
I did set up triggers that add the amount of copper coins a scalp is worth to a global variable, bounty_amount.
What I now wish to do, is get the amount in gold, silver, bronze and coppers based on the value of that global variable.
The lua script looks as follows:
When I change the global value and call the alias that converts the alias, I get the correct value for the global variable bounty_amount, but the values for the different coin types reflect the value of the time when I last called the alias.
E.g.
I set the global variable to 4097 and call the alias twice, just to overwrite everything that might have been stored in the variables and I get the following output:
When I now change the value for x to 8375 and call the alias _once_, I get this output:
Calling the alias a second time, the output changes to:
The alias I use to call looks like this:
What do I need to change in order to have to call the alias only once to show the correct values?
As there are different denominations, to the base of 16, calculating the total sum isn't that easy. Gold coins, silver coins, bronze coins and copper coins are used.
I did set up triggers that add the amount of copper coins a scalp is worth to a global variable, bounty_amount.
What I now wish to do, is get the amount in gold, silver, bronze and coppers based on the value of that global variable.
The lua script looks as follows:
function CoppersToCoinage(x)
local i=0
SetVariable("gold_coins",0)
SetVariable("silver_coins",0)
SetVariable("bronze_coins",0)
SetVariable("copper_coins",0)
SetVariable("rest_for_sc",0)
SetVariable("rest_for_bc",0)
Note("x =" .. x .. " i=" .. i)
i = x % 4096
SetVariable("rest_for_sc",i)
i = (x - i) / 4096
SetVariable("gold_coins",i)
i = GetVariable("rest_for_sc") % 256
SetVariable("rest_for_bc",i)
i = (GetVariable("rest_for_sc") - i ) / 256
SetVariable("silver_coins",i)
i = GetVariable("rest_for_bc") % 16
SetVariable("copper_coins", i)
i = (GetVariable("rest_for_bc") -i ) / 16
SetVariable("bronze_coins",i)
end -- CoppersToCoinage
When I change the global value and call the alias that converts the alias, I get the correct value for the global variable bounty_amount, but the values for the different coin types reflect the value of the time when I last called the alias.
E.g.
I set the global variable to 4097 and call the alias twice, just to overwrite everything that might have been stored in the variables and I get the following output:
x =4097 i=0
Expected bounty - 1 gc 0 sc 0 bc 1 cc
When I now change the value for x to 8375 and call the alias _once_, I get this output:
x =8375 i=0
Expected bounty - 1 gc 0 sc 0 bc 1 cc
Calling the alias a second time, the output changes to:
x =8375 i=0
Expected bounty - 2 gc 0 sc 11 bc 7 cc
The alias I use to call looks like this:
<alias
match="MyBounty"
enabled="y"
expand_variables="y"
group="statistics"
send_to="12"
ignore_case="y"
sequence="100"
>
<send>CoppersToCoinage(@bounty_amount)
ColourNote ("#0AFF0A", "#1E1E1E", "Expected bounty - " .. "@gold_coins" .. " gc " .. "@silver_coins" .. " sc " .. "@bronze_coins" .. " bc "
.. "@copper_coins" .. " cc")</send>
</alias>
What do I need to change in order to have to call the alias only once to show the correct values?