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

boolean value (tfs 1.2)

wizinx

Active Member
Joined
Jul 6, 2010
Messages
211
Solutions
3
Reaction score
49
Location
Chile, Santiago
Hello everyone, I have the following error.

Lua:
Lua Script Error: [CreatureScript Interface]
data/creaturescripts/scripts/playerdeath.lua:onDeath
data/lib/core/guildwars.lua:49: attempt to concatenate local 'warId' (a boolean value)
stack traceback:
        [C]: in function '__concat'
        data/lib/core/guildwars.lua:49: in function 'getFragLimit'
        data/lib/core/guildwars.lua:30: in function 'processKill'
        data/creaturescripts/scripts/playerdeath.lua:81: in function <data/creaturescripts/scripts/playerdeath.lua:4>

guildwars.lua

Lua:
--
-- Created by IntelliJ IDEA.
-- User: eubrunomiguel
-- Date: 2020-05-23
-- Time: 08:37
-- To change this template use File | Settings | File Templates.
--

guildwars = {}

guildwars.__index = guildwars

function guildwars:isInWar(player1, player2)
    if not player1:getGuild() or not player2:getGuild() then
        return 0
    end

    if player1:getGuild():getId() == 0 or player2:getGuild():getId() == 0 then
        return 0
    end

    if player1:getGuild():getId() == player2:getGuild():getId() then
        return 0
    end

    return isInWar(player1:getId(), player2:getId())
end

function guildwars:processKill(warId, killer, player)
    local fragLimit = self:getFragLimit(warId)

    local killerFrags = self:getKills(warId, killer:getGuild():getId()) + 1
    local deadFrags = self:getKills(warId, player:getGuild():getId())

    local killerMsg = "Opponent " .. player:getName() .. " of the " .. player:getGuild():getName() .. " was killed by " .. killer:getName() .. ". The new score is " .. killerFrags .. ":" .. deadFrags .. " frags (limit " .. fragLimit .. ")."
    killer:guildBroadcast(killerMsg)

    local deadMsg = "Guild member " .. player:getName() .. " was killed by " .. killer:getName() .. " of the " .. killer:getGuild():getName() .. ". The new score is " .. deadFrags .. ":" .. killerFrags .. " frags (limit " .. fragLimit .. ")."
    player:guildBroadcast(deadMsg)

    self:insertKill(warId, killer, player)

    if killerFrags >= fragLimit then
        self:endWar(warId, killer, player, killerFrags)
    end
end

function guildwars:getFragLimit(warId)
    local resultId = db.storeQuery("SELECT `frag_limit` FROM `guild_wars` WHERE `id` = " .. warId)
    if resultId ~= false then
        local frag_limit = result.getDataInt(resultId, "frag_limit")
        result.free(resultId)
        return frag_limit
    end
    return 0
end

function guildwars:getKills(warId, guildId)
    local resultId = db.storeQuery("SELECT COUNT(*) as frags FROM `guildwar_kills` WHERE `warid` = " .. warId .. " and `killerguild` = " .. guildId)
    if resultId ~= false then
        local frags = result.getDataInt(resultId, "frags")
        result.free(resultId)
        return frags
    end
    return 0
end

function guildwars:insertKill(warId, killer, target)
    db.asyncQuery("INSERT INTO `guildwar_kills` (`killer`, `target`, `killerguild`, `targetguild`, `warid`) VALUES (" .. db.escapeString(killer:getName()) .. ", " .. db.escapeString(target:getName()) .. ", " .. killer:getGuild():getId() .. ", " .. target:getGuild():getId() .. ", " .. warId .. ")")
end

function guildwars:endWar(warId, killer, player, frags)
    local winGuildInternalMessage = "Congratulations! You have won the war against " .. player:getGuild():getName() .. " with " .. frags .. " frags."
    killer:guildBroadcast(winGuildInternalMessage)

    local loseGuildInternalMessage = "You have lost the war against " .. killer:getGuild():getName() .. ". They have reached the limit of " .. frags .. " frags."
    player:guildBroadcast(loseGuildInternalMessage)

    broadcastMessage(killer:getGuild():getName() .. " have won the war against " .. player:getGuild():getName() .. " with " .. frags .. " frags.", MESSAGE_EVENT_ADVANCE)

    self:updateState(warId, 5)

    self:setWarEmblem(killer:getGuild(), player:getGuild(), 0)
