Code:
function dlg_return(id)
if id == 1 then
return 'Rupee'
elseif id == 2 then
return 'Holic'
elseif id == 3 then
return 'JP'
else
return 'AP'
end
end
function value_return(id)
if id == 1 then
return 'gold'
elseif id == 2 then
return 'huntaholic_point'
elseif id == 3 then
return 'jp'
else
return 'ap'
end
end
--short explanation:
--this are arrays wich stores the information of the cost or the amount of each trade
--for example we trade rupees for holics ,the cost is
--rupee_holic (1) 10000 rupees for
--holic_rupee (1) 1 holic point
--or we trade ap for jp ,the cost is
--ap_jp (1) 10000 ap for
--jp_ap (1) 50000000 jp
rupee_holic = {10000,50000,100000,500000}
rupee_jp = {1000000,2000000,5000000,10000000}
rupee_ap = {250000000,750000000,1500000000,3000000000}
holic_rupee = {1,5,10,50}
holic_jp = {1,5,10,50}
holic_ap = {1,5,10,50}
jp_rupee = {10000000,20000000,50000000,100000000}
jp_holic = {10000,50000,100000,500000}
jp_ap = {50000000,75000000,150000000,500000000}
ap_rupee = {10000,25000,50000,100000}
ap_holic = {1,5,10,50}
ap_jp = {10000,25000,50000,100000}
--||||||||||||||||||||||||||||||||||||||||||||||||--
-- DONT TOUCH THIS! ;) --
--||||||||||||||||||||||||||||||||||||||||||||||||--
-- this configures the trade options
function price_selector(source,trade,counter)
local cost,amount
cost = 0
amount = 0
if source == 1 then -- trade rupee
if trade == 2 then
cost = rupee_holic[counter]
amount = holic_rupee[counter]
elseif trade == 3 then
cost = rupee_jp[counter]
amount = jp_rupee[counter]
elseif trade == 4 then
cost = rupee_ap[counter]
amount = ap_rupee[counter]
end
end
if source == 2 then -- trade holic
if trade == 1 then
cost = holic_rupee[counter]
amount = rupee_holic[counter]
elseif trade == 3 then
cost = holic_jp[counter]
amount = jp_holic[counter]
elseif trade == 4 then
cost = holic_ap[counter]
amount = ap_holic[counter]
end
end
if source == 3 then -- trade jp
if trade == 1 then
cost = jp_rupee[counter]
amount = rupee_jp[counter]
elseif trade == 2 then
cost = jp_holic[counter]
amount = holic_jp[counter]
elseif trade == 4 then
cost = jp_ap[counter]
amount = ap_jp[counter]
end
end
if source == 4 then -- trade ap
if trade == 1 then
cost = ap_rupee[counter]
amount = rupee_ap[counter]
elseif trade == 2 then
cost = ap_holic[counter]
amount = holic_ap[counter]
elseif trade == 3 then
cost = ap_jp[counter]
amount = jp_ap[counter]
end
end
return cost,amount
end
function exchange_example()
dlg_title("Raskim")
dlg_text("This is an Example how easy all Exchanges can happen.")
for i = 1,4 do -- get a dlg list of the trade options
dlg_menu("Trade "..dlg_return(i),"exchange_select("..i..")")
end
dlg_menu("Nevermind","")
dlg_show()
end
function exchange_select(typ)
dlg_title("Raskim")
dlg_text("You want to exchange your "..dlg_return(typ)..".<br>For What?")
for i = 1,4 do
if i ~= typ then -- make sure you dont do dummy trades (e.g. rupees for rupees)
dlg_menu("Exchange for "..dlg_return(i),"exchange_select_amount("..typ..","..i..")")
end
end
dlg_menu("Return","exchange_example()")
dlg_menu("Nevermind","")
dlg_show()
end
function exchange_select_amount(source,trade)
dlg_title("Raskim")
dlg_text("You want to exchange your "..dlg_return(source).." for "..dlg_return(trade)..".<br>How much?")
for i = 1,4 do --build the trade amount/cost options
local cost,amount = price_selector(source,trade,i)
dlg_menu("Exchange "..cost.." "..dlg_return(source),"exchange_execute_check("..source..","..trade..","..cost..","..amount..")")
end
dlg_menu("Return","exchange_select("..source..")")
dlg_menu("Nevermind","")
dlg_show()
end
--make sure the user REALLY want to do this deal
function exchange_execute_check(source,trade,cost,amount)
local text = tostring("Exchange "..cost.." "..dlg_return(source).." for "..amount.." "..dlg_return(trade).."?")
dlg_special( 'confirm_window', "exchange_select_amount_execute("..source..","..trade..","..cost..","..amount..")", text )
end
--executing of the trade
function exchange_select_amount_execute(source,trade,cost,amount)
if gv(value_return(source)) >= cost then -- if the user has valid options for the trade - do it
if source == 2 then
set_huntaholic_point(gv(value_return(source))-cost)
else
sv(value_return(source),gv(value_return(source))-cost)
end
if trade == 2 then
set_huntaholic_point(gv(value_return(trade))+amount)
else
sv(value_return(trade),gv(value_return(trade))+amount)
end
whisper(gv("name"),"Exchanged "..cost.." "..dlg_return(source).." for "..amount.." "..dlg_return(trade)..".")
contuine_check(source)
else -- otherwise he have to GTFO
whisper(gv("name"),"Failed to Exchange.")
end
end
function contuine_check(source)
dlg_title("Raskim")
dlg_text("Contuine trading your "..dlg_return(source).."?")
dlg_menu("Yes","exchange_select("..source..")")
dlg_menu("Nevermind","")
dlg_show()
end