nurfaizfy19 Posted November 9, 2019 Posted November 9, 2019 hello, sorry for my bad english i want to get data from server side with database in client side i have server side function: function getPulsa(phone) local phoneSettings = mysql:query_fetch_assoc("SELECT * FROM `phones` WHERE `phonenumber`='"..mysql:escape_string(tostring(phone)).."' LIMIT 1") local pulsa = 0 if not phoneSettings then outputChatBox("ERROR", source, 255, 0, 0) else pulsa = tonumber(phoneSettings["pulsa"]) or 0 end return pulsa end addEvent("getPulsa", true) addEventHandler("getPulsa", root, getPulsa) and then i want to call the function in client side function: function getPulsa(nomor) return triggerServerEvent("getPulsa", localPlayer, tonumber(nomor)) end function testPulsa(commandName, nomoer) local pulsa = getPulsa(nomoer) outputChatBox(pulsa or "ERROR") end addCommandHandler("getpulsa", testPulsa, false, false) when i try to execute the command "/getpulsa", the output is boolean. i need the output in number thanks
komal Posted November 9, 2019 Posted November 9, 2019 (edited) you cant use return pulsa try with the code --server: function getPulsa(phone) local phoneSettings = mysql:query_fetch_assoc("SELECT * FROM `phones` WHERE `phonenumber`='"..mysql:escape_string(tostring(phone)).."' LIMIT 1") local pulsa = 0 if not phoneSettings then outputChatBox("ERROR", source, 255, 0, 0) else pulsa = tonumber(phoneSettings["pulsa"]) or 0 triggerEvent ( "printData", root, pulsa ) end end addEvent("getPulsa", true) addEventHandler("getPulsa", root, getPulsa) --client: function getPulsa(nomor) triggerServerEvent("getPulsa", localPlayer, tonumber(nomor)) end function testPulsa(commandName, nomoer) local pulsa = getPulsa(nomoer) end addCommandHandler("getpulsa", testPulsa, false, false) function printData(data) outputChatBox(data) end addEvent("printData", true) addEventHandler("printData", root,printData) Edited November 9, 2019 by komal
Castillo Posted November 10, 2019 Posted November 10, 2019 @komal You have to use triggerClientEvent, not triggerEvent.
nurfaizfy19 Posted November 10, 2019 Author Posted November 10, 2019 (edited) 16 hours ago, komal said: you cant use return pulsa thanks for the advice but i need this, because i also use the function in server side. any idea? thanks Edited November 10, 2019 by nurfaizfy19
Moderators IIYAMA Posted November 10, 2019 Moderators Posted November 10, 2019 (edited) 39 minutes ago, nurfaizfy19 said: thanks for the advice but i need this, because i also use the function in server side. any idea? thanks You can use this enchantment, if you really NEED that: Edited November 10, 2019 by IIYAMA
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