end

function guildwars:setWarEmblem(guild1, guild2, emblem)
    local guild1Members = guild1:getMembersOnline()
    for i = #guild1Members, 1, -1 do
        guild1Members[i]:setSkull(emblem)
    end

    local guild2Members = guild2:getMembersOnline()
    for i = #guild2Members, 1, -1 do
        guild2Members[i]:setSkull(emblem)
    end
end

function guildwars:updateState(warId, status)
    db.asyncQuery("UPDATE `guild_wars` SET `status` = " .. status .. " WHERE `id` = " .. warId)
end

function guildwars:getPendingInvitation(guild1, guild2)
    local resultId = db.storeQuery("SELECT `id` FROM `guild_wars` WHERE `guild1` = " .. guild1 .. " AND `guild2` = " .. guild2 .. " AND `status` = 0")

    if resultId then
        local id = result.getDataInt(resultId, "id")
        result.free(resultId)

        return id
    end

    return 0
end

function guildwars:startWar(warId, guild1, guild2)
    self:updateState(warId, 1)

    self:setWarEmblem(guild1, guild2, 2)

    broadcastMessage(guild1:getName() .. " has accepted " .. guild2:getName() .. " invitation to war.", MESSAGE_EVENT_ADVANCE)
end

function guildwars:rejectWar(warId, guild1, guild2)
    self:updateState(warId, 2)
    broadcastMessage(guild1:getName() .. " has rejected " .. guild2:getName() .. " invitation to war.", MESSAGE_EVENT_ADVANCE)
end

function guildwars:cancelWar(warId, guild1, guild2)
    self:updateState(warId, 3)
    broadcastMessage(guild1:getName() .. " has canceled invitation to a war with " .. guild2:getName() .. ".", MESSAGE_EVENT_ADVANCE)
end

function guildwars:invite(guild1, guild2, frags)
    local str = ""
    local tmpQuery = db.storeQuery("SELECT `guild1`, `status` FROM `guild_wars` WHERE `guild1` IN (" .. guild1:getId() .. "," .. guild2:getId() .. ") AND `guild2` IN (" .. guild2:getId() .. "," .. guild1:getId() .. ") AND `status` IN (0, 1)")
    if tmpQuery then
        if result.getDataInt(tmpQuery, "status") == 0 then
            if result.getDataInt(tmpQuery, "guild1") == guild1:getId() then
                str = "You have already invited " .. guild2:getName() .. " to war."
            else
                str = guild2:getName() .. " have already invited you to war."
            end
        else
            str = "You are already on a war with " .. guild2:getName() .. "."
        end

        result.free(tmpQuery)
    end

    if str ~= "" then
        player:sendCancelMessage(str)
        return true
    end

    frags = math.max(10, math.min(1000, frags))

    db.asyncQuery("INSERT INTO `guild_wars` (`guild1`, `guild2`, `frag_limit`) VALUES (" .. guild1:getId() .. ", " .. guild2:getId() .. ", " .. frags .. ");")
    broadcastMessage(guild1:getName() .. " has invited " .. guild2:getName() .. " to war for " .. frags .. " frags.", MESSAGE_EVENT_ADVANCE)
end

function guildwars:acceptRequestToEndWar(guild1, guild2)
    local resultId = db.storeQuery("SELECT `id`, `status` FROM `guild_wars` WHERE `guild1` = " .. guild1:getId() .. " AND `guild2` = " .. guild2:getId() .. " AND `status` IN (1, 4)")
    if resultId then
        local warId = result.getDataInt(resultId, "id")
        local status = result.getDataInt(resultId, "status")
        result.free(resultId)

        self:updateState(warId, 5)

        broadcastMessage(guild1:getName() .. " has " .. (status == 4 and "mend fences" or "ended up a war") .. " with " .. guild2:getName() .. ".", MESSAGE_EVENT_ADVANCE)

        self:setWarEmblem(guild1, guild2, 0)

        return true
    end

    return false
end

