PrivateKiller Posted March 30, 2015 Posted March 30, 2015 Hello folks, I want to delete data from "TOP 30 Drifters" on my server, because they were cheating. And they are already punished, don't worry . So guys, command would be okay. I don't have any experiences about databases, how they works, how can I create them... << I don't know this stuff. So I'm asking you guys, if you can help me to resed that table. serverside: drift_mejor = 0 addEventHandler( 'onResourceStart', getResourceRootElement(getThisResource()), function( ) outputChatBox("==[ Top-30 Drift Script | By MR.S3D ]==", root, 255, 125, 0,true) outputChatBox("==[ Press F5 To Open Top-30 Top-Drift Script ]==", root, 50, 255, 0,true) executeSQLQuery( 'CREATE TABLE IF NOT EXISTS Drift_top_byS3Dd (Owner, Score, Name)' ) end ) function getPlayerFromNamePart(name) if name then for i, player in ipairs(getElementsByType("player")) do if string.find(getPlayerName(player):lower(), tostring(name):lower(), 1, true) then return player end end end return false end function createTopSystem( player ) if not isElement( player ) then return end local Top = {} local CreatTop = executeSQLQuery( "SELECT * FROM Drift_top_byS3Dd" ) for i = 1, #CreatTop do table.insert(Top,{name = CreatTop[i].Name,score = CreatTop[i].Score}) end if #CreatTop >0 then table.sort(Top, function(a,b) return (tonumber(a.score)or 0) > (tonumber(b.score)or 0) end) setTimer( function() for k, data in ipairs(Top) do if k == 1 then triggerClientEvent (player,"deltTop",player) end triggerClientEvent (player,"updateTop",player,tostring(data.name),tostring(data.score),tonumber(k)) if k == 30 then table.remove(Top) break end end end, 500, 1 ) end end function setAcontSqlData( player, top, name) if not isElement( player ) then return end if isGuestAccount ( getPlayerAccount ( player ) ) then return end result = executeSQLQuery("SELECT * FROM `Drift_top_byS3Dd` WHERE `Owner`=?", getAccountName(getPlayerAccount( player ))) if ( type ( result ) == "table" and #result == 0 ) or not result then executeSQLQuery( 'INSERT INTO Drift_top_byS3Dd( Owner, Score , Name) VALUES( ?, ?, ? )', getAccountName(getPlayerAccount( player )), top, name) else if tonumber ( top ) < tonumber( result[1]["Score"] ) then top = result[1]["Score"] else top = top end executeSQLQuery( 'UPDATE Drift_top_byS3Dd SET Score =?,Name =? WHERE Owner =?', top, name, getAccountName(getPlayerAccount( player ))) end end addEvent("driftNuevoRecord", true) addEventHandler("driftNuevoRecord", root, function(score, name) drift_mejor = score drift_nombre = getPlayerFromNamePart(name) setAcontSqlData( drift_nombre, drift_mejor, name) end ) addEventHandler("onElementDataChange",root, function (data) if ( data == "Best Drift" ) and getElementType(source) == "player" then local drift = getElementData(source,data) setAcontSqlData( source, tonumber(drift), string.gsub(getPlayerName(source), "#%x%x%x%x%x%x", "")) end end ) addEvent("getTop", true) addEventHandler("getTop", root, function() createTopSystem( source ) end ) client-side: local Key = "F5" --- bind key HD = { gridlist = {}, S3D = {}, q = {} } function centerWindow(center_window) local screenW,screenH=guiGetScreenSize() local windowW,windowH=guiGetSize(center_window,false) local x,y = (screenW-windowW)/2,(screenH-windowH)/2 guiSetPosition(center_window,x,y,false) end HD.wnd = guiCreateWindow(415, 146, 450, 505, "Top 30 Drift Script || By MR.S3D V1.2", false) guiWindowSetSizable(HD.wnd, false) guiSetAlpha(HD.wnd, 1.00) guiSetProperty(HD.wnd, "CaptionColour", "FF200AF3") centerWindow(HD.wnd) HD.gridlist[1] = guiCreateGridList(18, 32, 430, 500, false, HD.wnd) local column = guiGridListAddColumn(HD.gridlist[1], "Rank", 0.20 ) -- Create a 'rank' column in the list local column1 = guiGridListAddColumn(HD.gridlist[1], "Player Name", 0.40 ) -- Create a 'players' column in the list local column2 = guiGridListAddColumn(HD.gridlist[1], "Best Drift", 0.30 ) -- Create a 'Total Drift' column in the list for i = 1,30 do local row = guiGridListAddRow ( HD.gridlist[1] ) guiGridListSetItemText ( HD.gridlist[1], row, column, "" .. i .. "-", false, false ) guiGridListSetItemText ( HD.gridlist[1], row, column1, "N/A", false, false ) guiGridListSetItemText ( HD.gridlist[1], row, column2, "N/A", false, false ) guiGridListSetItemColor(HD.gridlist[1], row, column1, 255, 255, 0) guiGridListSetItemColor(HD.gridlist[1], row, column2, 0, 180, 255) guiGridListSetItemColor(HD.gridlist[1], row, column, 255, 0, 0) end guiSetVisible(HD.wnd, not guiGetVisible(HD.wnd)) bindKey (Key, "down", function() guiSetVisible(HD.wnd, not guiGetVisible(HD.wnd)) showCursor(guiGetVisible(HD.wnd)) triggerServerEvent("getTop", localPlayer) end ) function convertNumber ( number ) local formatted = number while true do formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2') if ( k==0 ) then break end end return formatted end function updateTopList(name, top, i) local row = guiGridListAddRow ( HD.gridlist[1] ) guiGridListSetItemText ( HD.gridlist[1], row, column, "" .. i .. "-", false, false ) guiGridListSetItemText ( HD.gridlist[1], row, column1, tostring(name), false, false ) guiGridListSetItemText ( HD.gridlist[1], row, column2, convertNumber(top), false, false ) guiGridListSetItemColor(HD.gridlist[1], row, column1, 255, 255, 0) guiGridListSetItemColor(HD.gridlist[1], row, column2, 0, 180, 255) guiGridListSetItemColor(HD.gridlist[1], row, column, 255, 0, 0) end addEvent("updateTop", true) addEventHandler("updateTop", root, updateTopList) function update() guiGridListClear(HD.gridlist[1]) end addEvent("deltTop", true) addEventHandler("deltTop", root, update)
TrapLord Studios™ Posted March 31, 2015 Posted March 31, 2015 Just clear the database. Visit TrapLord Studios™
xXMADEXx Posted March 31, 2015 Posted March 31, 2015 Use the DELETE statement in SQL. DELETE FROM TableName The Ultimate Lua Tutorial! | MTA PHP SDK
PrivateKiller Posted March 31, 2015 Author Posted March 31, 2015 Just clear the database. There is no database in resource folder even when I start the script.
PrivateKiller Posted March 31, 2015 Author Posted March 31, 2015 Use the DELETE statement in SQL. DELETE FROM TableName Like that? function TableReset ( player ) executeSQLQuery("DELETE FROM 'Drift_top_byS3Dd'") addCommandHandler("DeleteTopDrift", TableReset) end
xXMADEXx Posted March 31, 2015 Posted March 31, 2015 Just clear the database. There is no database in resource folder even when I start the script. That's because its using executeSQLQuery, and not the sqlite/mysql functions. The script is saving the data to registry.db located in the same directory as acl.xml Use the DELETE statement in SQL. DELETE FROM TableName Like that? function TableReset ( player ) executeSQLQuery("DELETE FROM 'Drift_top_byS3Dd'") addCommandHandler("DeleteTopDrift", TableReset) end Not quite, but close. function TableReset ( player ) executeSQLQuery("DELETE FROM Drift_top_byS3Dd") end addCommandHandler("DeleteTopDrift", TableReset) The Ultimate Lua Tutorial! | MTA PHP SDK
PrivateKiller Posted March 31, 2015 Author Posted March 31, 2015 Just clear the database. There is no database in resource folder even when I start the script. That's because its using executeSQLQuery, and not the sqlite/mysql functions. The script is saving the data to registry.db located in the same directory as acl.xml Use the DELETE statement in SQL. DELETE FROM TableName Like that? function TableReset ( player ) executeSQLQuery("DELETE FROM 'Drift_top_byS3Dd'") addCommandHandler("DeleteTopDrift", TableReset) end Not quite, but close. function TableReset ( player ) executeSQLQuery("DELETE FROM Drift_top_byS3Dd") end addCommandHandler("DeleteTopDrift", TableReset) Ohh that's great information for me... I'm learning lua scripting, and I almost got it ha
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