Page 1 of 1

Money Changer

Posted: Sat Oct 07, 2017 8:49 pm
by Xardas
Hey guys,
I´m having Problems creating a script Code, which allows to Change coins which are being put in an alcove.
I am using the dm coins (copper, silver, gold).
I want the alcove to Change any amount of coins to any coins, so it should be able to Change to copper,silver and gold coins.
Changing Course should be (x copper = 1 silver, x silver = 1 Gold).

Solved: Code for it is below

Re: Money Changer

Posted: Sun Oct 08, 2017 12:33 pm
by AdrTru
Try to Virtual Money ( https://www.nexusmods.com/legendofgrimrock2/mods/39/? )
In this code is universal conversion script.

Re: Money Changer

Posted: Sun Oct 08, 2017 2:22 pm
by Xardas
Hey ArdTru,
I took a look at the Code and i don´t really understand it. :cry:
Seems like i have to figure out something else. Nevertheless thank you

Re: Money Changer

Posted: Mon Oct 09, 2017 7:29 pm
by Xardas
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. :lol:
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