trux_yt Posted February 22, 2022 Share Posted February 22, 2022 hi, how i can use the function local sql = exports.sql:query_assoc_single("SELECT nivel FROM characters WHERE characterID = "..exports.players:getCharacterID(getLocalPlayer)) in the client-side? is for a hud, for example. dxDrawText("LVL: "..tostring(sql.nivel) .."", x*2079, y*185, x*21, y*14, tocolor(255, 255, 255, 255), 1.00, font, "center", "center", false, false, false, false, false) Link to comment
βurak Posted February 23, 2022 Share Posted February 23, 2022 (edited) You can't do this on client side and I don't recommend doing it. it's good to stay on server side, use "triggerServerEvent" and "triggerClientEvent" to do this example: server: addEvent("requestGetLevelPlayer", true) --create event on server side addEventHandler("requestGetLevelPlayer", root, function() local sql = exports.sql:query_assoc_single("SELECT nivel FROM characters WHERE characterID=?"..exports.players:getCharacterID(source)) triggerClientEvent(source, "updateLevelPlayer", source, sql.nivel) --send level information to client end ) client: local level = 0 triggerServerEvent("requestGetLevelPlayer", localPlayer) --send level update request (don't use it in onClientRender) dxDrawText("LVL: "..level, x*2079, y*185, x*21, y*14, tocolor(255, 255, 255, 255), 1.00, font, "center", "center", false, false, false, false, false) addEvent("updateLevelPlayer", true) --event to update level addEventHandler("updateLevelPlayer", root, function(playerLevel) level = playerLevel --update level end ) Edited February 23, 2022 by Burak5312 Link to comment
trux_yt Posted February 25, 2022 Author Share Posted February 25, 2022 On 23/02/2022 at 11:13, Burak5312 said: You can't do this on client side and I don't recommend doing it. it's good to stay on server side, use "triggerServerEvent" and "triggerClientEvent" to do this example: server: addEvent("requestGetLevelPlayer", true) --create event on server side addEventHandler("requestGetLevelPlayer", root, function() local sql = exports.sql:query_assoc_single("SELECT nivel FROM characters WHERE characterID=?"..exports.players:getCharacterID(source)) triggerClientEvent(source, "updateLevelPlayer", source, sql.nivel) --send level information to client end ) client: local level = 0 triggerServerEvent("requestGetLevelPlayer", localPlayer) --send level update request (don't use it in onClientRender) dxDrawText("LVL: "..level, x*2079, y*185, x*21, y*14, tocolor(255, 255, 255, 255), 1.00, font, "center", "center", false, false, false, false, false) addEvent("updateLevelPlayer", true) --event to update level addEventHandler("updateLevelPlayer", root, function(playerLevel) level = playerLevel --update level end ) Hi bro, thx, but i have this error in the server code ``` attempt to index local sql a boolean value ``` in the line 5 Link to comment
βurak Posted February 25, 2022 Share Posted February 25, 2022 local sql = exports.sql:query_assoc_single("SELECT nivel FROM characters WHERE characterID = "..exports.players:getCharacterID(source)) I may have made a typo here, I fixed it, try this Link to comment
trux_yt Posted February 25, 2022 Author Share Posted February 25, 2022 7 hours ago, Burak5312 said: local sql = exports.sql:query_assoc_single("SELECT nivel FROM characters WHERE characterID = "..exports.players:getCharacterID(source)) I may have made a typo here, I fixed it, try this This works, but, in the client side, how i can made to the level text change the level? PlayerLevel What does it perform? Link to comment
βurak Posted February 25, 2022 Share Posted February 25, 2022 (edited) You can create a client-side timer with setTimer, then use the triggerServerEvent as is so it will constantly update the level text (1 second may be enough for the update to avoid creating too many network connections) 1 hour ago, trux_yt said: PlayerLevel What does it perform? parameter of client side event "updateLevelPlayer" Edited February 25, 2022 by Burak5312 Link to comment
trux_yt Posted February 25, 2022 Author Share Posted February 25, 2022 Fine, but i have this error now server triggered clientside event updateLevelPlayer, but event is not added clientside Link to comment
βurak Posted February 25, 2022 Share Posted February 25, 2022 (edited) can you show the code Edited February 25, 2022 by Burak5312 Link to comment
trux_yt Posted February 25, 2022 Author Share Posted February 25, 2022 Client-side: local level = 5 triggerServerEvent("requestGetLevelPlayer", localPlayer) --send level update request (don't use it in onClientRender) addEvent("updateLevelPlayer", true) --event to update level addEventHandler("updateLevelPlayer", root, function(playerLevel) level = playerLevel --update level end ) dxDrawText("LVL: "..level, x*2079, y*185, x*21, y*14, tocolor(255, 255, 255, 255), 1.00, font, "center", "center", false, false, false, false, false) Server-side addEvent("requestGetLevelPlayer", true) --create event on server side addEventHandler("requestGetLevelPlayer", root, function() local sql = exports.sql:query_assoc_single("SELECT nivel FROM characters WHERE characterID = "..exports.players:getCharacterID(source)) triggerClientEvent(source, "updateLevelPlayer", source, sql.nivel) --send level information to client end ) Link to comment
βurak Posted February 26, 2022 Share Posted February 26, 2022 (edited) where the event is triggered before the resource starts on the client side or the use of the sql query may be wrong outputDebugString(sql.nivel) You can add a debug line inside the event to find out. Edited February 26, 2022 by Burak5312 Link to comment
trux_yt Posted February 27, 2022 Author Share Posted February 27, 2022 6 hours ago, Burak5312 said: where the event is triggered before the resource starts on the client side or the use of the sql query may be wrong outputDebugString(sql.nivel) You can add a debug line inside the event to find out. I have this error attempt to index global sql a nil value Link to comment
βurak Posted February 27, 2022 Share Posted February 27, 2022 (edited) the problem may be in the sql query so make sure this query is correct Edited February 27, 2022 by Burak5312 Link to comment
trux_yt Posted February 27, 2022 Author Share Posted February 27, 2022 hmmmm yea, this is correct i use this sql query in another resource and works 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