..:D&G:.. Posted February 16, 2015 Share Posted February 16, 2015 Hello guys, I am working on an exchange-system and I want to make a machine that exchanges coins for money. When a player selects the amount of coins they want to exchange, I get an error saying that getPlayerCoins retuns nil, even tho when I made a function with a command and chatbox, it returned my number of coins. function exchangeOption1(thePlayer) local playerCoins = tonumber(getPlayerCoins(thePlayer)) if (playerCoins > 99) then givePlayerMoney(thePlayer, 1) takePlayerCoins(thePlayer, 100) else outputChatBox("You don't have enough coins!", thePlayer, 255, 255, 0) end end addEvent("exchangeOption1", true) addEventHandler("exchangeOption1", getRootElement(), exchangeOption1) Client side - function proceedCEM( button, state ) if ( button == "left" and state == "up" ) then if (guiRadioButtonGetSelected(option1)) then triggerServerEvent("exchangeOption1", getLocalPlayer()) closeCEM() elseif (guiRadioButtonGetSelected(option2)) then triggerServerEvent("exchangeOption2", getLocalPlayer()) closeCEM() elseif (guiRadioButtonGetSelected(option3)) then triggerServerEvent("exchangeOption3", getLocalPlayer()) closeCEM() elseif (guiRadioButtonGetSelected(option4)) then triggerServerEvent("exchangeOption4", getLocalPlayer()) closeCEM() elseif (guiRadioButtonGetSelected(option5)) then triggerServerEvent("exchangeOption5", getLocalPlayer()) closeCEM() elseif (guiRadioButtonGetSelected(option6)) then triggerServerEvent("exchangeOption6", getLocalPlayer()) closeCEM() else showPINCodeError("You did not select an option.") end end end Any ideas guys? Link to comment
MTA Team botder Posted February 16, 2015 MTA Team Share Posted February 16, 2015 Where is your getPlayerCoins function? Link to comment
..:D&G:.. Posted February 16, 2015 Author Share Posted February 16, 2015 In the same resource, but different .lua file. It worked when I did: function test(thePlayer) outputChatBox(tonumber(getPlayerCoins(thePlayer))) end addCommandHandler("test12", test) But in the function that I posted firstly, didn't work. Link to comment
JR10 Posted February 16, 2015 Share Posted February 16, 2015 You never send a player argument, you just specify it as a source element. function exchangeOption1() local playerCoins = tonumber(getPlayerCoins(source)) if (playerCoins > 99) then givePlayerMoney(source, 1) takePlayerCoins(source, 100) else outputChatBox("You don't have enough coins!", source, 255, 255, 0) end end addEvent("exchangeOption1", true) addEventHandler("exchangeOption1", getRootElement(), exchangeOption1) This should fix your current problem. However, it's vulnerable to event faking. You should replace thePlayer from triggerServerEvent with root, and then use 'client' on the server. Read more here: https://wiki.multitheftauto.com/wiki/TriggerServerEvent Link to comment
..:D&G:.. Posted February 16, 2015 Author Share Posted February 16, 2015 It still says "tonumber(value expected)" Link to comment
JR10 Posted February 16, 2015 Share Posted February 16, 2015 My bad, I forgot to remove the parameter. Try this: function exchangeOption1() local playerCoins = tonumber(getPlayerCoins(source)) if (playerCoins > 99) then givePlayerMoney(source, 1) takePlayerCoins(source, 100) else outputChatBox("You don't have enough coins!", source, 255, 255, 0) end end addEvent("exchangeOption1", true) addEventHandler("exchangeOption1", getRootElement(), exchangeOption1) Link to comment
..:D&G:.. Posted February 16, 2015 Author Share Posted February 16, 2015 Same thing... This is what I done for the client side, maybe is something wrong with it? function proceedCEM( button, state ) if ( button == "left" and state == "up" ) then if (guiRadioButtonGetSelected(option1)) then triggerServerEvent("exchangeOption1", root) closeCEM() Link to comment
JR10 Posted February 16, 2015 Share Posted February 16, 2015 This is why I separated my answer, so that you don't get confused, I guess it didn't help. Now 'source' will not refer to the player, you need to use 'client'. If what you posted is your current client code then this should work: function exchangeOption1() local playerCoins = tonumber(getPlayerCoins(client)) if (playerCoins > 99) then givePlayerMoney(client, 1) takePlayerCoins(client, 100) else outputChatBox("You don't have enough coins!", client, 255, 255, 0) end end addEvent("exchangeOption1", true) addEventHandler("exchangeOption1", getRootElement(), exchangeOption1) Link to comment
MTA Team botder Posted February 16, 2015 MTA Team Share Posted February 16, 2015 function exchangeOption1() local playerCoins = tonumber(getPlayerCoins(client)) if (playerCoins > 99) then givePlayerMoney(client, 1) takePlayerCoins(client, 100) else outputChatBox("You don't have enough coins!", client, 255, 255, 0) end end Use the hidden variable client Link to comment
..:D&G:.. Posted February 16, 2015 Author Share Posted February 16, 2015 It works thanks. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now