Best-Killer Posted October 31, 2016 Share Posted October 31, 2016 server Kills_ = {} addEventHandler('onResourceStart',resourceRoot,function () exports.NGSQL:db_exec("CREATE TABLE IF NOT EXISTS `group_stuff` ( name, kills , arrests )") end ) addEventHandler("onPlayerWasted",root,function ( _,Killer ) if ( Killer and Killer ~= source and getElementType(Killer) == "player" ) then local groupPlayer = exports.SAEGGroups:getPlayerGroup( Killer ) if not Kills_[Killer] then Kills_[Killer] = 0; end Kills_[Killer] = Kills_[Killer] + 1 local Sel = exports.NGSQL:db_exec("SELECT * FROM `group_stuff` WHERE name=?", groupPlayer) if ( type ( Sel ) == "table" and #Sel == 0 or not Sel ) then exports.NGSQL:db_exec(" INSERT INTO `group_stuff` (name, kills) VALUES(?,?)",groupPlayer , Kills_[Killer]) else exports.NGSQL:db_exec(" UPDATE `group_stuff` SET name =?, kills =? ",groupPlayer,Kills_[Killer]) end end end) addEvent ( 'getData', true) addEventHandler ( 'getData', root, function() local db = exports.NGSQL:db_exec("SELECT * FROM `group_stuff` ") if ( type ( db ) == "table" and #db == 0 or not db ) then return end triggerClientEvent ( source, 'setData', source, db ) end ) Client : local screenW, screenH = guiGetScreenSize() function killListGui() killgrid = guiCreateGridList(865, 590, 159, 178, false) guiGridListAddColumn(killgrid, "Gang", 0.5) guiGridListAddColumn(killgrid, "Kills", 0.5) guiSetAlpha(killgrid, 0.73) dxDrawRectangle(865, 590, 159, 178, tocolor(0, 0, 0, 180), false) guiSetVisible ( killgrid,true ) end addEventHandler("onClientResourceStart", resourceRoot,killListGui) dx = function() dxDrawRectangle(865, 590, 159, 178, tocolor(0, 0, 0, 180), false) end function isEventHandlerAdded( sEventName, pElementAttachedTo, func ) if type( sEventName ) == 'string' and isElement( pElementAttachedTo ) and type( func ) == 'function' then local aAttachedFunctions = getEventHandlers( sEventName, pElementAttachedTo ) if type( aAttachedFunctions ) == 'table' and #aAttachedFunctions > 0 then for i, v in ipairs( aAttachedFunctions ) do if v == func then return true end end end end return false end bindKey('f4','down', function() if isEventHandlerAdded ("onClientRender", root,dx) then removeEventHandler("onClientRender", root,dx) else triggerServerEvent( 'getData', localPlayer ) addEventHandler("onClientRender", root,dx) end end) addEvent( 'setData', true ) addEventHandler ( 'setData', root, function(data) guiGridListClear ( killgrid ) table.sort ( data, function (a,b) return ( tonumber(a.Kills) or 0 ) > ( tonumber(b.Kills) or 0 )end) for k,v in ipairs ( data ) do local Row = guiGridListAddRow(killgrid) guiGridListSetItemText(killgrid,Row,1,v.name,false,false) guiGridListSetItemText(killgrid,Row,2,v.kills,false,false) if k == 10 then break end -- هذا بس 10 ويوقف تقدر تعدله او تحذف السطر . end end) error : dbexe failed, (1064) you have an error in your sql syntax; check the manual that corresponds to your mariaDB server version for the right syntax to use near 'kills , arrests) Link to comment
pa3ck Posted October 31, 2016 Share Posted October 31, 2016 Okay, so you probably have list of players / groups in the table, but when you are updating it, you never specify what you want to update. You forgot the WHERE clause. Try this: exports.NGSQL:db_exec(" UPDATE `group_stuff` kills =? WHERE name = ?", Kills_[Killer], groupPlayer) I removed the name = ? part, because I'm pretty sure you don't need to update the name of the group, if you do (depends on what you actually want), just put it back in. Link to comment
Best-Killer Posted October 31, 2016 Author Share Posted October 31, 2016 9 minutes ago, pa3ck said: Okay, so you probably have list of players / groups in the table, but when you are updating it, you never specify what you want to update. You forgot the WHERE clause. Try this: exports.NGSQL:db_exec(" UPDATE `group_stuff` kills =? WHERE name = ?", Kills_[Killer], groupPlayer) I removed the name = ? part, because I'm pretty sure you don't need to update the name of the group, if you do (depends on what you actually want), just put it back in. you're right but still same error Link to comment
GTX Posted October 31, 2016 Share Posted October 31, 2016 exports.NGSQL:db_exec(" UPDATE `group_stuff` SET kills = ? WHERE name = ?", Kills_[Killer], groupPlayer) Link to comment
Best-Killer Posted October 31, 2016 Author Share Posted October 31, 2016 with addEventHandler('onResourceStart',resourceRoot,function () exports.NGSQL:db_exec("CREATE TABLE IF NOT EXISTS `group_stuff` ( name VARCHAR(20), kills VARCHAR(40)"); end ) and exports.NGSQL:db_exec(" UPDATE `group_stuff` SET kills = ? WHERE name = ?", Kills_[Killer], groupPlayer) and that client side : local screenW, screenH = guiGetScreenSize() function killListGui() killgrid = guiCreateGridList(865, 590, 159, 178, false) guiGridListAddColumn(killgrid, "Gang", 0.5) guiGridListAddColumn(killgrid, "Kills", 0.5) guiSetAlpha(killgrid, 0.73) dxDrawRectangle(865, 590, 159, 178, tocolor(0, 0, 0, 180), false) guiSetVisible ( killgrid,true ) end addEventHandler("onClientResourceStart", resourceRoot,killListGui) dx = function() dxDrawRectangle(865, 590, 159, 178, tocolor(0, 0, 0, 180), false) end function isEventHandlerAdded( sEventName, pElementAttachedTo, func ) if type( sEventName ) == 'string' and isElement( pElementAttachedTo ) and type( func ) == 'function' then local aAttachedFunctions = getEventHandlers( sEventName, pElementAttachedTo ) if type( aAttachedFunctions ) == 'table' and #aAttachedFunctions > 0 then for i, v in ipairs( aAttachedFunctions ) do if v == func then return true end end end end return false end bindKey('f4','down', function() if isEventHandlerAdded ("onClientRender", root,dx) then removeEventHandler("onClientRender", root,dx) else triggerServerEvent( 'getData', localPlayer ) addEventHandler("onClientRender", root,dx) end end) addEvent( 'setData', true ) addEventHandler ( 'setData', root, function(data) guiGridListClear ( killgrid ) table.sort ( data, function (a,b) return ( tonumber(a.Kills) or 0 ) > ( tonumber(b.Kills) or 0 )end) for k,v in ipairs ( data ) do local Row = guiGridListAddRow(killgrid) guiGridListSetItemText(killgrid,Row,1,v.name,false,false) guiGridListSetItemText(killgrid,Row,2,v.kills,false,false) if k == 10 then break end -- هذا بس 10 ويوقف تقدر تعدله او تحذف السطر . end end) error : bad argument #1 to 'sort' (table expected, got boolean ) Link to comment
Best-Killer Posted November 1, 2016 Author Share Posted November 1, 2016 bad argument #1 to 'sort' (table expected, got boolean ) Client------- local screenW, screenH = guiGetScreenSize() function killListGui() killgrid = guiCreateGridList(865, 590, 159, 178, false) guiGridListAddColumn(killgrid, "Gang", 0.5) guiGridListAddColumn(killgrid, "Kills", 0.5) guiSetAlpha(killgrid, 0.73) dxDrawRectangle(865, 590, 159, 178, tocolor(0, 0, 0, 180), false) guiSetVisible ( killgrid,true ) end addEventHandler("onClientResourceStart", resourceRoot,killListGui) dx = function() dxDrawRectangle(865, 590, 159, 178, tocolor(0, 0, 0, 180), false) end function isEventHandlerAdded( sEventName, pElementAttachedTo, func ) if type( sEventName ) == 'string' and isElement( pElementAttachedTo ) and type( func ) == 'function' then local aAttachedFunctions = getEventHandlers( sEventName, pElementAttachedTo ) if type( aAttachedFunctions ) == 'table' and #aAttachedFunctions > 0 then for i, v in ipairs( aAttachedFunctions ) do if v == func then return true end end end end return false end bindKey('f4','down', function() if isEventHandlerAdded ("onClientRender", root,dx) then removeEventHandler("onClientRender", root,dx) else triggerServerEvent( 'getData', localPlayer ) addEventHandler("onClientRender", root,dx) end end) addEvent( 'setData', true ) addEventHandler ( 'setData', root, function(data) guiGridListClear ( killgrid ) table.sort ( data, function (a,b) return ( tonumber(a.kills) or 0 ) > ( tonumber(b.kills) or 0 )end) for k,v in ipairs ( data ) do local Row = guiGridListAddRow(killgrid) guiGridListSetItemText(killgrid,Row,1,v.name,false,false) guiGridListSetItemText(killgrid,Row,2,v.kills,false,false) if k == 10 then break end -- هذا بس 10 ويوقف تقدر تعدله او تحذف السطر . end end) serve------ Kills_ = {} addEventHandler('onResourceStart',resourceRoot,function () exports.NGSQL:db_exec("CREATE TABLE IF NOT EXISTS `group_stuff` ( name, kills "); end ) addEventHandler("onPlayerWasted",root,function ( _,Killer ) if ( Killer and Killer ~= source and getElementType(Killer) == "player" ) then local groupPlayer = exports.SAEGGroups:getPlayerGroup( Killer ) if not Kills_[Killer] then Kills_[Killer] = 0; end Kills_[Killer] = Kills_[Killer] + 1 local Sel = exports.NGSQL:db_exec("SELECT * FROM `group_stuff` WHERE name=?", groupPlayer) if ( type ( Sel ) == "table" and #Sel == 0 or not Sel ) then exports.NGSQL:db_exec(" INSERT INTO `group_stuff` (name, kills) VALUES(?,?)",groupPlayer , Kills_[Killer]) else exports.NGSQL:db_exec(" UPDATE `group_stuff` SET kills = ? WHERE name = ?", Kills_[Killer], groupPlayer) end end end) addEvent ( 'getData', true) addEventHandler ( 'getData', root, function() local db = exports.NGSQL:db_exec("SELECT * FROM `group_stuff` ") if ( type ( db ) == "table" and #db == 0 or not db ) then return end triggerClientEvent ( source, 'setData', source, db ) end ) Link to comment
Addlibs Posted November 1, 2016 Share Posted November 1, 2016 There error is self-explanatory. Argument #1 ("data") is nil where it should be a table. Line 26 in serverside filters (breaks function via return) only in the following circumstances: If type of return is a table... ...and that table is empty The return is a nil value. This means that a value of true/false will succeed past line 26 and get sent over to the client, and the client will then attempt to sort that boolean value as if it were a table, causing the error. Try using the following code instead of what you have on line 26. if (type(db) ~= "table" or (type(db)=="table" and #db==0) or not db) then return end This should: Reject any non-table values If the value is a table, reject it if it is empty Reject nil values 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