function guildwars:requestToEndWar(guild1, guild2)
    local resultId = db.storeQuery("SELECT `id` FROM `guild_wars` WHERE `guild1` = " .. guild1:getId() .. " AND `guild2` = " .. guild2:getId() .. " AND `status` = 1")
    if resultId then
        local warId = result.getDataInt(resultId, "id")
        result.free(resultId)

        self:updateState(warId, 4)

        broadcastMessage(guild1:getName() .. " has signed an armstice declaration on a war with " .. guild2:getName() .. ".", MESSAGE_EVENT_ADVANCE)
        return true
    end
    return false
end

playerdeath

Lua:
    local warId = guildwars:isInWar(killer, player)

    if warId ~= 0 then
        guildwars:processKill(warId, killer, player)
    end

I hope you can help me, thank you all!.
 
Last edited:
Lua:
data/lib/core/guildwars.lua:49: attempt to concatenate local 'warId' (a boolean value)

we need see guildwars.lua
Lua:
--
-- Created by IntelliJ IDEA.
-- User: eubrunomiguel
-- Date: 2020-05-23
-- Time: 08:37
-- To change this template use File | Settings | File Templates.
--

guildwars = {}

guildwars.__index = guildwars

function guildwars:isInWar(player1, player2)
    if not player1:getGuild() or not player2:getGuild() then
        return 0
    end

    if player1:getGuild():getId() == 0 or player2:getGuild():getId() == 0 then
        return 0
    end

    if player1:getGuild():getId() == player2:getGuild():getId() then
        return 0
    end

    return isInWar(player1:getId(), player2:getId())
end

function guildwars:processKill(warId, killer, player)
    local fragLimit = self:getFragLimit(warId)

    local killerFrags = self:getKills(warId, killer:getGuild():getId()) + 1
    local deadFrags = self:getKills(warId, player:getGuild():getId())

    local killerMsg = "Opponent " .. player:getName() .. " of the " .. player:getGuild():getName() .. " was killed by " .. killer:getName() .. ". The new score is " .. killerFrags .. ":" .. deadFrags .. " frags (limit " .. fragLimit .. ")."
    killer:guildBroadcast(killerMsg)

    local deadMsg = "Guild member " .. player:getName() .. " was killed by " .. killer:getName() .. " of the " .. killer:getGuild():getName() .. ". The new score is " .. deadFrags .. ":" .. killerFrags .. " frags (limit " .. fragLimit .. ")."
    player:guildBroadcast(deadMsg)

    self:insertKill(warId, killer, player)

    if killerFrags >= fragLimit then
        self:endWar(warId, killer, player, killerFrags)
    end
end

function guildwars:getFragLimit(warId)
    local resultId = db.storeQuery("SELECT `frag_limit` FROM `guild_wars` WHERE `id` = " .. warId)
    if resultId ~= false then
        local frag_limit = result.getDataInt(resultId, "frag_limit")
        result.free(resultId)
        return frag_limit
    end
    return 0
end

function guildwars:getKills(warId, guildId)
    local resultId = db.storeQuery("SELECT COUNT(*) as frags FROM `guildwar_kills` WHERE `warid` = " .. warId .. " and `killerguild` = " .. guildId)
    if resultId ~= false then
        local frags = result.getDataInt(resultId, "frags")
        result.free(resultId)
        return frags
    end
    return 0
end

function guildwars:insertKill(warId, killer, target)
    db.asyncQuery("INSERT INTO `guildwar_kills` (`killer`, `target`, `killerguild`, `targetguild`, `warid`) VALUES (" .. db.escapeString(killer:getName()) .. ", " .. db.escapeString(target:getName()) .. ", " .. killer:getGuild():getId() .. ", " .. target:getGuild():getId() .. ", " .. warId .. ")")
end

function guildwars:endWar(warId, killer, player, frags)
    local winGuildInternalMessage = "Congratulations! You have won the war against " .. player:getGuild():getName() .. " with " .. frags .. " frags."
    killer:guildBroadcast(winGuildInternalMessage)

    local loseGuildInternalMessage = "You have lost the war against " .. killer:getGuild():getName() .. ". They have reached the limit of " .. frags .. " frags."
    player:guildBroadcast(loseGuildInternalMessage)

    broadcastMessage(killer:getGuild():getName() .. " have won the war against " .. player:getGuild():getName() .. " with " .. frags .. " frags.", MESSAGE_EVENT_ADVANCE)

    self:updateState(warId, 5)

    self:setWarEmblem(killer:getGuild(), player:getGuild(), 0)
