• 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 tfs 1.3 error

Dorianek

Member
Joined
Nov 29, 2018
Messages
247
Reaction score
10
Location
Poland
img, screen error

Lua:
--[[
CREATE TABLE `castle_48` (
  `guild_id` int(3) NOT NULL,
) ENGINE=MyISAM DEFAULT CHARSET=latin1
--]]

Castle48H = {
    players = {},
    guilds ={},
    msg = {
        prefix = "[Castle48H] ",
        start = "The event has started, good luck to all guilds!",
        endEvent = "The event ended and everyone was taken to the temple.",
        guildWinner = "The winning guild was %s. Everyone in the guild wins %d% more experience until 3 pm tomorrow.",
        openEvent = "The event will start in %d minute%s, get ready!",
        endingEvent = "The event will end in %d minute%s! conquer the throne!",
        notOpen = "The event has not yet opened!",
        notGuild = "You don't have a guild to join this event..",
        alreadyOwner = "The dominant guild is already yours.",
        nowOwner = "the guild %s just mastered the event.",
        notWinner = "No guild has conquered the castle.",
        levelMin = "You need to be on the level %d or greater%s.",
        vote = "Voting has been opened. Use !castle48 1 for the last dominant guild to win or !castle48 2 for the longest dominant guild to win.",
        chooseVote = "Voting was closed and it was determined that %s with %d wishes.",
        tieVote = "The vote was tied! The last dominant of the castle will be the winner!",
    },
    days = {
        ["Sunday"] = {"20:00"},
        ["Tuesday"] = {"20:00"},
        ["Thursday"] = {"20:00"},
        ["Friday"] = {"20:00"},
        ["Saturday"] = {"20:00"},
    },
    levelMin = 100,
    plusXP = 50,
    storageGlobal = 74641,
    storageLever = 74642,
    storageVoteOne = 74643,
    storageVoteTwo = 74644,
    playerStorageVote = 74645,
    storageVoteFinal = 74646,
    actionIDEnter = 7197,
    actionIDExit = 7198,
    
}

Castle48H.open = function()
    Game.setStorageValue(Castle48H.storageGlobal, 0)
    Game.setStorageValue(Castle48H.storageVoteOne, 0)
    Game.setStorageValue(Castle48H.storageVoteTwo, 0)
    Game.broadcastMessage(Castle48H.msg.prefix .. Castle48H.msg.vote)
    addEvent(Game.broadcastMessage, 5 * 60 * 1000, Castle48H.msg.prefix .. Castle48H.msg.openEvent:format(5, "s"))
    addEvent(Game.broadcastMessage, 7 * 60 * 1000, Castle48H.msg.prefix .. Castle48H.msg.openEvent:format(3, "s"))
    addEvent(function()
        Game.broadcastMessage(Castle48H.msg.prefix .. Castle48H.msg.openEvent:format(1, ""))
    end, 9 * 60 * 1000)
    addEvent(function()
        if Game.getStorageValue(Castle48H.storageVoteOne) > Game.getStorageValue(Castle48H.storageVoteTwo) then
            Game.broadcastMessage(Castle48H.msg.prefix .. Castle48H.msg.chooseVote:format("the last dominant of the castle will be the winner", Game.getStorageValue(Castle48H.storageVoteOne)))
            Game.setStorageValue(Castle48H.storageVoteFinal, 1)
        elseif Game.getStorageValue(Castle48H.storageVoteTwo) > Game.getStorageValue(Castle48H.storageVoteOne) then
            Game.broadcastMessage(Castle48H.msg.prefix .. Castle48H.msg.chooseVote:format("the dominant guild for the longest time will be the winner", Game.getStorageValue(Castle48H.storageVoteTwo)))
            Game.setStorageValue(Castle48H.storageVoteFinal, 2)
        else
            Game.broadcastMessage(Castle48H.msg.prefix .. Castle48H.msg.tieVote)
            Game.setStorageValue(Castle48H.storageVoteFinal, 1)
        end
        Game.setStorageValue(Castle48H.storageGlobal, 1)
        Game.broadcastMessage(Castle48H.msg.prefix .. Castle48H.msg.start)
    end, 10 * 60 * 1000)
end

