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

Global.....

imback1

Unknown member
Joined
Jul 11, 2013
Messages
785
Solutions
1
Reaction score
46
Hello, I've got a problem with globalsave script
https://imgur.com/HdaQkcO
and this is my init.lua

Code:
function onGlobalSave()
    if(getGameState() ~= GAMESTATE_CLOSING) then
        return onStartup()
    end

    return true
end

Second one with pacman script, i was using with 0.3.6 and was working without any problems but now with 0.4 i found this error when i die from ghost

https://imgur.com/6vu8jzD

local config = {
idleWarning = getConfigValue('idleWarningTime'),
idleKick = getConfigValue('idleKickTime')
}

function onThink(cid, interval)
if(getTileInfo(getCreaturePosition(cid)).nologout or getCreatureNoMove(cid) or
getPlayerCustomFlagValue(cid, PLAYERCUSTOMFLAG_ALLOWIDLE)) then
return true
end

local idleTime = getPlayerIdleTime(cid) + interval
doPlayerSetIdleTime(cid, idleTime)
if(config.idleKick > 0 and idleTime > config.idleKick) then
doRemoveCreature(cid)
elseif(config.idleWarning > 0 and idleTime == config.idleWarning) then
local message = "You have been idle for " .. math.ceil(config.idleWarning / 60000) .. " minutes"
if(config.idleKick > 0) then
message = message .. ", you will be disconnected in "
local diff = math.ceil((config.idleWarning - config.idleKick) / 60000)
if(diff > 1) then
message = message .. diff .. " minutes"
else
message = message .. "one minute"
end

message = message .. " if you are still idle"
end

doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, message .. ".")
end

return true
end
TFS 0.4
 
Last edited:
this is my init
Also a 9 second video on how to display your images.. instead of making us click open a new tab to imgur
(no idea on the pacman)
Code:
local config = {
   creationTime = 7 * 86400,
   checkTime = 7 * 86400,
   viceCount = 4,
   memberCount = 10
}

function onStartup()
   local data, time, result = {}, os.time(), db.getResult("SELECT `id`, `ownerid`, `creationdata`, `checkdata` FROM `guilds` WHERE `world_id` = " .. getConfigValue('worldId') .. ";")
   if(result:getID() ~= -1) then
     repeat
       data[result:getDataInt("id")] = {result:getDataInt("ownerid"), result:getDataInt("creationdata"), result:getDataInt("checkdata")}
     until not(result:next())
     result:free()
   end

   for id, v in ipairs(data) do
     local owner, created, check = v[1], v[2], v[3]
     if(created < (time - config.creationTime)) then
       result = db.getResult("SELECT `id`, `level` FROM `guild_ranks` WHERE `guild_id` = " .. id .. ";")
       if(result:getID() ~= -1) then
         local rank, ranks = 0, {}
         repeat
           ranks[result:getDataInt("id")] = result:getDataInt("level")
           if(result:getDataInt("level") == 1) then
             rank = result:getDataInt("id")
           end
         until not(result:next())
         result:free()

         local members = {0, 0, 0, 0}
         for k, v in ipairs(ranks) do
           result = db.getResult("SELECT COUNT(`id`) AS `count` FROM `players` WHERE `rank_id` = " .. k .. ";")
           if(result:getID() ~= -1) then
             members[v] = members[v] + result:getDataInt("count")
             result:free()
           end

           if(v == 2) then
             result = db.getResult("SELECT `p`.`id` FROM `players` p LEFT JOIN `accounts` a ON `p`.`account_id` = `a`.`id` WHERE `p`.`rank_id` = " .. k .. " AND (`a`.`premdays` = 0 OR (`a`.`lastday` + (`a`.`premdays` * 86400) <= 0));")
             if(result:getID() ~= -1) then
               local demote = ""
               repeat
                 demote = demote .. result:getDataInt("id") .. ","
                 members[2] = members[2] - 1
                 members[1] = members[1] + 1
               until not(result:next())
               result:free()

               if(demote ~= "" and rank ~= 0) then
                 db.executeQuery("UPDATE `players` SET `rank_id` = " .. rank .. " WHERE `id` IN (" .. demote:sub(1, -2) .. ");")
               end
             end
           end
         end

         for i = 1, 3 do
           members[4] = members[4] + members[i]
         end

         if(members[2] < config.viceCount or members[4] < config.memberCount) then
           if(check == 0) then
             db.executeQuery("UPDATE `guilds` SET `checkdata` = " .. (time + config.checkTime) .. " WHERE `id` = " .. id .. ";")
           elseif(check < time) then
             local tmp = ""
             for rank, _ in ipairs(ranks) do
               tmp = tmp .. rank .. ","
             end

             db.executeQuery("UPDATE `players` SET `rank_id` = 0, `guildnick` = '', `guildjoin` = 0 WHERE `rank_id` IN (" .. tmp:sub(1, -2) .. ");")
             db.executeQuery("DELETE FROM `guilds` WHERE `id` = " .. id .. ";")
           end
         end
       end
     end
   end

   db.executeQuery("UPDATE `players` SET `online` = 0 WHERE `world_id` = " .. getConfigValue('worldId') .. " AND `online` > 0;")
   db.executeQuery("UPDATE `bans` SET `active` = 0 WHERE `expires` <= " .. time .. " AND `expires` >= 0 AND `active` = 1")
   db.executeQuery("DELETE FROM `guild_wars` WHERE `status` = 0 AND `begin` < " .. (time - 2 * 86400) .. ";")

   if(getConfigValue("sqlType") ~= "sqlite") then
     db.executeQuery("TRUNCATE TABLE `player_statements`;")
   else
     db.executeQuery("DELETE FROM `player_statements`;")
   end

   return true
