Jump to content

how do i make this in mta?


yesyesok

Recommended Posts

$from = "USD"; 
$to = "GBP"; 
$amount = 12.50; 
$url = "http://www.exchangerate-api.com/".$from."/".$to."/".$amount."?k=API_KEY"; 
$result = file_get_contents($url); 
echo $result; 

i was learning php for Mta, what should i do to make it like a command

/currency usd gbp and it outputs the result.

Link to comment
function convertMoney(plr, cmd, usd, gbp, amount) 
    if plr and isElement(plr) then  
        if not (tostring(usd)) or not(tostring(gbp)) then 
            outputChatBox("[Wrong Command]: /currency usd gbp ", plr, 0, 255, 0) 
        return 
    end 
    if (not tonumber(amount)) then return end 
    exchangerate(plr,usd,gbp,amount) 
    end 
end  
addCommandHandler("currency", convertMoney) 
  
function currency_return(sum) 
    if sum ~= "ERROR" then 
        outputChatBox(sum) 
    end 
end 
  
function exchangerate(player,usd,gbp,amount) 
    if (usd and gbp and amount) then 
       return callRemote("<< you php file link >>", currency_return, player, usd,gbp,amount) 
    end 
end 

untested

Note: as ALw7sH said you must use fetchRemote to get echo (print text) or try to change you php file code.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...