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

attempt to call global 'getCastleConfig' (a nil value)

thegood

New Member
Joined
Jan 20, 2012
Messages
28
Reaction score
0
I need help with this Castle War script, all works good, but when the event finish, i recive this message:
Broadcasted message: "[Castle War] Castle has been saved by owner.".
And have this error:
[Error - CreatureScript Interface]
[0:25:30.781] data/creaturescripts/scripts/castlekill.lua:eek:nDeath
[0:25:30.784] Description:
[0:25:30.784] data/creaturescripts/scripts/castlekill.lua:2: attempt to call global 'getCastleConfig' (a nil value)
[0:25:30.787] stack traceback:
[0:25:30.787] data/creaturescripts/scripts/castlekill.lua:2: in function <data/creaturescripts/scripts/castlekill.lua:

This is my castlekill.lua:
Lua:
function onDeath(cid, corpse, killer)
    if (getCreatureName(cid) == getCastleConfig("monster")) then
        Castle_endEvent(true, damages)
    end
    -- cleanup
    damages = {0,0,0}
    return true
end

And this is castle lib:

Lua:
CWE_DAMAGES = {0, 0, 0}

CWE_MESSAGE_PREFIX = "[Castle War] "
CWE_MIN_GROUP_TO_START_EVENT = 1
CWE_TIME_1 = 1 * 60 * 1000 -- time from start event to fight
CWE_TIME_2 = 2 * 60 * 1000 -- time from fight to end event
CWE_GUILD_OWN_STORAGE = 17000
CWE_ATTACKERS_STORAGE = 17002
CWE_ENABLED_STORAGE = 17006
CWE_ENDED_STORAGE = 17007
CWE_LEADER_LEVEL = 200
CWE_MEMBERS_NEEDED = 1
CWE_MONSTER = "King"
CWE_MONSTER_SPAWN = {x = 969, y = 850, z = 4}
CWE_START_ATTACKERS =
{
    [1] = {x = 986, y = 988, z = 7},
    [2] = {x = 990, y = 876, z = 7},
    [3] = {x = 988, y = 837, z = 7}
}
CWE_GATES =
{
    [1] = {pos = {x = 956, y = 860, z = 7}, itemid = 9533},
    [2] = {pos = {x = 956, y = 861, z = 7}, itemid = 9533},

    [3] = {pos = {x = 990, y = 844, z = 7}, itemid = 9486},
    [4] = {pos = {x = 991, y = 844, z = 7}, itemid = 9486},

    [5] = {pos = {x = 985, y = 871, z = 7}, itemid = 9485},
    [6] = {pos = {x = 986, y = 871, z = 7}, itemid = 9485},
    [7] = {pos = {x = 987, y = 871, z = 7}, itemid = 9485},

    -- new
    [8] = {pos = {x = 951, y = 890, z = 7}, itemid = 9533},
    [9] = {pos = {x = 998, y = 875, z = 7}, itemid = 9533},
    [10] = {pos = {x = 998, y = 876, z = 7}, itemid = 9533},

    [11] = {pos = {x = 2605, y = 615, z = 7}, itemid = 9485}, 

    [12] = {pos = {x = 2618, y = 619, z = 7}, itemid = 9533},
    [13] = {pos = {x = 2618, y = 620, z = 7}, itemid = 9533},

    [14] = {pos = {x = 985, y = 841, z = 7}, itemid = 9486},
    [15] = {pos = {x = 986, y = 841, z = 7}, itemid = 9486},
    [16] = {pos = {x = 987, y = 841, z = 7}, itemid = 9486},
}

function castle_removeNotKilledKing(cid)
    if(isMonster(cid) and getCreatureName(cid) == CWE_MONSTER) then
        doRemoveCreature(cid)
    end
  
    return true
end

function castle_getGuildPos(guildId)
    local attackers = castle_getAttackers()
    for i, value in ipairs(attackers) do
        if(tonumber(guildId) == tonumber(value)) then
            ret = i
        end
    end
  
    return ret
end

function castle_getAttackers()
    local ret = {}
    local query = string.explode(getStorage(CWE_ATTACKERS_STORAGE), ",")
    for _, value in ipairs(query) do
        if(isNumber(value)) then
            table.insert(ret, value)
        end
    end
  
    return ret
end

function castle_startEvent()
    doSetStorage(CWE_ENABLED_STORAGE, 0)
    doSetStorage(CWE_ENDED_STORAGE, 0)
  
    if(table.maxn(castle_getAttackers()) == 0) then
        doBroadcastMessage(CWE_MESSAGE_PREFIX .. "We have not attackers!", MESSAGE_EVENT_ADVANCE)
        return true
    end
  
    doBroadcastMessage(CWE_MESSAGE_PREFIX .. "Event has been started. Kill " .. CWE_MONSTER .. "!", MESSAGE_EVENT_ADVANCE)
  
    local monster = doSummonCreature(CWE_MONSTER, CWE_MONSTER_SPAWN)
  
    for _, gate in pairs(CWE_GATES) do
        doRemoveItem(getTileItemById(gate.pos, gate.itemid).uid)
    end
  
    addEvent(castle_endEvent, CWE_TIME_2, false)
    addEvent(castle_removeNotKilledKing, CWE_TIME_2, monster)
    return true
