Just finished this up and implementing on my server tonight at next restart. BTW does anyone know why changes in the StringResourceEN Table don't take effect? I added a unused code, 0 group ID, and a value, then referenced it in the code but it always shows empty string. Same for anytime I change an existing value in that table.
If the code is not "clean" its because I learning LUA on the fly. Though I would share this though incase its useful to others.
If the code is not "clean" its because I learning LUA on the fly. Though I would share this though incase its useful to others.
Code:
dlg_menu( "JP To AP Exchange", "Exchange_JP_to_AP()" )
Code:
-- JP to AP Exchange Begin --
-- Max AP is 2,147,483 647 --
function Exchange_JP_to_AP()
local exchange_rate = 0.00000001
local numrac, exchange_ap, player_ap, text, numap
numrac = gv("jp") -- It fetches the amount of JP that is currently collected.
exchange_ap = math.floor(numrac * exchange_rate) -- Calculate the maximum AP amount that can be exchanged.
player_ap = gv("ap") -- Get player current AP amount.
numap = tonumber(exchange_ap .. player_ap) -- The current user AP and the exchange AP are combined.
dlg_title( "GreeneTech Shop" )
text = sconv("You Have #@rac@# JP To Exchange For #@number@# AP.", "#@rac@#",tostring( numrac ) , "#@number@#",tostring(exchange_ap)) -- Replace variable with actual value (string).
dlg_text_without_quest_menu( text ) -- Insert text in the dialog window
-- <Common menu>
-- All exchange.
if numrac >= 100000000 then
dlg_menu( "@90010083", 'PointExchange_AP_num(' .. exchange_ap .. ')' )
end
local num1, num2, num3, num4
num1 = 10
if numrac <3000000000 then
num1 = 1
num2 = 5
num3 = 10
num4 = 20
elseif numrac < 11000000000 then
num2 = 30
num3 = 50
num4 = 100
elseif numrac < 31000000000 then
num2 = 50
num3 = 100
num4 = 300
else
num2 = 50
num3 = 200
num4 = 500
end
if numrac >= num1 then
-- #@ number @ # exchange only. num1
text = sconv("Purchase #@number@# AP", "#@number@#", tostring( num1 ) ) -- Replace variable with actual value (string).
dlg_menu( text, 'PointExchange_AP_num(' .. num1 ..')' )
end
if numrac >= num2 then
-- #@ number @ # exchange only. num2
text = sconv("Purchase #@number@# AP", "#@number@#", tostring( num2 ) ) -- Replace variable with actual value (string)
dlg_menu( text, 'PointExchange_AP_num(' .. num2 ..')' )
end
if numrac >= num3 then
-- #@ number @ # exchange only. num3
text = sconv("Purchase #@number@# AP", "#@number@#", tostring( num3 ) ) -- Replace variable with actual value (string)
dlg_menu( text, 'PointExchange_AP_num(' .. num3 ..')' )
end
if numrac >= num4 then
-- #@ number @ # exchange only. num4
text = sconv("Purchase #@number@# AP", "#@number@#", tostring( num4 ) ) -- Replace variable with actual value (string)
dlg_menu( text, 'PointExchange_AP_num(' .. num4 .. ')' )
end
dlg_menu( "@99000016", "NPC_RevoTrader_Contact()" )
-- End conversation
dlg_menu( "@90010002", "" )
-- Outputting the dialog
dlg_show()
end
-- JP to AP Exchange End --
-- JP Currency Exchange Begin --
function PointExchange_AP_num( ap_amount )
player_jp = gv("jp")
player_ap = gv("ap")
ap_cost = ap_amount*100000000
if player_jp >= ap_cost then
temp_jp = player_jp - ap_cost
temp_ap = player_ap + ap_amount
-- Update Player AP Amount
sv("ap", temp_ap )
-- Update Player JP Amount
sv("jp", temp_jp )
message( sconv( "Recieved #@ap_num@# AP", "#@ap_num@#", tostring(ap_amount) ) )
end
end
-- JP Currency Exchange End --