end

function onGlobalSave()
   if(getGameState() ~= GAMESTATE_CLOSING) then
     return onStartup()
   end

   return true
end
 
this is my init
Also a 9 second video on how to display your images.. instead of making us click open a new tab to imgur
(no idea on the pacman)
Code:
local config = {
   creationTime = 7 * 86400,
   checkTime = 7 * 86400,
   viceCount = 4,
   memberCount = 10
}

function onStartup()
   local data, time, result = {}, os.time(), db.getResult("SELECT `id`, `ownerid`, `creationdata`, `checkdata` FROM `guilds` WHERE `world_id` = " .. getConfigValue('worldId') .. ";")
   if(result:getID() ~= -1) then
     repeat
       data[result:getDataInt("id")] = {result:getDataInt("ownerid"), result:getDataInt("creationdata"), result:getDataInt("checkdata")}
     until not(result:next())
     result:free()
   end

   for id, v in ipairs(data) do
     local owner, created, check = v[1], v[2], v[3]
     if(created < (time - config.creationTime)) then
       result = db.getResult("SELECT `id`, `level` FROM `guild_ranks` WHERE `guild_id` = " .. id .. ";")
       if(result:getID() ~= -1) then
         local rank, ranks = 0, {}
         repeat
           ranks[result:getDataInt("id")] = result:getDataInt("level")
           if(result:getDataInt("level") == 1) then
             rank = result:getDataInt("id")
           end
         until not(result:next())
         result:free()

         local members = {0, 0, 0, 0}
         for k, v in ipairs(ranks) do
           result = db.getResult("SELECT COUNT(`id`) AS `count` FROM `players` WHERE `rank_id` = " .. k .. ";")
           if(result:getID() ~= -1) then
             members[v] = members[v] + result:getDataInt("count")
             result:free()
           end

           if(v == 2) then
             result = db.getResult("SELECT `p`.`id` FROM `players` p LEFT JOIN `accounts` a ON `p`.`account_id` = `a`.`id` WHERE `p`.`rank_id` = " .. k .. " AND (`a`.`premdays` = 0 OR (`a`.`lastday` + (`a`.`premdays` * 86400) <= 0));")
             if(result:getID() ~= -1) then
               local demote = ""
               repeat
                 demote = demote .. result:getDataInt("id") .. ","
                 members[2] = members[2] - 1
                 members[1] = members[1] + 1
               until not(result:next())
               result:free()

               if(demote ~= "" and rank ~= 0) then
                 db.executeQuery("UPDATE `players` SET `rank_id` = " .. rank .. " WHERE `id` IN (" .. demote:sub(1, -2) .. ");")
               end
             end
           end
         end

         for i = 1, 3 do
           members[4] = members[4] + members[i]
         end

         if(members[2] < config.viceCount or members[4] < config.memberCount) then
           if(check == 0) then
             db.executeQuery("UPDATE `guilds` SET `checkdata` = " .. (time + config.checkTime) .. " WHERE `id` = " .. id .. ";")
           elseif(check < time) then
             local tmp = ""
             for rank, _ in ipairs(ranks) do
               tmp = tmp .. rank .. ","
             end

             db.executeQuery("UPDATE `players` SET `rank_id` = 0, `guildnick` = '', `guildjoin` = 0 WHERE `rank_id` IN (" .. tmp:sub(1, -2) .. ");")
             db.executeQuery("DELETE FROM `guilds` WHERE `id` = " .. id .. ";")
           end
         end
       end
     end
   end

   db.executeQuery("UPDATE `players` SET `online` = 0 WHERE `world_id` = " .. getConfigValue('worldId') .. " AND `online` > 0;")
   db.executeQuery("UPDATE `bans` SET `active` = 0 WHERE `expires` <= " .. time .. " AND `expires` >= 0 AND `active` = 1")
   db.executeQuery("DELETE FROM `guild_wars` WHERE `status` = 0 AND `begin` < " .. (time - 2 * 86400) .. ";")

   if(getConfigValue("sqlType") ~= "sqlite") then
     db.executeQuery("TRUNCATE TABLE `player_statements`;")
   else
     db.executeQuery("DELETE FROM `player_statements`;")
   end

   return true
