benwilkins Posted October 13, 2017 Share Posted October 13, 2017 How can I request info from server scripts? Inside a client function, I need to run a SQL query, which can only be done in server, and I need to send back the row of data. I have tried: -- CLIENT function getCharacterInfo(charid) triggerServerEvent("server:getCharInfo", getRootElement(), charid) end function test () details = getCharacterInfo("1") outputChatBox(details["charactername"]) end -- SERVER function servergetCharInfo ( charid ) local cmSQL = mysql:query("SELECT * FROM `characters` WHERE `id`='"..charid.."'") or false local row = mysql:fetch_assoc(cmSQL) or false return row end addEvent( "server:getCharInfo", true ) addEventHandler( "server:getCharInfo", getRootElement(), servergetCharInfo ) Doesn't seem to work.. Link to comment
Administrators Lpsd Posted October 13, 2017 Administrators Share Posted October 13, 2017 (edited) You can't return values like that, you have to create an event running the other way (server->client) Simple example --Clientside function getData(charid) triggerServerEvent("pushData", root, charid) --send charid to server end function receiveData(info) --do something with info end addEvent("onClientReceiveData", true) addEventHandler("onClientReceiveData", root, receiveData) --Serverside function processData(charid) local thePlayer = client --client is a predefined variable, contains the client who triggered the event --use charid to get your info triggerClientEvent(thePlayer, "onClientReceiveData", thePlayer, charid) --send info back (replace "charid" with whatever you want to send) end addEvent("pushData", true) addEventHandler("pushData", root, processData) Edited October 13, 2017 by LopSided_ Link to comment
WorthlessCynomys Posted October 13, 2017 Share Posted October 13, 2017 Throw that module in the trash can and use MTA's built in db functions. Btw you can send data back (if you have): triggerClientEvent(elementToSendTo((client)), "eventName", sourceElement((resourceRoot)), additional, variables) 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