end

function castle_endEvent(killed, damages)
    local playersOnline = getPlayersOnline()
    local dmgCount, message, winner = 0, "", 0
  
    if(getStorage(CWE_ENDED_STORAGE) ~= 1) then
        if(killed) then
            for _, value in ipairs(castle_getAttackers()) do
                message = message .. "\n" .. getGuildName(value) .. ": " .. damages[castle_getGuildPos(value)] .. " dmg"
                if(damages[castle_getGuildPos(value)] > dmgCount) then
                    winner = value
                    dmgCount = damages[castle_getGuildPos(value)]
                end
            end
          
            doBroadcastMessage(CWE_MESSAGE_PREFIX .. "\n> Statistics " .. message .. "\nThe winner is: " .. getGuildName(winner), MESSAGE_EVENT_ADVANCE)
          
            local attackers = castle_getAttackers()
            table.insert(attackers, getStorage(CWE_GUILD_OWN_STORAGE))
            for _, pid in ipairs(playersOnline) do
                if((isInArray(attackers, getPlayerGuildId(pid)) or getStorage(CWE_GUILD_OWN_STORAGE) == getPlayerGuildId(pid)) and not(tonumber(getPlayerGuildId(pid)) == tonumber(winner))) then
                    doRemoveCondition(pid, CONDITION_INFIGHT)
                    doTeleportThing(pid, getTownTemplePosition(getPlayerTown(pid)))
                end
            end
          
            doSetStorage(CWE_GUILD_OWN_STORAGE, winner)
        else
            doBroadcastMessage(CWE_MESSAGE_PREFIX .. "Castle has been saved by owner.", MESSAGE_EVENT_ADVANCE)
        end
      
        doSetStorage(CWE_ENDED_STORAGE, 1)
    end
  
    doSetStorage(CWE_ATTACKERS_STORAGE, ",")
    return true
end

function castle_getGuildMembers(guildId)
    local members = {}
    local playersOnline = getPlayersOnline()
    for _, pid in ipairs(playersOnline) do
        if(getPlayerGuildId(pid) == guildId) then
            table.insert(members, pid)
        end
    end
  
    return members
end

I use tfs 0.4, tibia 8.6
Post automatically merged:

I need help with this Castle War script, all works good, but when the event finish, i recive this message:

And have this error:


This is my castlekill.lua:
Lua:
function onDeath(cid, corpse, killer)
    if (getCreatureName(cid) == getCastleConfig("monster")) then
        Castle_endEvent(true, damages)
    end
    -- cleanup
    damages = {0,0,0}
    return true
end

And this is castle lib:

Lua:
CWE_DAMAGES = {0, 0, 0}

CWE_MESSAGE_PREFIX = "[Castle War] "
CWE_MIN_GROUP_TO_START_EVENT = 1
CWE_TIME_1 = 1 * 60 * 1000 -- time from start event to fight
CWE_TIME_2 = 2 * 60 * 1000 -- time from fight to end event
CWE_GUILD_OWN_STORAGE = 17000
CWE_ATTACKERS_STORAGE = 17002
CWE_ENABLED_STORAGE = 17006
CWE_ENDED_STORAGE = 17007
CWE_LEADER_LEVEL = 200
CWE_MEMBERS_NEEDED = 1
CWE_MONSTER = "King"
CWE_MONSTER_SPAWN = {x = 969, y = 850, z = 4}
CWE_START_ATTACKERS =
{
    [1] = {x = 986, y = 988, z = 7},
    [2] = {x = 990, y = 876, z = 7},
    [3] = {x = 988, y = 837, z = 7}
}
CWE_GATES =
{
    [1] = {pos = {x = 956, y = 860, z = 7}, itemid = 9533},
    [2] = {pos = {x = 956, y = 861, z = 7}, itemid = 9533},

    [3] = {pos = {x = 990, y = 844, z = 7}, itemid = 9486},
    [4] = {pos = {x = 991, y = 844, z = 7}, itemid = 9486},

    [5] = {pos = {x = 985, y = 871, z = 7}, itemid = 9485},
    [6] = {pos = {x = 986, y = 871, z = 7}, itemid = 9485},
    [7] = {pos = {x = 987, y = 871, z = 7}, itemid = 9485},

    -- new
    [8] = {pos = {x = 951, y = 890, z = 7}, itemid = 9533},
    [9] = {pos = {x = 998, y = 875, z = 7}, itemid = 9533},
    [10] = {pos = {x = 998, y = 876, z = 7}, itemid = 9533},

    [11] = {pos = {x = 2605, y = 615, z = 7}, itemid = 9485},

    [12] = {pos = {x = 2618, y = 619, z = 7}, itemid = 9533},
    [13] = {pos = {x = 2618, y = 620, z = 7}, itemid = 9533},

    [14] = {pos = {x = 985, y = 841, z = 7}, itemid = 9486},
    [15] = {pos = {x = 986, y = 841, z = 7}, itemid = 9486},
    [16] = {pos = {x = 987, y = 841, z = 7}, itemid = 9486},
}

