Ok i managed to get the moneychanger working now. It works just fine as far as i tested it.
The only Thing is, that there shouldn´t be more than 1 stack of the same coin in it or the results are nonsense.
I might put some instructions next to it....
I´m just gonna dump the Code for it here and i hope someone else can use it too, so this thread wasn´t for nothing.
When your interested in the Code, then read through it.
I added some explanations to it, since a Counter and a Surface is involved, but it isn´t hard to understand anyway.
Code: Select all
money = 0
function moneyinfo()
----------------------------------------------------------
--Name your counter kindcounter and set it to 0 (Default value)
local counter = kindcounter.counter:getValue()
----------------------------------------------------------
if counter == 1 then
hudPrint("Changing in gold coins")
elseif counter == 2 then
hudPrint("Changing in silver coins")
elseif counter == 3 then
hudPrint("Changing in copper coins")
elseif counter >3 then
kindcounter.counter:setValue(0)
end
end
function surfaceContains(surface, item)
money = 0
for v,i in surface.surface:contents() do
if i.go.name == item then
i.go:destroy()
money = i:getStackSize()
end
end
end
function moneychange()
if kindcounter.counter:getValue() > 0 then
----------------------------------------------------------
--counts coins
----------------------------------------------------------
surfaceContains(moneychanger, "dm_coin_copper")
local coinscopper = money
surfaceContains(moneychanger, "dm_coin_silver")
local coinssilver = money
surfaceContains(moneychanger, "dm_coin_gold")
local coinsgold = money
----------------------------------------------------------
----------------------------------------------------------
local copper = 0
local silver = 0
local gold = 0
----------------------------------------------------------
--This is your changing Course (x copper = 1 silver, x silver = 1 gold)
local x = 5
----------------------------------------------------------
--changing in goldcoins
----------------------------------------------------------
if kindcounter.counter:getValue() == 1 then
copper=coinscopper%x
silver=math.floor(coinscopper/x)+coinssilver
gold=math.floor(silver/x)+coinsgold
silver=silver%x
----------------------------------------------------------
--changing in silvercoins
----------------------------------------------------------
elseif kindcounter.counter:getValue() == 2 then
copper=coinscopper%x
silver=math.floor(coinscopper/x)+coinssilver+coinsgold*x
----------------------------------------------------------
--changing in coppercoins
----------------------------------------------------------
elseif kindcounter.counter:getValue() == 3 then
silver=coinssilver+coinsgold*x
copper=silver*x+coinscopper
silver=0
end
----------------------------------------------------------
--spawn coins on the surface of your choice except the moneychanger itself!
----------------------------------------------------------
for m=1,gold do
changetable.surface:addItem(spawn("dm_coin_gold").item)
end
for m=1,silver do
changetable.surface:addItem(spawn("dm_coin_silver").item)
end
for m=1,copper do
changetable.surface:addItem(spawn("dm_coin_copper").item)
end
----------------------------------------------------------
else
hudPrint("No changing mode was selected")
end
end
In order to get to the other side of the pit you have to get hit by the fireball and die....
Yep.....moving on!