thund3rbird23 Posted September 11, 2019 Share Posted September 11, 2019 I have an input label in client side called "fakeInputs.Message" and I want to process this label's value in server side and insert this value to the database it's possible? Here is how works the input label: function processFakeInput(key, forcedInput) local theInput, inputType, maxChar = getActiveFakeInput(type(forcedInput) == "string" and forcedInput or false) if theInput then if not fakeInputs[theInput] then fakeInputs[theInput] = "" end if key == "enter" then elseif key == "backspace" then fakeInputs[theInput] = utf8.sub(fakeInputs[theInput], 1, -2) else if maxChar > utf8.len(fakeInputs[theInput]) then if inputType == "num-only" then if tonumber(key) then fakeInputs[theInput] = fakeInputs[theInput] .. key end else fakeInputs[theInput] = fakeInputs[theInput] .. key end end end end end So in server side I need something like this ( ofc, that doesn't work because I don't know how to get the value from client side): dbExec(connection, "INSERT INTO messages VALUES (?)", fakeInputs.Message) Link to comment
Scripting Moderators ds1-e Posted September 11, 2019 Scripting Moderators Share Posted September 11, 2019 1 hour ago, thund3rbird23 said: I have an input label in client side called "fakeInputs.Message" and I want to process this label's value in server side and insert this value to the database it's possible? Here is how works the input label: function processFakeInput(key, forcedInput) local theInput, inputType, maxChar = getActiveFakeInput(type(forcedInput) == "string" and forcedInput or false) if theInput then if not fakeInputs[theInput] then fakeInputs[theInput] = "" end if key == "enter" then elseif key == "backspace" then fakeInputs[theInput] = utf8.sub(fakeInputs[theInput], 1, -2) else if maxChar > utf8.len(fakeInputs[theInput]) then if inputType == "num-only" then if tonumber(key) then fakeInputs[theInput] = fakeInputs[theInput] .. key end else fakeInputs[theInput] = fakeInputs[theInput] .. key end end end end end So in server side I need something like this ( ofc, that doesn't work because I don't know how to get the value from client side): dbExec(connection, "INSERT INTO messages VALUES (?)", fakeInputs.Message) Take a look: 1 Link to comment
China_Yann Posted September 11, 2019 Share Posted September 11, 2019 https://wiki.multitheftauto.com/wiki/TriggerServerEvent Link to comment
thund3rbird23 Posted September 11, 2019 Author Share Posted September 11, 2019 6 hours ago, majqq said: Take a look: Thanks, I did with your suggestion: -- Client-side local guiText = guiGetText(pin) triggerServerEvent("check", resourceRoot, guiText) -- pass data -- Server-side function checkEvent(text) outputChatBox(text) end addEvent("check", true) addEventHandler("check", resourceRoot, checkEvent) But what about if I have something in server side and I want to display it in client side? Example (I want to display the "res" in client side): function LoadMessages() local query = dbQuery(connection, "SELECT * FROM messages WHERE characterID = 1") local result = dbPoll(query,-1) for x, ad in ipairs( result ) do local res = result[x]['message'] end end addEvent("LoadMsg", true) addEventHandler("LoadMsg", resourceRoot, LoadMessages) Link to comment
Rockyz Posted September 11, 2019 Share Posted September 11, 2019 Use triggerClientEvent Link to comment
Awang Posted September 11, 2019 Share Posted September 11, 2019 1 hour ago, thund3rbird23 said: function LoadMessages() local query = dbQuery(connection, "SELECT * FROM messages WHERE characterID = 1") local result = dbPoll(query,-1) for x, ad in ipairs( result ) do local res = result[x]['message'] end end addEvent("LoadMsg", true) addEventHandler("LoadMsg", resourceRoot, LoadMessages) Do not use dbPoll with -1 query time, its will couse server side freeze if one of the query comeback with timeout. You can use the dbQuery's callback function with zero timeout instead of, like this: function LoadMessages() local query = dbQuery(function(qh) result = dbPoll(qh,0) end,connection, "SELECT * FROM messages WHERE characterID = 1") for x, ad in ipairs( result ) do local res = result[x]['message'] end end addEvent("LoadMsg", true) addEventHandler("LoadMsg", resourceRoot, LoadMessages) You can read more about there:https://wiki.multitheftauto.com/wiki/DbQuery 1 Link to comment
thund3rbird23 Posted September 11, 2019 Author Share Posted September 11, 2019 1 hour ago, Awang said: Do not use dbPoll with -1 query time, its will couse server side freeze if one of the query comeback with timeout. You can use the dbQuery's callback function with zero timeout instead of, like this: function LoadMessages() local query = dbQuery(function(qh) result = dbPoll(qh,0) end,connection, "SELECT * FROM messages WHERE characterID = 1") for x, ad in ipairs( result ) do local res = result[x]['message'] end end addEvent("LoadMsg", true) addEventHandler("LoadMsg", resourceRoot, LoadMessages) You can read more about there:https://wiki.multitheftauto.com/wiki/DbQuery Thanks! But I still don't know how to display that in client side. Link to comment
Moderators IIYAMA Posted September 11, 2019 Moderators Share Posted September 11, 2019 6 hours ago, thund3rbird23 said: But I still don't know how to display that in client side. By sending it back Serverside local something = "something" triggerClientEvent(player, "sending-something-back" resourceRoot, something) player = sending it specific to that player. Clientside addEvent("sending-something-back", true) addEventHandler("sending-something-back", resourceRoot, function (something) outputChatBox(something) end, false) If you want to work with callbacks instead, you need an enchantment of the feature. 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