function castle_removeNotKilledKing(cid)
    if(isMonster(cid) and getCreatureName(cid) == CWE_MONSTER) then
        doRemoveCreature(cid)
    end
 
    return true
end

function castle_getGuildPos(guildId)
    local attackers = castle_getAttackers()
    for i, value in ipairs(attackers) do
        if(tonumber(guildId) == tonumber(value)) then
            ret = i
        end
    end
 
    return ret
end

function castle_getAttackers()
    local ret = {}
    local query = string.explode(getStorage(CWE_ATTACKERS_STORAGE), ",")
    for _, value in ipairs(query) do
        if(isNumber(value)) then
            table.insert(ret, value)
        end
    end
 
    return ret
end

function castle_startEvent()
    doSetStorage(CWE_ENABLED_STORAGE, 0)
    doSetStorage(CWE_ENDED_STORAGE, 0)
 
    if(table.maxn(castle_getAttackers()) == 0) then
        doBroadcastMessage(CWE_MESSAGE_PREFIX .. "We have not attackers!", MESSAGE_EVENT_ADVANCE)
        return true
    end
 
    doBroadcastMessage(CWE_MESSAGE_PREFIX .. "Event has been started. Kill " .. CWE_MONSTER .. "!", MESSAGE_EVENT_ADVANCE)
 
    local monster = doSummonCreature(CWE_MONSTER, CWE_MONSTER_SPAWN)
 
    for _, gate in pairs(CWE_GATES) do
        doRemoveItem(getTileItemById(gate.pos, gate.itemid).uid)
    end
 
    addEvent(castle_endEvent, CWE_TIME_2, false)
    addEvent(castle_removeNotKilledKing, CWE_TIME_2, monster)
    return true
end

function castle_endEvent(killed, damages)
    local playersOnline = getPlayersOnline()
    local dmgCount, message, winner = 0, "", 0
 
    if(getStorage(CWE_ENDED_STORAGE) ~= 1) then
        if(killed) then
            for _, value in ipairs(castle_getAttackers()) do
                message = message .. "\n" .. getGuildName(value) .. ": " .. damages[castle_getGuildPos(value)] .. " dmg"
                if(damages[castle_getGuildPos(value)] > dmgCount) then
                    winner = value
                    dmgCount = damages[castle_getGuildPos(value)]
                end
            end
         
            doBroadcastMessage(CWE_MESSAGE_PREFIX .. "\n> Statistics " .. message .. "\nThe winner is: " .. getGuildName(winner), MESSAGE_EVENT_ADVANCE)
         
            local attackers = castle_getAttackers()
            table.insert(attackers, getStorage(CWE_GUILD_OWN_STORAGE))
            for _, pid in ipairs(playersOnline) do
                if((isInArray(attackers, getPlayerGuildId(pid)) or getStorage(CWE_GUILD_OWN_STORAGE) == getPlayerGuildId(pid)) and not(tonumber(getPlayerGuildId(pid)) == tonumber(winner))) then
                    doRemoveCondition(pid, CONDITION_INFIGHT)
                    doTeleportThing(pid, getTownTemplePosition(getPlayerTown(pid)))
                end
            end
         
            doSetStorage(CWE_GUILD_OWN_STORAGE, winner)
        else
            doBroadcastMessage(CWE_MESSAGE_PREFIX .. "Castle has been saved by owner.", MESSAGE_EVENT_ADVANCE)
        end
     
        doSetStorage(CWE_ENDED_STORAGE, 1)
    end
 
    doSetStorage(CWE_ATTACKERS_STORAGE, ",")
    return true
end

function castle_getGuildMembers(guildId)
    local members = {}
    local playersOnline = getPlayersOnline()
    for _, pid in ipairs(playersOnline) do
        if(getPlayerGuildId(pid) == guildId) then
            table.insert(members, pid)
        end
    end
 
    return members
end

I use tfs 0.4, tibia 8.6
OK SOLVED, I'm using a bad castlekill.lua, I look it beeter and and changue it and now I don't have the error, but when event end all times send this msg:
Broadcasted message: "[Castle War] Castle has been saved by owner.".

This is my new castlekill.lua:
Lua:
function onDeath(cid, corpse, killer)
    if(getCreatureName(cid) == CWE_MONSTER) then
        castle_endEvent(true, CWE_DAMAGES)
    end
    
    CWE_DAMAGES = {0, 0, 0}
    return true
end
 
Last edited:
Top