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

Lua Guild cleaner

maikons

Member
Joined
Aug 1, 2015
Messages
227
Reaction score
16
I have an idea but idk if it is possible and how to do...

There is a problem in all server that have a lot of guilds, it never clean, it can have a total inactive guild, but it still there on the list...

My idea of Guild Cleaner i request is:

  • when player logout, if he have a guild store in lastlogin of the guild
  • on starts the server if last login of the guild is more then 3 months clean the guild


- my server is 8.6 using 0.4 sources: Fir3element/3777 (https://github.com/Fir3element/3777)
 
Last edited:
since you provided no information about which server you are using, I'm going to assume latest one, and then you might try this script:
 
since you provided no information about which server you are using, I'm going to assume latest one, and then you might try this script:

i've edit the topic with my sources info

---

so the clean part could be an global event on start up
with mysql querys to clean?

that are 0.4 guild tables:










there is no such thing of guild last login

it could be done in a creaturescript in every player on logout?

idk how to do, idk if it is possible and if it is good
 
i would like to open create guild for free, but last time i did this the guild page become a mess
i need something to clean inactives guilds
 
i would like to have this script too, i know what need to do, but idk how, i need some help

the way should be:

Code:
after check table `guilds` in column `creationdata`
check if guild as more then 30 days

so check amount of players in the guild
Code:
SELECT COUNT(guild_id) FROM `players` WHERE `guild_id` = 2;

so clean
Code:
clean table `guild_invite`
where column `guild_id`

clean table `guild_kills`
where column `guild_id`

clean table `guild_ranks`
where column `guild_id`

clean table `guild_storage`
where column `guild_id`

clean table `guild_wars`
where column `guild_id`
 
i would like to have this script too, i know what need to do, but idk how, i need some help

the way should be:

Code:
after check table `guilds` in column `creationdata`
check if guild as more then 30 days

so check amount of players in the guild
Code:
SELECT COUNT(guild_id) FROM `players` WHERE `guild_id` = 2;

so clean
Code:
clean table `guild_invite`
where column `guild_id`

clean table `guild_kills`
where column `guild_id`

clean table `guild_ranks`
where column `guild_id`

clean table `guild_storage`
where column `guild_id`

clean table `guild_wars`
where column `guild_id`


I made this by look others scripts
I need someone to tell if it is good or there is something wrong:

Code:
<globalevent name="GuildClean" type="startup" event="script" value="guildcleanner.lua"/>

Code:
function onStartup()
   local result_guilds = db.getResult("SELECT `id`, `creationdata` FROM `guilds` ORDER by `creationdata` ASC;")
   local days = 30*3600*24
   local nowtime = os.date('*t')
   if (result_guilds and result_guilds:getID() ~= -1) then
     while(true) do
       local id = result:getDataInt("id")
       local date = result_guilds:getDataInt("creationdata")
       local time= os.time(nowtime) - date
       local duedate = time - days
       if duedate >= 0 then
           local result_countplayersguild = db.getResult("SELECT COUNT(guild_id) FROM `players` WHERE `guild_id` = '".. id .."';")
           if (result_countplayersguild and result_countplayersguild:getID() ~= -1) then
               local manyplayers = result_countplayersguild:getDataInt("COUNT(guild_id)")
               if manyplayers < 10 then
                   db.executeQuery("DELETE FROM `guild_invite` WHERE `guild_id` = '".. id .."';")
                   db.executeQuery("DELETE FROM `guild_kills` WHERE `guild_id` = '".. id .."';")
                   db.executeQuery("DELETE FROM `guild_ranks` WHERE `guild_id` = '".. id .."';")
                   db.executeQuery("DELETE FROM `guild_storage` WHERE `guild_id` = '".. id .."';")
                   db.executeQuery("DELETE FROM `guild_wars` WHERE `guild_id` = '".. id .."';")
               end
           end
       end
       if not(result_guilds:next()) then
           break
       end
   end
   end
end
 
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 :p.

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
 
Last edited:
Back
Top