..:D&G:.. Posted February 16, 2015 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? MTA:Rust Pre-Alpha Build v.0.3: https://forum.mtasa.com/viewtopic.php?f=114&t=97848 2Pac: ''Only God can judge me!''
MTA Team botder Posted February 16, 2015 MTA Team Posted February 16, 2015 Where is your getPlayerCoins function? GitHub: Debug Console • MTA-Discord Relay Scripting: How to draw a line chart with DirectX functions? • Doppler Effect in MTA • Get the client's FPS • Customizable Blur Shader
..:D&G:.. Posted February 16, 2015 Author 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. MTA:Rust Pre-Alpha Build v.0.3: https://forum.mtasa.com/viewtopic.php?f=114&t=97848 2Pac: ''Only God can judge me!''
JR10 Posted February 16, 2015 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 Business System viewtopic.php?f=108&t=35797 Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726 SQLite Tutorial viewtopic.php?f=148&t=38203
..:D&G:.. Posted February 16, 2015 Author Posted February 16, 2015 It still says "tonumber(value expected)" MTA:Rust Pre-Alpha Build v.0.3: https://forum.mtasa.com/viewtopic.php?f=114&t=97848 2Pac: ''Only God can judge me!''
JR10 Posted February 16, 2015 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) Business System viewtopic.php?f=108&t=35797 Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726 SQLite Tutorial viewtopic.php?f=148&t=38203
..:D&G:.. Posted February 16, 2015 Author 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() MTA:Rust Pre-Alpha Build v.0.3: https://forum.mtasa.com/viewtopic.php?f=114&t=97848 2Pac: ''Only God can judge me!''
JR10 Posted February 16, 2015 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) Business System viewtopic.php?f=108&t=35797 Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726 SQLite Tutorial viewtopic.php?f=148&t=38203
MTA Team botder Posted February 16, 2015 MTA Team 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 GitHub: Debug Console • MTA-Discord Relay Scripting: How to draw a line chart with DirectX functions? • Doppler Effect in MTA • Get the client's FPS • Customizable Blur Shader
..:D&G:.. Posted February 16, 2015 Author Posted February 16, 2015 It works thanks. MTA:Rust Pre-Alpha Build v.0.3: https://forum.mtasa.com/viewtopic.php?f=114&t=97848 2Pac: ''Only God can judge me!''
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