end

function guildwars:setWarEmblem(guild1, guild2, emblem)
    local guild1Members = guild1:getMembersOnline()
    for i = #guild1Members, 1, -1 do
        guild1Members[i]:setSkull(emblem)
    end

    local guild2Members = guild2:getMembersOnline()
    for i = #guild2Members, 1, -1 do
        guild2Members[i]:setSkull(emblem)
    end
end

function guildwars:updateState(warId, status)
    db.asyncQuery("UPDATE `guild_wars` SET `status` = " .. status .. " WHERE `id` = " .. warId)
end

function guildwars:getPendingInvitation(guild1, guild2)
    local resultId = db.storeQuery("SELECT `id` FROM `guild_wars` WHERE `guild1` = " .. guild1 .. " AND `guild2` = " .. guild2 .. " AND `status` = 0")

    if resultId then
        local id = result.getDataInt(resultId, "id")
        result.free(resultId)

        return id
    end

    return 0
end

function guildwars:startWar(warId, guild1, guild2)
    self:updateState(warId, 1)

    self:setWarEmblem(guild1, guild2, 2)

    broadcastMessage(guild1:getName() .. " has accepted " .. guild2:getName() .. " invitation to war.", MESSAGE_EVENT_ADVANCE)
end

function guildwars:rejectWar(warId, guild1, guild2)
    self:updateState(warId, 2)
    broadcastMessage(guild1:getName() .. " has rejected " .. guild2:getName() .. " invitation to war.", MESSAGE_EVENT_ADVANCE)
end

function guildwars:cancelWar(warId, guild1, guild2)
    self:updateState(warId, 3)
    broadcastMessage(guild1:getName() .. " has canceled invitation to a war with " .. guild2:getName() .. ".", MESSAGE_EVENT_ADVANCE)
end

function guildwars:invite(guild1, guild2, frags)
    local str = ""
    local tmpQuery = db.storeQuery("SELECT `guild1`, `status` FROM `guild_wars` WHERE `guild1` IN (" .. guild1:getId() .. "," .. guild2:getId() .. ") AND `guild2` IN (" .. guild2:getId() .. "," .. guild1:getId() .. ") AND `status` IN (0, 1)")
    if tmpQuery then
        if result.getDataInt(tmpQuery, "status") == 0 then
            if result.getDataInt(tmpQuery, "guild1") == guild1:getId() then
                str = "You have already invited " .. guild2:getName() .. " to war."
            else
                str = guild2:getName() .. " have already invited you to war."
            end
        else
            str = "You are already on a war with " .. guild2:getName() .. "."
        end

        result.free(tmpQuery)
    end

    if str ~= "" then
        player:sendCancelMessage(str)
        return true
    end

    frags = math.max(10, math.min(1000, frags))

    db.asyncQuery("INSERT INTO `guild_wars` (`guild1`, `guild2`, `frag_limit`) VALUES (" .. guild1:getId() .. ", " .. guild2:getId() .. ", " .. frags .. ");")
    broadcastMessage(guild1:getName() .. " has invited " .. guild2:getName() .. " to war for " .. frags .. " frags.", MESSAGE_EVENT_ADVANCE)
end

function guildwars:acceptRequestToEndWar(guild1, guild2)
    local resultId = db.storeQuery("SELECT `id`, `status` FROM `guild_wars` WHERE `guild1` = " .. guild1:getId() .. " AND `guild2` = " .. guild2:getId() .. " AND `status` IN (1, 4)")
    if resultId then
        local warId = result.getDataInt(resultId, "id")
        local status = result.getDataInt(resultId, "status")
        result.free(resultId)

        self:updateState(warId, 5)

        broadcastMessage(guild1:getName() .. " has " .. (status == 4 and "mend fences" or "ended up a war") .. " with " .. guild2:getName() .. ".", MESSAGE_EVENT_ADVANCE)

        self:setWarEmblem(guild1, guild2, 0)

        return true
    end

    return false
end

