fairyoggy Posted June 27, 2019 Share Posted June 27, 2019 local dbSecurityConnection = dbConnect( 'sqlite', 'accs.db') local getAnswerData = dbQuery( dbSecurityConnection, ' SELECT `fname`,`sname` FROM `accountsSecurity` WHERE Login = ? ', getAccountName(getPlayerAccount(source)) ) local result = dbPoll( getAnswerData, -1 ) if result then for rid, row in ipairs ( result) do for column, value in pairs ( row ) do end local fname = row["fname"] local sname = row["sname"] outputChatBox (fname..'_'..sname, source, 0, 255, 0, true ) end end end How do I use this on the client side? I mean, for example, I have a label on a client And how to make "fname" from server side to client in this label? smth like that guiSetText ( myLabel, fname ) Link to comment
SycroX Posted June 27, 2019 Share Posted June 27, 2019 local dbSecurityConnection = dbConnect( 'sqlite', 'accs.db') local getAnswerData = dbQuery( dbSecurityConnection, ' SELECT `fname`,`sname` FROM `accountsSecurity` WHERE Login = ? ', getAccountName(getPlayerAccount(source)) ) local result = dbPoll( getAnswerData, -1 ) triggerClientEvent ( source , "DBTABLE" , source , result ) -----# CLIENT addEvent ( "DBTABLE" , true ) addEventHandler ( "DBTABLE" , root , function ( Table ) if Table and #Table > 0 then guiSetText ( myLabel, Table[1]["fname"] ) end end ) 1 Link to comment
fairyoggy Posted June 27, 2019 Author Share Posted June 27, 2019 (edited) 1 hour ago, #x1AhMeD-09 said: local dbSecurityConnection = dbConnect( 'sqlite', 'accs.db') local getAnswerData = dbQuery( dbSecurityConnection, ' SELECT `fname`,`sname` FROM `accountsSecurity` WHERE Login = ? ', getAccountName(getPlayerAccount(source)) ) local result = dbPoll( getAnswerData, -1 ) triggerClientEvent ( source , "DBTABLE" , source , result ) -----# CLIENT addEvent ( "DBTABLE" , true ) addEventHandler ( "DBTABLE" , root , function ( Table ) if Table and #Table > 0 then guiSetText ( myLabel, Table[1]["fname"] ) end end ) and how to make that united in 1 label. (fname and sname) Edited June 27, 2019 by slapz0r Link to comment
SycroX Posted June 27, 2019 Share Posted June 27, 2019 1 hour ago, slapz0r said: and how to make that united in 1 label. (fname and sname) i don't understand what do you trying to say Link to comment
Moderators IIYAMA Posted June 27, 2019 Moderators Share Posted June 27, 2019 guiSetText ( myLabel, tostring(Table[1]["fname"] or "") .. " " .. tostring(Table[1]["sname"] or "") ) 1 Link to comment
fairyoggy Posted June 27, 2019 Author Share Posted June 27, 2019 (edited) 1 hour ago, #x1AhMeD-09 said: i don't understand what do you trying to say --label rpnickname = DGS:dgsCreateLabel(100,310,100,40,"Nick:",false) addEvent ( "DBTABLE" , true ) addEventHandler ( "DBTABLE" , root , function ( Table ) local d1 = Table[1]["fname"] local d2 = Table[1]["sname"] if Table and #Table > 0 then DGS:dgsSetText ( rpnickname, d1.."_"..d2) end end ) -- display nick in other function local name3 = DGS:dgsGetText(rpnickname) The database has data (fname = first name, sname = second name) Each player is different, indicated by the player himself during registration. I made the player see his name like that: FirstName_SecondName but now the player sees his name above ALL PLAYERS but i need to do so that everyone would have a different nickname above their heads (which they type in register(fname and sname field in .db) What am I doing wrong? How to fix it For example, you entered during registration in the field(fname = Alex, sname = Faber) and now you will see this nickname above ALL PLAYERS. NOW IT"S DONE BUT I need to make sure everyone has their own nickname(fname, sname) and this should see all players Edited June 27, 2019 by slapz0r Link to comment
Moderators IIYAMA Posted June 27, 2019 Moderators Share Posted June 27, 2019 (edited) @slapz0r The simplest way would be using serverside element data. You can only use triggerEvents for that, if you can synchronize the fullName data from all players yourself. Server setElementData(source, "fullName", result) Client local players = getElementsByType("player", root, true) for i=1, #players do local player = players[i] local fullName = tostring(getElementData(player, "fullName") or "") end 14 minutes ago, slapz0r said: What am I doing wrong? How to fix it You are sending the message from the server to the OWNER of the nick name. So nobody else has this data. This requires much more code to achieve this functionality. * Edited June 27, 2019 by IIYAMA 1 Link to comment
fairyoggy Posted June 27, 2019 Author Share Posted June 27, 2019 (edited) 7 minutes ago, IIYAMA said: @slapz0r The simplest way would be using serverside element data. You can only use triggerEvents for that, if you can synchronize the fullName data from all players yourself. Server setElementData(source, "fullName", result) Client local players = getElementsByType("player", root, true) for i=1, #players do local player = players[i] local fullName = tostring(getElementData(player, "fullName") or "") end You are sending the message from the server to the OWNER of the nick name. So nobody else has this data. This requires much more code to achieve this functionality. * @IIYAMA how to fix this problem in my code? Edited June 27, 2019 by slapz0r Link to comment
Moderators IIYAMA Posted June 27, 2019 Moderators Share Posted June 27, 2019 1 hour ago, slapz0r said: @IIYAMA how to fix this problem in my code? Can't, as you didn't post your other function... I can't read your mind after all. 2 hours ago, slapz0r said: -- display nick in other function local name3 = DGS:dgsGetText(rpnickname) Link to comment
fairyoggy Posted June 27, 2019 Author Share Posted June 27, 2019 (edited) @IIYAMA Used your code local players = getElementsByType("player", root, true) for i=1, #players do local player = players[i] local fullName = tostring(getElementData(player, "fullName") or "") DGS:dgsSetText ( tester2owibka123, fullName.."_") I do not understand what it gives. After restarting the values are different and should be Lyashko_Lolka Lyashko = fname Lolka = sname What's wrong? 1 hour ago, IIYAMA said: Can't, as you didn't post your other function... I can't read your mind after all. function onClientRender() local cx, cy, cz, lx, ly, lz = getCameraMatrix() for k, player in pairs(g_StreamedInPlayers) do if isElement(player) and isElementStreamedIn(player) then do local vx, vy, vz = getPedBonePosition(player, 8) local dist = getDistanceBetweenPoints3D(cx, cy, cz, vx, vy, vz) if dist < drawDistance and isLineOfSightClear(cx, cy, cz, vx, vy, vz, true, false, false) then local x, y = getScreenFromWorldPosition(vx, vy, vz + 0.3) if x and y then local name = getPlayerName(player) local id = getElementData ( player, "ID", s_id ) local w = dxGetTextWidth(name, 1, "default-bold") local h = dxGetFontHeight(1, "default-bold") local name3 = DGS:dgsGetText(rpnickname) dxDrawText("#FFFFFF"..name3.."#1E90FF ["..id.."]", x - 2 - w / 2, y - 0 - h - 12, w, h, tocolor(255, 0, 0), 1, "default-bold","left","top",false,false,false,true) local health = getElementHealth(player) local armour = getPedArmor(player) if health > 0 then local rate = 500 / getPedStat(player, 24) drawHPBar(x, y - 6, health * rate, dist) if armour > 0 then drawArmourBar(x, y - 12, armour, dist) end end end end end else table.remove(g_StreamedInPlayers, k) end end end addEventHandler("onClientRender", root, onClientRender) @IIYAMA This is a script displaying health, armor, nickname and id . And I need to instead of "getPlayerName(player)" need "First _ SecondName"(fname_sname) from table .db Edited June 27, 2019 by slapz0r Link to comment
Moderators IIYAMA Posted June 27, 2019 Moderators Share Posted June 27, 2019 setElementData(source, "fullName", result[1]) local name = tostring(getElementData(player, "fullName") or "") 1 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