Well what i did on mine was just make it work as it worked in tibia, 1 leader and 4 vice leaders with premium account.
So if you create a guild, you have 4 days to have your 4 vice leaders with premium account, or it will disband.
Also, if you lose 1 of your vice leaders once the guild is activated, you have 14 days to fullfit the 4 vice leaders with premium account, or the guild will disband after that period.
So, i added a column to the guilds table and named it "status", and i set 0 if inactive, 1 if active, and also i added another column named "expiration", where i set the amount of time it have until it expires.
After it, you just need to manage the events in startup.lua:
Just check all the guilds, the amount of vice leaders with pacc, if the amount is less than 4, then set expiration time to current date + 14 days and the state of the guild to inactive.
Also check for all the guilds that have expiration time < than current date, to delete the guild.
I even edited it in the sources, so only players on a "active" guild can be seen with their current guild and tittles, if inactive then it just looks like a normal player (as it was in rl).
I guess you can do the same with the innactivity, make a query to check the lastlogin of all players of a guild, select the player with the closest lastlogin to the current date and compare if it have more than 3 months, if so, then delete guild
.
Here my code (for othire):
Lua:
function Guilds_System()
-- Check Guilds Activations
local resultGuild = db.storeQuery("SELECT `guilds`.`id` as `id`, COUNT(`guild_ranks`.`name`) as `Vice-Leaders` from `players` inner join `guild_ranks` on `players`.`rank_id` = `guild_ranks`.`id` inner join `accounts` on `players`.`account_id` = `accounts`.`id` inner join `guilds` on `guilds`.`id` = `guild_ranks`.`guild_id` inner join (select `id` from `guilds`) as `g2` on `guilds`.`id` = `g2`.`id` where `accounts`.`premend` > "..os.time().." and `guild_ranks`.`level` = 2 group by `guilds`.`id`")
if resultGuild ~= false then
repeat
local guildId = result.getDataInt(resultGuild, "id")
local viceleaders_amount = result.getDataInt(resultGuild, "Vice-Leaders")
if viceleaders_amount > 3 then
db.query("UPDATE `guilds` SET `status` = 0, `expirationdate` = "..os.time()+1209600 .." WHERE `id` = " .. guildId)
else
db.query("UPDATE `guilds` SET `status` = 1 WHERE `id` = " .. guildId) -- Set guilds with less than 3 members as inactives
end
until not result.next(resultGuild)
end
-- Check Players from Guilds already expired
local resultExpirationPlayers = db.storeQuery("select `guilds`.`id` as `guild_id`, `players`.`id` as `player_id`, `guild_invites`.`guild_id` from `guilds` inner join `guild_ranks` on `guilds`.`id` = `guild_ranks`.`guild_id` inner join `players` on `players`.`rank_id` = `guild_ranks`.`id` left join `guild_invites` on `guilds`.`id` = `guild_invites`.`guild_id` where `guilds`.`expirationdate` < "..os.time())
if resultExpirationPlayers ~= false then
repeat
local PlayerId = result.getDataInt(resultExpirationPlayers, "player_id")
db.query("UPDATE `players` SET `rank_id`='0' WHERE `id`= " .. PlayerId) -- Delete guild rank
db.query("UPDATE `players` SET `guildnick`= NULL WHERE `id`= " .. PlayerId) -- Delete guild nick
until not result.next(resultExpirationPlayers)
end
-- Check Guilds already expired
local resultExpiration = db.storeQuery("select `guilds`.`id` as `guild_id` from `guilds` left join `guild_invites` on `guilds`.`id` = `guild_invites`.`guild_id` where `guilds`.`expirationdate` < "..os.time())
if resultExpiration ~= false then
repeat
local ExpirationGuildId = result.getDataInt(resultExpiration, "guild_id")
db.query("DELETE FROM `guild_invites` WHERE `guild_id`= " .. ExpirationGuildId) -- Delete guild invitations
db.query("DELETE FROM `guilds` WHERE `id`= " .. ExpirationGuildId) -- Delete guild itself.
until not result.next(resultExpiration)
end
end