Ranous Posted June 14, 2016 Share Posted June 14, 2016 (edited) Datas in database and panel datas is not equal. Client-Side; function getGridPlayer(userMoney,userKills,userDeaths,userJoins) if ( guiGridListGetSelectedItem ( playersGridList ) ) then local thePlayerName = guiGridListGetSelectedItemText ( playersGridList ) getUserName = getPlayerFromPartialName (thePlayerName) guiSetText (nameLabel,"Username: "..thePlayerName) triggerServerEvent("onClientRequestAccountNames", getLocalPlayer(),getUserName) guiSetText (moneyLabel,"Money: "..userMoney) guiSetText (killsLabel,"Kills: "..userKills) guiSetText (deathsLabel,"Deaths: "..userDeaths) guiSetText (joinLabel,"Joins: "..userJoins.."x") end end addEvent("onSendAccountNamesToClient", true) addEventHandler("onSendAccountNamesToClient", getRootElement(), getGridPlayer) addEventHandler ("onClientGUIClick",root,getGridPlayer) Server-Side; function gAccountsToSend(getUserName) local gAccount = getPlayerAccount(getUserName) local gAccountName = getAccountName(gAccount) if (gAccountName) then local query = dbQuery (dataBase,"SELECT money,playerKills,playerDeaths,playerJoin FROM userDatabase WHERE accountName = ?",gAccountName) local result = dbPoll (query,-1) if (#result ~= 0) then userMoney = result.money userKills = result.playerKills userDeaths = result.playerDeaths userJoins = result.playerJoin triggerClientEvent(source, "onSendAccountNamesToClient", getRootElement(), userMoney,userKills,userDeaths,userJoins) end end end addEvent("onClientRequestAccountNames", true) addEventHandler("onClientRequestAccountNames", getRootElement(), gAccountsToSend) Database; Panel; Debug Code; Edited June 14, 2016 by Guest Link to comment
KariiiM Posted June 14, 2016 Share Posted June 14, 2016 Explain your problem with more details Link to comment
Tomas Posted June 14, 2016 Share Posted June 14, 2016 Client function getGridPlayer(userMoney,userKills,userDeaths,userJoins) if ( guiGridListGetSelectedItem ( playersGridList ) ) then local thePlayerName = guiGridListGetSelectedItemText ( playersGridList ) getUserName = getPlayerFromPartialName (thePlayerName) guiSetText (nameLabel,"Username: "..thePlayerName) triggerServerEvent("onClientRequestAccountNames", getLocalPlayer(),getUserName) guiSetText (moneyLabel,"Money: "..(userMoney or 0) ) guiSetText (killsLabel,"Kills: "..(userKills or 0) ) guiSetText (deathsLabel,"Deaths: "..(userDeaths or 0) ) guiSetText (joinLabel,"Joins: "..(userJoins or 0).."x") end end addEvent("onSendAccountNamesToClient", true) addEventHandler("onSendAccountNamesToClient", getRootElement(), getGridPlayer) addEventHandler ("onClientGUIClick",root,getGridPlayer) Link to comment
Ranous Posted June 14, 2016 Author Share Posted June 14, 2016 Thank you Tomas but statics is 0 now. Link to comment
KariiiM Posted June 14, 2016 Share Posted June 14, 2016 Thank you Tomas but statics is 0 now. Debug the outputted values. Link to comment
KariiiM Posted June 14, 2016 Share Posted June 14, 2016 Remove your client code by this code and open your panel be sure the debugscript is actived before you open the panel and show us what's on the debugscript. Code: function getGridPlayer(userMoney,userKills,userDeaths,userJoins) if ( guiGridListGetSelectedItem ( playersGridList ) ) then local thePlayerName = guiGridListGetSelectedItemText ( playersGridList ) getUserName = getPlayerFromPartialName (thePlayerName) guiSetText (nameLabel,"Username: "..thePlayerName) outputDebugString ( "UserMoney: ".. tostring ( userMoney ) ) outputDebugString ( "UserKills: ".. tostring ( userKills ) ) outputDebugString ( "UserDeaths: ".. tostring ( userDeaths ) ) outputDebugString ( "UserJoins: ".. tostring ( userJoins ) ) triggerServerEvent("onClientRequestAccountNames", getLocalPlayer(),getUserName) guiSetText (moneyLabel,"Money: "..(userMoney or 0) ) guiSetText (killsLabel,"Kills: "..(userKills or 0) ) guiSetText (deathsLabel,"Deaths: "..(userDeaths or 0) ) guiSetText (joinLabel,"Joins: "..(userJoins or 0).."x") end end addEvent("onSendAccountNamesToClient", true) addEventHandler("onSendAccountNamesToClient", getRootElement(), getGridPlayer) addEventHandler ("onClientGUIClick",root,getGridPlayer) Link to comment
KariiiM Posted June 14, 2016 Share Posted June 14, 2016 Well, I noticed that, the problem isn't in client side it's in server side Because with this line, as far as userMoney variable is a nil value it will keep outputting number 0 to your label. guiSetText (moneyLabel,"Money: "..(userMoney or 0) ) Link to comment
Ranous Posted June 14, 2016 Author Share Posted June 14, 2016 Full:Server-Side; -- CONNECT DATABASE -- addEventHandler ("onResourceStart",root, function() dataBase = dbConnect ("sqlite","userDatabase.db") userDatabase = dbExec (dataBase ,"CREATE TABLE IF NOT EXISTS userDatabase(accountName TEXT,money INT,playerKills INT,playerDeaths INT,playerJoin INT)" ) end ) -- ADD ACCOUNT DATA -- addEventHandler ("onPlayerLogin",root, function(_,acName) local userAccountName = getAccountName (acName) local accountNameQuery = dbQuery(dataBase, "SELECT accountName FROM userDatabase WHERE accountName = ?", userAccountName) local result = dbPoll(accountNameQuery, -1) if #result == 0 or not result then createData = dbExec (dataBase,"INSERT INTO userDatabase(accountName,money,playerKills,playerDeaths,playerJoin) VALUES (?,?,?,?,?)",userAccountName,0,0,0,0) if (createData) then outputChatBox ("#FF8600*#C1C1C1Your account data was successfully created.",source,255,255,255,true) end end end ) -- DELETE ACCOUNT DATA -- addCommandHandler ("deleteAccountData", function(thePlayer,command,accName) local aName = getAccountName( getPlayerAccount(thePlayer) ) if isObjectInACLGroup("user."..aName, aclGetGroup("Admin")) then if accName then local accountNameDB = dbQuery(dataBase, "SELECT accountName FROM userDatabase WHERE accountName = ?", accName) local result = dbPoll(accountNameDB, -1) if #result ~= 0 then deleteUserData = dbExec (dataBase,"DELETE FROM userDatabase WHERE accountName=?", accName) if (deleteUserData) then outputChatBox ("#FF8600*#C1C1C1Account data was deleted. ("..accName..")",source,255,255,255,true) end else outputChatBox ("#FF8600*#C1C1C1Account name could not be found. ("..accName..")",source,255,255,255,true) end end end end ) -- ACCOUNT CLIENT-SIDE -- function gAccountsToSend(getUserName) local gAccount = getPlayerAccount(getUserName) local gAccountName = getAccountName(gAccount) if (gAccountName) then local query = dbQuery (dataBase,"SELECT money,playerKills,playerDeaths,playerJoin FROM userDatabase WHERE accountName = ?",gAccountName) local result = dbPoll (query,-1) if (#result ~= 0) then userMoney = result.money userKills = result.playerKills userDeaths = result.playerDeaths userJoins = result.playerJoin triggerClientEvent(source, "onSendAccountNamesToClient", getRootElement(), userMoney,userKills,userDeaths,userJoins) end end end addEvent("onClientRequestAccountNames", true) addEventHandler("onClientRequestAccountNames", getRootElement(), gAccountsToSend) -- STATICS: DEATHS -- function deathPlayer() local playerAccount = getPlayerAccount(source) local userAccountName = getAccountName (playerAccount) dbExec(dataBase, "UPDATE userDatabase SET playerDeaths = IFNULL (playerDeaths, 0) + 1 WHERE accountName = ?", userAccountName) end addEventHandler ("onPlayerWasted",root,deathPlayer) -- STATICS: JOINS -- function joinsX(_,uName) local userAccountName = getAccountName (uName) dbExec(dataBase, "UPDATE userDatabase SET playerJoin = IFNULL (playerJoin, 0) + 1 WHERE accountName = ?", userAccountName) end addEventHandler ("onPlayerLogin",root,joinsX) Link to comment
KariiiM Posted June 14, 2016 Share Posted June 14, 2016 Full server side: local dataBase = dbConnect ( "sqlite", "userDatabase.db" ) dbExec (dataBase ,"CREATE TABLE IF NOT EXISTS userDatabase(accountName TEXT,money INT,playerKills INT,playerDeaths INT,playerJoin INT)" ) -- ADD ACCOUNT DATA -- addEventHandler ("onPlayerLogin",root, function(_,acName) local userAccountName = getAccountName ( acName ) local accountNameQuery = dbQuery ( dataBase, "SELECT accountName FROM userDatabase WHERE accountName = ?", userAccountName ) local result = dbPoll ( accountNameQuery, -1 ) if ( #result == 0 ) then local createData = dbExec ( dataBase, "INSERT INTO userDatabase(accountName,money,playerKills,playerDeaths,playerJoin) VALUES (?,?,?,?,?)",userAccountName,0,0,0,0) if ( createData ) then outputChatBox ("#FF8600*#C1C1C1Your account data was successfully created.",source,255,255,255,true) end end end ) -- DELETE ACCOUNT DATA -- addCommandHandler ("deleteAccountData", function(thePlayer,command,accName) local aName = getAccountName( getPlayerAccount(thePlayer) ) if isObjectInACLGroup("user."..aName, aclGetGroup("Admin")) then if accName then local accountNameDB = dbQuery(dataBase, "SELECT accountName FROM userDatabase WHERE accountName = ?", accName) local result = dbPoll(accountNameDB, -1) if #result ~= 0 then deleteUserData = dbExec (dataBase,"DELETE FROM userDatabase WHERE accountName=?", accName) if (deleteUserData) then outputChatBox ("#FF8600*#C1C1C1Account data was deleted. ("..accName..")",source,255,255,255,true) end else outputChatBox ("#FF8600*#C1C1C1Account name could not be found. ("..accName..")",source,255,255,255,true) end end end end ) -- ACCOUNT CLIENT-SIDE -- function gAccountsToSend( user ) local gAccount = getPlayerAccount( user ) local gAccountName = getAccountName(gAccount) if (gAccountName) then local query = dbQuery (dataBase,"SELECT money,playerKills,playerDeaths,playerJoin FROM userDatabase WHERE accountName = ?",gAccountName) local result = dbPoll (query,-1) if ( #result > 0 ) then local userMoney = result.money local userKills = result.playerKills local userDeaths = result.playerDeaths local userJoins = result.playerJoin triggerClientEvent( client, "onSendAccountNamesToClient", client, userMoney,userKills,userDeaths,userJoins) end end end addEvent("onClientRequestAccountNames", true) addEventHandler("onClientRequestAccountNames", getRootElement(), gAccountsToSend) -- STATICS: DEATHS -- function deathPlayer() local playerAccount = getPlayerAccount(source) local userAccountName = getAccountName (playerAccount) dbExec(dataBase, "UPDATE userDatabase SET playerDeaths = IFNULL (playerDeaths, 0) + 1 WHERE accountName = ?", userAccountName) end addEventHandler ("onPlayerWasted",root,deathPlayer) -- STATICS: JOINS -- function joinsX(_,uName) local userAccountName = getAccountName (uName) dbExec(dataBase, "UPDATE userDatabase SET playerJoin = IFNULL (playerJoin, 0) + 1 WHERE accountName = ?", userAccountName) end addEventHandler ("onPlayerLogin",root,joinsX) Client side: function getGridPlayer(userMoney,userKills,userDeaths,userJoins) if ( guiGridListGetSelectedItem ( playersGridList ) ) then local thePlayerName = guiGridListGetSelectedItemText ( playersGridList ) local getUserName = getPlayerFromPartialName (thePlayerName) guiSetText (nameLabel,"Username: "..thePlayerName) outputDebugString ( "UserMoney: ".. tostring ( userMoney ) ) outputDebugString ( "UserKills: ".. tostring ( userKills ) ) outputDebugString ( "UserDeaths: ".. tostring ( userDeaths ) ) outputDebugString ( "UserJoins: ".. tostring ( userJoins ) ) triggerServerEvent("onClientRequestAccountNames", getLocalPlayer(),getUserName) guiSetText (moneyLabel,"Money: ".. tostring ( userMoney ) ) guiSetText (killsLabel,"Kills: ".. tostring ( userKills ) ) guiSetText (deathsLabel,"Deaths: ".. tostring ( userDeaths ) ) guiSetText (joinLabel,"Joins: ".. tostring ( userJoins ).."x") end end addEvent("onSendAccountNamesToClient", true) addEventHandler("onSendAccountNamesToClient", getRootElement(), getGridPlayer) addEventHandler ("onClientGUIClick",root,getGridPlayer) Link to comment
Ranous Posted June 14, 2016 Author Share Posted June 14, 2016 -- OUTPUT -- Money: Nil Kills: Nil Deaths: Nil Joins: Nil Link to comment
KariiiM Posted June 14, 2016 Share Posted June 14, 2016 I found your problem as well, tell me are you pressing on something to get the statics of a player? Link to comment
KariiiM Posted June 14, 2016 Share Posted June 14, 2016 I think I solved your problem, try that and tell me the results --Client side: function getGridPlayer ( getUserName, userMoney, userKills, userDeaths, userJoins ) guiSetText (nameLabel,"Username: ".. tostring ( getPlayerName ( getUserName ) ) ) guiSetText (moneyLabel,"Money: ".. tostring ( userMoney ) ) guiSetText (killsLabel,"Kills: ".. tostring ( userKills ) ) guiSetText (deathsLabel,"Deaths: ".. tostring ( userDeaths ) ) guiSetText (joinLabel,"Joins: ".. tostring ( userJoins ).."x") end addEvent ( "onSendAccountNamesToClient", true ) addEventHandler("onSendAccountNamesToClient", root, getGridPlayer) function onGridClick( ) if ( source == playersGridList ) then local getUserName = getPlayerFromName ( guiGridListGetItemText ( playersGridList, guiGridListGetSelectedItem ( playersGridList ), 1) ) if ( getUserName ) then triggerServerEvent ( "onClientRequestAccountNames", localPlayer, getUserName ) end end end addEventHandler ( "onClientGUIClick", guiRoot, onGridClick ) --Server side: Change the gAccountsToSendfunction with this one: -- ACCOUNT CLIENT-SIDE -- function gAccountsToSend( getUserName ) local gAccount = getPlayerAccount( getUserName ) local gAccountName = getAccountName ( gAccount ) if ( gAccountName ) then local query = dbQuery (dataBase,"SELECT money,playerKills,playerDeaths,playerJoin FROM userDatabase WHERE accountName = ?",gAccountName) local result = dbPoll (query,-1) if ( #result > 0 ) then local userMoney = result.money local userKills = result.playerKills local userDeaths = result.playerDeaths local userJoins = result.playerJoin triggerClientEvent( client, "onSendAccountNamesToClient", client, getUserName, userMoney, userKills, userDeaths, userJoins) end end end addEvent("onClientRequestAccountNames", true) addEventHandler("onClientRequestAccountNames", getRootElement(), gAccountsToSend) Link to comment
Ranous Posted June 14, 2016 Author Share Posted June 14, 2016 I get player statics with dbQuery and I send a Client-Side with triggerClientEvent. I have tried. Script does not work. Link to comment
KariiiM Posted June 14, 2016 Share Posted June 14, 2016 The code that I wrote should work, debug the outputted values from database -- ACCOUNT CLIENT-SIDE -- function gAccountsToSend( getUserName ) local gAccount = getPlayerAccount( getUserName ) local gAccountName = getAccountName ( gAccount ) if ( gAccountName ) then local query = dbQuery (dataBase,"SELECT money,playerKills,playerDeaths,playerJoin FROM userDatabase WHERE accountName = ?",gAccountName) local result = dbPoll (query,-1) if ( #result > 0 ) then local userMoney = result.money local userKills = result.playerKills local userDeaths = result.playerDeaths local userJoins = result.playerJoin outputDebugString ( tostring ( userMoney ) ) outputDebugString ( tostring ( userKills ) ) outputDebugString ( tostring ( userDeaths ) ) outputDebugString ( tostring ( userJoins ) ) outputDebugString ( tostring ( getPlayerName ( getUserName ) ) triggerClientEvent( client, "onSendAccountNamesToClient", client, getUserName, userMoney, userKills, userDeaths, userJoins) end end end addEvent("onClientRequestAccountNames", true) addEventHandler("onClientRequestAccountNames", getRootElement(), gAccountsToSend) Link to comment
Ranous Posted June 14, 2016 Author Share Posted June 14, 2016 Debug is empty. I guess sql is difficult. Link to comment
KariiiM Posted June 14, 2016 Share Posted June 14, 2016 Debug is empty. I guess sql is difficult. Don't give up, Delete the selected account and reconnect then check again Link to comment
Ranous Posted June 14, 2016 Author Share Posted June 14, 2016 it's still the same, debug is empty and script does not work. Link to comment
KariiiM Posted June 15, 2016 Share Posted June 15, 2016 ? Send me the full code via pm, I will test it and fix it for you when I have a free time ofc. 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