• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

GlobalEvent Automated Database Cleanup 1.1, the solution for inactive players

Status
Not open for further replies.
Pretty cool!
THIS ROX LOVE YOU AND REPPED!

What happens on level 150+, it is 90 days?
they wont get deleted, but you can configure yours, just read the code, its easy to understand and modify

I. Personally like the script and the idea but the fact that ur doing it basically for rep and basically pushon kids to rep you just ruins it for me.
i am not you
 
Last edited:
I. Personally like the script and the idea but the fact that ur doing it basically for rep and basically pushon kids to rep you just ruins it for me.

You seems jealous :peace:


It's a great relese, and flamers .i.
 
thanks guys :]
 
very good script.
using in my server thank you.
 
plx:
Lua:
-- [[> Automated Database Cleanup 1.1 //By Cybermaster <]] --
-- [[> Function getDBPlayersCount() by Elf <]] --
-- [[> Function & Script edited by Shawak <]] --

local cleanup = {
       	[10] = {time = 5 * 24 * 60 * 60},
        [20] = {time = 15 * 24 * 60 * 60},
        [50] = {time = 30 * 24 * 60 * 60},
        [100] = {time = 60 * 24 * 60 * 60},
        [150] = {time = 90 * 24 * 60 * 60}
}

function getDBPlayersCount()
	local result = db.getResult("SELECT COUNT(`id`) as `count` FROM `players`;")
	return result:getDataInt("count") and result:free()
end

function onStartup()
        local DB_BEFORE = getDBPlayersCount()

        for i = 1, #cleanup do
                db.executeQuery("DELETE FROM `players` WHERE `level` < ".. cleanup[i].level .." AND `group_id` < 2 AND `lastlogin` < UNIX_TIMESTAMP() - ".. cleanup[i].time ..";")
        end

	local DB_NOW = DB_BEFORE - getDBPlayersCount()
	if DB_NOW == 0 then
		return print(">> [DB_CLEANUP] No inactive players have been deleted from database.")
	end

	local text = ">> [DB_CLEANUP] "..DB_NOW.." inactive players have been deleted from database."
	local file = io.open("data/logs/db_cleanup.txt", "a")
	return print("" .. text .. "") and file:write("\n[".. os.date("%d %B %Y %X ", os.time()) .."] Deleted "..DB_NOW.." players from the database.") and file:close()
end

Not tested :peace:.
 
is this right? Cybermaster
[20/12/2009 16:54:58] OTSYS_SQLITE3_PREPARE(): SQLITE ERROR: no such function: UNIX_TIMESTAMP (DELETE FROM "players" WHERE "level" < 2 AND "id" > 6 AND "group_id" < 2 AND "lastlogin" < UNIX_TIMESTAMP() - 864000;)
[20/12/2009 16:54:58] OTSYS_SQLITE3_PREPARE(): SQLITE ERROR: no such function: UNIX_TIMESTAMP (DELETE FROM "players" WHERE "level" < 100 AND "id" > 6 AND "group_id" < 2 AND "lastlogin" < UNIX_TIMESTAMP() - 1296000;)
[20/12/2009 16:54:58] OTSYS_SQLITE3_PREPARE(): SQLITE ERROR: no such function: UNIX_TIMESTAMP (DELETE FROM "players" WHERE "level" < 200 AND "id" > 6 AND "group_id" < 2 AND "lastlogin" < UNIX_TIMESTAMP() - 1728000;)
[20/12/2009 16:54:58] OTSYS_SQLITE3_PREPARE(): SQLITE ERROR: no such function: UNIX_TIMESTAMP (DELETE FROM "players" WHERE "level" < 300 AND "id" > 6 AND "group_id" < 2 AND "lastlogin" < UNIX_TIMESTAMP() - 2160000;)
[20/12/2009 16:54:58] OTSYS_SQLITE3_PREPARE(): SQLITE ERROR: no such function: UNIX_TIMESTAMP (DELETE FROM "players" WHERE "level" < 400 AND "id" > 6 AND "group_id" < 2 AND "lastlogin" < UNIX_TIMESTAMP() - 2592000;)
 
plx:
Lua:
-- [[> Automated Database Cleanup 1.1 //By Cybermaster <]] --
-- [[> Function getDBPlayersCount() by Elf <]] --
-- [[> Function & Script edited by Shawak <]] --

local cleanup = {
       	[10] = {time = 5 * 24 * 60 * 60},
        [20] = {time = 15 * 24 * 60 * 60},
        [50] = {time = 30 * 24 * 60 * 60},
        [100] = {time = 60 * 24 * 60 * 60},
        [150] = {time = 90 * 24 * 60 * 60}
}

function getDBPlayersCount()
	local result = db.getResult("SELECT COUNT(`id`) as `count` FROM `players`;")
	return result:getDataInt("count") and result:free()
end

function onStartup()
        local DB_BEFORE = getDBPlayersCount()

        for i = 1, #cleanup do
                db.executeQuery("DELETE FROM `players` WHERE `level` < ".. cleanup[i].level .." AND `group_id` < 2 AND `lastlogin` < UNIX_TIMESTAMP() - ".. cleanup[i].time ..";")
        end

	local DB_NOW = DB_BEFORE - getDBPlayersCount()
	if DB_NOW == 0 then
		return print(">> [DB_CLEANUP] No inactive players have been deleted from database.")
	end

	local text = ">> [DB_CLEANUP] "..DB_NOW.." inactive players have been deleted from database."
	local file = io.open("data/logs/db_cleanup.txt", "a")
	return print("" .. text .. "") and file:write("\n[".. os.date("%d %B %Y %X ", os.time()) .."] Deleted "..DB_NOW.." players from the database.") and file:close()
end

Not tested :peace:.

you are using the "return" the wrong way in this function.

is not wrong to do so but when it comes to a function we need to use the return, it would generate an error occurred because the return argument can not be built within "scopos".

function getDBPlayersCount()
local result = db.getResult("SELECT COUNT(`id`) as `count` FROM `players`;")
return result:getDataInt("count") and result:free()
end
not everything can be built that way all returning.
 
aww forgott;
Lua:
  -- [[> Automated Database Cleanup 1.1 //By Cybermaster <]] --
-- [[> Function getDBPlayersCount() by Elf <]] --
-- [[> Function & Script edited by Shawak <]] --

local cleanup = {
        [10] = {time = 5 * 24 * 60 * 60},
        [20] = {time = 15 * 24 * 60 * 60},
        [50] = {time = 30 * 24 * 60 * 60},
        [100] = {time = 60 * 24 * 60 * 60},
        [150] = {time = 90 * 24 * 60 * 60}
}

function getDBPlayersCount()
        local result = db.getResult("SELECT COUNT(`id`) as `count` FROM `players`;")
        local _result = result:getDataInt("count")
        result:free()
        return _result
end

function onStartup()
        local DB_BEFORE = getDBPlayersCount()

        for k, v in pairs(cleanup) do
                db.executeQuery("DELETE FROM `players` WHERE `level` < ".. k .." AND `group_id` < 2 AND `lastlogin` < UNIX_TIMESTAMP() - ".. v.time ..";")
        end

        local DB_NOW = DB_BEFORE - getDBPlayersCount()
        if DB_NOW == 0 then
                return print(">> [DB_CLEANUP] No inactive players have been deleted from database.")
        end

        local text = ">> [DB_CLEANUP] "..DB_NOW.." inactive players have been deleted from database."
        local file = io.open("data/logs/db_cleanup.txt", "a")
        return print("" .. text .. "") and file:write("\n[".. os.date("%d %B %Y %X ", os.time()) .."] Deleted "..DB_NOW.." players from the database.") and file:close()
end
 
Last edited:
and for SQLITE too, change ` to "

[20/12/2009 16:54:58] OTSYS_SQLITE3_PREPARE(): SQLITE ERROR: no such function: UNIX_TIMESTAMP (DELETE FROM "players" WHERE "level" < 2 AND "id" > 6 AND "group_id" < 2 AND "lastlogin" < UNIX_TIMESTAMP() - 864000

there is no such function for sqlite.
 
modify the script for the way it is can only be used in mysql.
 
Very good script definetly using it to keep the database clean and simple :D


and WORD UP guitar freak

Eff you flamers >:]
 
thanks
well i still dont know if the deleted players get their items in db deleted too
if someone can confirm me this, i will update the script then
 
What happens with possible houses that they owned? Do they get cleaned aswell?
 
as i said before, you shouldnt worry about that
its their fault if they dont login and lose their items, if u are using this script
 
Nice script like always cybermaster. Could you tell me where the line is with the samples? I can't read anything out that chracters of 0-6 are protected since i got a clean by that database script with samples of 3-6
 
Nice script like always cybermaster. Could you tell me where the line is with the samples? I can't read anything out that chracters of 0-6 are protected since i got a clean by that database script with samples of 3-6

modify it there:

PHP:
  for i = 1, #cleanup do
                db.executeQuery("DELETE FROM `players` WHERE `level` < ".. cleanup[i].level .." AND `group_id` < 2 AND `lastlogin` < UNIX_TIMESTAMP() - ".. cleanup[i].time ..";")
 
Status
Not open for further replies.
Back
Top