end

function onGlobalSave()
   if(getGameState() ~= GAMESTATE_CLOSING) then
     return onStartup()
   end

   return true
end
this is my init
Also a 9 second video on how to display your images.. instead of making us click open a new tab to imgur
(no idea on the pacman)
Code:
local config = {
   creationTime = 7 * 86400,
   checkTime = 7 * 86400,
   viceCount = 4,
   memberCount = 10
}

function onStartup()
   local data, time, result = {}, os.time(), db.getResult("SELECT `id`, `ownerid`, `creationdata`, `checkdata` FROM `guilds` WHERE `world_id` = " .. getConfigValue('worldId') .. ";")
   if(result:getID() ~= -1) then
     repeat
       data[result:getDataInt("id")] = {result:getDataInt("ownerid"), result:getDataInt("creationdata"), result:getDataInt("checkdata")}
     until not(result:next())
     result:free()
   end

   for id, v in ipairs(data) do
     local owner, created, check = v[1], v[2], v[3]
     if(created < (time - config.creationTime)) then
       result = db.getResult("SELECT `id`, `level` FROM `guild_ranks` WHERE `guild_id` = " .. id .. ";")
       if(result:getID() ~= -1) then
         local rank, ranks = 0, {}
         repeat
           ranks[result:getDataInt("id")] = result:getDataInt("level")
           if(result:getDataInt("level") == 1) then
             rank = result:getDataInt("id")
           end
         until not(result:next())
         result:free()

         local members = {0, 0, 0, 0}
         for k, v in ipairs(ranks) do
           result = db.getResult("SELECT COUNT(`id`) AS `count` FROM `players` WHERE `rank_id` = " .. k .. ";")
           if(result:getID() ~= -1) then
             members[v] = members[v] + result:getDataInt("count")
             result:free()
           end

           if(v == 2) then
             result = db.getResult("SELECT `p`.`id` FROM `players` p LEFT JOIN `accounts` a ON `p`.`account_id` = `a`.`id` WHERE `p`.`rank_id` = " .. k .. " AND (`a`.`premdays` = 0 OR (`a`.`lastday` + (`a`.`premdays` * 86400) <= 0));")
             if(result:getID() ~= -1) then
               local demote = ""
               repeat
                 demote = demote .. result:getDataInt("id") .. ","
                 members[2] = members[2] - 1
                 members[1] = members[1] + 1
               until not(result:next())
               result:free()

               if(demote ~= "" and rank ~= 0) then
                 db.executeQuery("UPDATE `players` SET `rank_id` = " .. rank .. " WHERE `id` IN (" .. demote:sub(1, -2) .. ");")
               end
             end
           end
         end

         for i = 1, 3 do
           members[4] = members[4] + members[i]
         end

         if(members[2] < config.viceCount or members[4] < config.memberCount) then
           if(check == 0) then
             db.executeQuery("UPDATE `guilds` SET `checkdata` = " .. (time + config.checkTime) .. " WHERE `id` = " .. id .. ";")
           elseif(check < time) then
             local tmp = ""
             for rank, _ in ipairs(ranks) do
               tmp = tmp .. rank .. ","
             end

             db.executeQuery("UPDATE `players` SET `rank_id` = 0, `guildnick` = '', `guildjoin` = 0 WHERE `rank_id` IN (" .. tmp:sub(1, -2) .. ");")
             db.executeQuery("DELETE FROM `guilds` WHERE `id` = " .. id .. ";")
           end
         end
       end
     end
   end

   db.executeQuery("UPDATE `players` SET `online` = 0 WHERE `world_id` = " .. getConfigValue('worldId') .. " AND `online` > 0;")
   db.executeQuery("UPDATE `bans` SET `active` = 0 WHERE `expires` <= " .. time .. " AND `expires` >= 0 AND `active` = 1")
   db.executeQuery("DELETE FROM `guild_wars` WHERE `status` = 0 AND `begin` < " .. (time - 2 * 86400) .. ";")

   if(getConfigValue("sqlType") ~= "sqlite") then
     db.executeQuery("TRUNCATE TABLE `player_statements`;")
   else
     db.executeQuery("DELETE FROM `player_statements`;")
   end

   return true
end

function onGlobalSave()
   if(getGameState() ~= GAMESTATE_CLOSING) then
     return onStartup()
   end

   return true
end
i know this way but i tried to do it but something wrong happened and doesn't show the photo :(, btw thanks for this init i will try it and tell you if is it work.
 
Last edited:
Back
Top