function guildwars:requestToEndWar(guild1, guild2)
    local resultId = db.storeQuery("SELECT `id` FROM `guild_wars` WHERE `guild1` = " .. guild1:getId() .. " AND `guild2` = " .. guild2:getId() .. " AND `status` = 1")
    if resultId then
        local warId = result.getDataInt(resultId, "id")
        result.free(resultId)

        self:updateState(warId, 4)

        broadcastMessage(guild1:getName() .. " has signed an armstice declaration on a war with " .. guild2:getName() .. ".", MESSAGE_EVENT_ADVANCE)
        return true
    end
    return false
end


I'm sorry, here it is, thank you very much
 
Lua:
function guildwars:isInWar(player1, player2)
    if not player1:getGuild() or not player2:getGuild() then
        return 0
    end

    if player1:getGuild():getId() == 0 or player2:getGuild():getId() == 0 then
        return 0
    end

    if player1:getGuild():getId() == player2:getGuild():getId() then
        return 0
    end

    return isInWar(player1:getId(), player2:getId())
end
as you can see this function ends with a return calling another function, which is not in your code, i suppose this function return the Id of the war.
you can walk around using a query to find the war id, but i think you may be missing some code depending where you got that from.


edit;
this may fix it for you. haven't tested gl

add function:
Lua:
function getWarId(player_name)
    local player = Player(player_name)
    if not player then
        return 0
    end
    local guild_id = player:getGuild():getId()
    local query = db.storeQuery("SELECT `id` FROM `guild_wars` WHERE `status` = 1 AND (`guild1` = "..guild_id.." OR `guild2` = "..guild_id..") LIMIT 1")
    local war_id = 0
    if(query ~= false) then
        local id = result.getDataInt(query, "id")
        war_id = id
        result.free(query)   
    end
    return tonumber(war_id)
end

edit playerdeath

Lua:
local warId = guildwars:isInWar(killer, player)

if warId ~= 0 then
    local war_id = getWarId(player:getName())
    guildwars:processKill(war_id, killer, player)
end
 
Last edited:
Thanks for the help, everything worked correctly in the guild war, but even without guild war there is an error when a player dies, here it is

1609906935210.png
Post automatically merged:

Lua:
function guildwars:isInWar(player1, player2)
    if not player1:getGuild() or not player2:getGuild() then
        return 0
    end

    if player1:getGuild():getId() == 0 or player2:getGuild():getId() == 0 then
        return 0
    end

    if player1:getGuild():getId() == player2:getGuild():getId() then
        return 0
    end

    return isInWar(player1:getId(), player2:getId())
end
as you can see this function ends with a return calling another function, which is not in your code, i suppose this function return the Id of the war.
you can walk around using a query to find the war id, but i think you may be missing some code depending where you got that from.


edit;
this may fix it for you. haven't tested gl

add function:
Lua:
function getWarId(player_name)
    local player = Player(player_name)
    if not player then
        return 0
    end
    local guild_id = player:getGuild():getId()
    local query = db.storeQuery("SELECT `id` FROM `guild_wars` WHERE `status` = 1 AND (`guild1` = "..guild_id.." OR `guild2` = "..guild_id..") LIMIT 1")
    local war_id = 0
    if(query ~= false) then
        local id = result.getDataInt(query, "id")
        war_id = id
        result.free(query)  
    end
    return tonumber(war_id)
end

edit playerdeath

Lua:
local warId = guildwars:isInWar(killer, player)

if warId ~= 0 then
    local war_id = getWarId(player:getName())
    guildwars:processKill(war_id, killer, player)
end
Thanks for the help, everything worked correctly in the guild war, but even without guild war there is an error when a player dies, here it is

1609906935210.png
 
The way I read it, the first error was here (line 49 of guildwars.lua).
Lua:
local resultId = db.storeQuery("SELECT `frag_limit` FROM `guild_wars` WHERE `id` = " .. warId)

Looks like a data typing issue to me.

Lua said "warId" is boolean, which I guess Lua doesn't want to turn into a string for concatenation to the rest of the string being built for "db.storeQuery()"

Updated:
IIRC I've seen a list of Lua features for a newer release (maybe 5.0, but I'm too lazy to check) saying that they'd added a boolean datatype. In that case, maybe check if your code came from a "pre-boolean" version of Lua. If so, it might have run ok on the older Lua.

In that case, the original code might depend on "warId" working as boolean sometimes, and an identifier at other times, which could easily cause trouble after a boolean dataype was introduced.
 
Last edited:
Back
Top