Castle48H.close = function()
    Game.broadcastMessage(Castle48H.msg.prefix .. Castle48H.msg.endingEvent:format(5, "s"))
    addEvent(Game.broadcastMessage, 2 * 60 * 1000, Castle48H.msg.prefix .. Castle48H.msg.endingEvent:format(3, "s"))
    addEvent(Game.broadcastMessage, 4 * 60 * 1000, Castle48H.msg.prefix .. Castle48H.msg.endingEvent:format(1, ""))
    addEvent(function()
        if Game.getStorageValue(Castle48H.storageVoteFinal) == 1 then
            if Game.getStorageValue(Castle48H.storageLever) >= 0 then
                Game.broadcastMessage(Castle48H.msg.prefix .. Castle48H.msg.endEvent)
                local guild = Guild(Game.getStorageValue(Castle48H.storageLever))
                Game.broadcastMessage(Castle48H.msg.prefix .. Castle48H.msg.guildWinner:format(guild:getName(), Castle48H.plusXP))
                db.query(('UPDATE `castle_48` SET `guild_id` = "%d"'):format(guild:getId()))
            else
                Game.broadcastMessage(Castle48H.msg.prefix .. Castle48H.msg.endEvent)
                Game.broadcastMessage(Castle48H.msg.prefix .. Castle48H.msg.notWinner)
                db.query(('UPDATE `castle_48` SET `guild_id` = "%d"'):format(-1))
            end
        elseif Game.getStorageValue(Castle48H.storageVoteFinal) == 2 then
            if #Castle48H.guilds ~= nil then
                table.sort(Castle48H.guilds, function(a,b) return a[1] > b[1] end)
                Game.broadcastMessage(Castle48H.msg.prefix .. Castle48H.msg.endEvent)
                local guild = Guild(Castle48H.guilds[1])
                Game.broadcastMessage(Castle48H.msg.prefix .. Castle48H.msg.guildWinner:format(guild:getName(), Castle48H.plusXP))
                db.query(('UPDATE `castle_48` SET `guild_id` = "%d"'):format(guild:getId()))
            else
                Game.broadcastMessage(Castle48H.msg.prefix .. Castle48H.msg.notWinner)
                db.query(('UPDATE `castle_48` SET `guild_id` = "%d"'):format(-1))
            end
        else
            print("Error Castle48H - function close")
        end
        Game.setStorageValue(Castle48H.storageGlobal, -1)
        Game.setStorageValue(Castle48H.storageLever, -1)
        Game.setStorageValue(Castle48H.storageVoteFinal, -1)
        Castle48H.endEvent()
        db.query('UPDATE `player_storage SET `0` WHERE `key` = '.. Castle48H.playerStorageVote)
    end, 5 * 60 * 1000)
end

Castle48H.insertPlayer = function(playerId)
    if not Castle48H.players[playerId] then
        Castle48H.players[playerId] = {}
    end
end

Castle48H.deletePlayer = function(playerId)
    if Castle48H.players[playerId] then
        Castle48H.players[playerId] = nil
    end
end

Castle48H.useLever = function(guildId)
    if Game.getStorageValue(Castle48H.storageVoteFinal) == 1 then
        Game.setStorageValue(Castle48H.storageLever, guildId)
    elseif Game.getStorageValue(Castle48H.storageVoteFinal) == 2 then
        if not Castle48H.guilds[guildId] then
            Castle48H.guilds[guildId] = 0
        end
        Game.setStorageValue(Castle48H.storageLever, guildId)
        addEvent(function (guildId)
            Castle48H.guilds[guildId] = Castle48H.guilds[guildId] + 1
        end, 1000)
        Castle48H.useLever(guildId)
    else
        print(">> Error in Castle48H - userLever")
    end
end

Castle48H.removePlayers = function()
    for a in pairs(Castle48H.players) do
        local player = Player(a)
        player:teleportTo(player:getTown():getTemplePosition())
        player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
        Castle48H.deletePlayer(player:getId())
    end
end
Castle48H.removeGuilds = function()
    for b in pairs(Castle48H.guilds) do
        Castle48H.guilds[b] = nil
    end
end

Castle48H.endEvent = function()
    Castle48H.removePlayers()
    Castle48H.removeGuilds()
end

Castle48H.checkGuildWinner = function()
    local guildId  = -1
    local resultId = db.storeQuery("SELECT `guild_id` FROM `castle_48`;")
    if (resultId ~= false) then
      guildId = result.getDataInt(resultId, "guild_id")
      result.free(resultId)
    end
    return guildId
end
 

Attachments

You mostly have to add this Game.setStorageValue(Castle48H.storageLever, 0) at the beginning of the function Castle48H.open = function() or change the check to ~= -1 in line 79.
 
Back
Top