• 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!

[MOD/Globalevents] Guild clean.

kito2

www.masteria.net
Joined
Mar 9, 2009
Messages
3,766
Solutions
1
Reaction score
225
Location
Chile, Santiago
Many times there are people that makes guilds but then they retire and the guild stays there... So, I have an idea... Making a MOD or a globalevent that checks the leader last log in, and if it is older than X days, then the guild gets deleted.

It is a nice idea.

I don't know how to do it, but it should be like:

Check guilds ids -> get leader from ownerid -> check leader lastlogin -> compare lastlogin to the actual date -> if it higher than X days, then the guild id gets deleted, if it is lower than X days, then it skips and continue with the other guild id.
 
Try that:
PHP:
function getLastLoginDiff(name)
	if type(name) ~= "string" then
		return name
	end
	
	local res = db.getResult("SELECT `lastlogin` FROM `players` WHERE `name` = '"..name.."';")
	if res:getID() ~= -1 then
		return os.time()-res:getDataInt('lastlogin')
	end
end

local days = 7

function onStartup()
	local guild = db.getResult("SELECT `id`, `ownerid` FROM `guilds`;")
	if guild:getID() == -1 then
		return true
	end
	repeat
		local id, owner = guild:getDataInt("id"), guild:getDataInt("ownerid")
		local diff = getLastLoginDiff(getPlayerNameByGUID(owner))
		if diff >= 7*24*60*60 then
			db.executeQuery("DELETE FROM `guilds` WHERE `id` = "..id..";")
		end
	until not(guild:next())
	guild:free()
	return true
end

Globalevent.
 
dibujokju.png


Bug :S
 
Well it works. How did you test it? With a real guild or you just created a "fake" database entry?

PHP:
function getLastLoginDiff(name)
	if type(name) ~= "string" then
		return name
	end
	
	local res = db.getResult("SELECT `lastlogin` FROM `players` WHERE `name` = '"..name.."';")
	if res:getID() ~= -1 then
		return os.time()-res:getDataInt('lastlogin')
	end
end

local days = 7

function onStartup()
	local guild = db.getResult("SELECT `id`, `ownerid` FROM `guilds`;")
	if guild:getID() ~= -1 then
		repeat
			local id, owner = guild:getDataInt("id"), guild:getDataInt("ownerid")
			local diff = getLastLoginDiff(getPlayerNameByGUID(owner))
			if diff >= 60 then
				db.executeQuery("DELETE FROM `guilds` WHERE `id` = "..id..";")
				print("Guild " .. id .. " was deleted.")
			end
		until not(guild:next())
		guild:free()
	end
	return true
end
 
It works for me, but then I have the problem that no guild -> no war scores, so I removed this script and also the option to delete guilds on website.
 
Back
Top