12p Posted January 10, 2011 Share Posted January 10, 2011 Thanks to all scripters that have patience to help all noobish scripters, like me OK, I'm trying to create my own "Top Scores" system with GUI. Everythings works but 1 thing... Rows aren't added. I don't know what is happening, no debug errors, even from mine. The thing I noticed with custom debugging is that normally when a row is added, there should be a "+1 row" message; that one doesn't shows, anytime. SERVER SIDE: function updateSQLRowForPlayer(p) local name = getPlayerName(p) local acc = getPlayerAccount (p) if not isGuestAccount (acc) then local kills = getAccountData (acc,"zombieKills") local level = getAccountData (acc,"rankLvl") local test = executeSQLSelect ("levelling","player_name","player_name = '"..name.."'") if test == false then local acc = getPlayerAccount (p) if executeSQLInsert ("levelling","'"..name.."', "..kills..", "..level) then outputDebugString ("SQL Database has created a row for "..name.."!") else outputDebugString ("SQL Database got error when creating a row for "..name.."!") end else if executeSQLUpdate ("levelling","player_name = '"..name.."', kills = '"..kills.."', level = '"..level.."'", "player_name = '"..name.."'") then outputDebugString ("SQL Database has updated "..name.." row!") else outputDebugString ("SQL Database got error when updating "..name.." row!") end end end end function getHighScores () local highScores = executeSQLQuery ("SELECT player_name, kills, level FROM levelling") if highScores then return highScores else outputDebugString ("Error when trying to get high scores!") return false end end setTimer(triggerClientEvent,1500,1,"onClientHighScoresUpdate",getRootElement(),getHighScores()) CLIENT SIDE: addEventHandler ("onClientHighScoresUpdate",getRootElement(), function (scores) if type(scores) == "table" then for i,s in ipairs (scores) do outputDebugString ("+1 Row!") --THIS DOESNT APPEAR! WHAT THE...? IF "scores" IS A TABLE, WHY DOESNT GET SHOWED ANY DEBUG MESSAGE LIKE THIS? local row = guiGridListAddRow (scoresGrid) guiGridListSetItemText (scoresGrid,row,1,s[1],false,false) guiGridListSetItemText (scoresGrid,row,2,tostring(s[2]),false,true) guiGridListSetItemText (scoresGrid,row,3,tostring(s[3]),false,true) end else outputDebugString ("Problem with the high scores table, looks like isn't processed!") --THIS DOESNT APPEARS TOO! end end) Why aren't rows added? Maybe tables can't be synced with events? Link to comment
Kenix Posted January 11, 2011 Share Posted January 11, 2011 Thanks to all scripters that have patience to help all noobish scripters, like me OK, I'm trying to create my own "Top Scores" system with GUI. Everythings works but 1 thing... Rows aren't added. I don't know what is happening, no debug errors, even from mine. The thing I noticed with custom debugging is that normally when a row is added, there should be a "+1 row" message; that one doesn't shows, anytime. SERVER SIDE: function updateSQLRowForPlayer(p) local name = getPlayerName(p) local acc = getPlayerAccount (p) if not isGuestAccount (acc) then local kills = getAccountData (acc,"zombieKills") local level = getAccountData (acc,"rankLvl") local test = executeSQLSelect ("levelling","player_name","player_name = '"..name.."'") if test == false then local acc = getPlayerAccount (p) if executeSQLInsert ("levelling","'"..name.."', "..kills..", "..level) then outputDebugString ("SQL Database has created a row for "..name.."!") else outputDebugString ("SQL Database got error when creating a row for "..name.."!") end else if executeSQLUpdate ("levelling","player_name = '"..name.."', kills = '"..kills.."', level = '"..level.."'", "player_name = '"..name.."'") then outputDebugString ("SQL Database has updated "..name.." row!") else outputDebugString ("SQL Database got error when updating "..name.." row!") end end end end function getHighScores () local highScores = executeSQLQuery ("SELECT player_name, kills, level FROM levelling") if highScores then return highScores else outputDebugString ("Error when trying to get high scores!") return false end end setTimer(triggerClientEvent,1500,1,"onClientHighScoresUpdate",getRootElement(),getHighScores()) CLIENT SIDE: addEventHandler ("onClientHighScoresUpdate",getRootElement(), function (scores) if type(scores) == "table" then for i,s in ipairs (scores) do outputDebugString ("+1 Row!") --THIS DOESNT APPEAR! WHAT THE...? IF "scores" IS A TABLE, WHY DOESNT GET SHOWED ANY DEBUG MESSAGE LIKE THIS? local row = guiGridListAddRow (scoresGrid) guiGridListSetItemText (scoresGrid,row,1,s[1],false,false) guiGridListSetItemText (scoresGrid,row,2,tostring(s[2]),false,true) guiGridListSetItemText (scoresGrid,row,3,tostring(s[3]),false,true) end else outputDebugString ("Problem with the high scores table, looks like isn't processed!") --THIS DOESNT APPEARS TOO! end end) Why aren't rows added? Maybe tables can't be synced with events? the problem might be opening event will likely need to be getLocal Player () server setTimer(triggerClientEvent,1500,1,"onClientHighScoresUpdate",source,getHighScores()) client addEvent ( "onClientHighScoresUpdate", true ) -- lol you forgot to add Event. addEventHandler ("onClientHighScoresUpdate",getLocalPlayer(), function (scores) I'm not sure what is right. P.s and yet I doubt setTimer () Link to comment
Castillo Posted January 11, 2011 Share Posted January 11, 2011 if i'm right when you use triggerClientEvent it must use getRootElement not getLocalPlayer. Link to comment
12p Posted January 11, 2011 Author Share Posted January 11, 2011 ok... volk, you aren't right. That event hasn't a player as source, because I don't want to, and it setTimer(triggerClientEvent,1500,1,"onClientHighScoresUpdate",source,getHighScores()) What source? LOL there is no source -.- addEvent ( "onClientHighScoresUpdate", true ) -- I did this in my source code, just I forgot to add it to the code I passed here. addEventHandler ("onClientHighScoresUpdate",getLocalPlayer(), --As the event source ISNT A PLAYER, then that event won't work, ever. function (scores) Link to comment
Castillo Posted January 11, 2011 Share Posted January 11, 2011 it was returning nil for me, seems that i fixed it addEvent("onClientHighScoresUpdate",true) addEventHandler ("onClientHighScoresUpdate",getRootElement(), function (scores) if type(scores) == "table" then for i,s in ipairs (scores) do outputDebugString ("+1 Row!") local row = guiGridListAddRow (scoresGrid) guiGridListSetItemText (scoresGrid,row,1,tostring(s["player_name"]),false,false) guiGridListSetItemText (scoresGrid,row,2,tostring(s["kills"]),false,true) guiGridListSetItemText (scoresGrid,row,3,tostring(s["level"]),false,true) end else outputDebugString ("Problem with the high scores table, looks like isn't processed!") end end) now it adds a row with: [MM]Castillo 100 500 Link to comment
12p Posted January 11, 2011 Author Share Posted January 11, 2011 Doesn't work... lol. Link to comment
Castillo Posted January 12, 2011 Share Posted January 12, 2011 It works and you know that it does since i show you a pic in msn.. Link to comment
12p Posted January 12, 2011 Author Share Posted January 12, 2011 If I'm right you modified some things and you didn't give me the last code version that you have. It doesn't work. Link to comment
Castillo Posted January 12, 2011 Share Posted January 12, 2011 you aren't inserting any data in the sqlite db, you should insert it manually to test it, use sqlitebrowser (you can find it on mta community) 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