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

TFS 0.X [TFS 0.4 - LUA] Monster with rounds

elnelson

Lunaria World Dev
Joined
Jun 20, 2009
Messages
579
Solutions
2
Reaction score
58
Location
México
Good morning, otlanders.

I have this script that is supposed to summon X creatures and wont let summon more until you defeat all the creatures in the room, and, when u kill all the creatures, if you use the lever again, it will summon the second round of creatures. But, it does not advance to round 2, it remains in round 1 even if i complete te round.

So basically, im trying to fix the rounds issue so it can advance to the second or more round of creatures.

Here is the script for TFS 0.4 rev 3774


Lua:
    local c = {
        tp = {x = 1109, y = 1172, z = 9}, -- Where player will be teleported on use.
        text = {
                pos = {x = 1109, y = 1172, z = 9}, --position for animated text
                say = "Prepare for round "
        },
        area = {
            from = {x = 1062, y = 1097, z = 9}, -- the first north-west tile pos
            to = { x = 1139, y = 1177, z = 9} -- the last south-east tile pos
        },
        monsterSpawnPoints = {
            [1] = {x = 1067, y = 1111, z = 9}, -- spawn point 1
            [2] = {x = 1068, y = 1150, z = 9}, -- spawn point 2
            [3] = {x = 1125, y = 1150, z = 9}, -- spawn point 3
            [4] = {x = 1111, y = 1116, z = 9} -- spawn point 4
        },
        rounds = {
            [1] = { -- round 1
                    [1] = { name = "warlock" }, -- will spawn at spawn point 1
                    [2] = { name = "warlock" }, -- will spawn at spawn point 2
                    [3] = { name = "warlock" }, -- will spawn at spawn point 3
                    [4] = { name = "demon" } -- will spawn at spawn point 4
                },
            [2] = { -- round 2
                    [1] = { name = "infernalist" },
                    [2] = { name = "infernalist" },
                    [3] = { name = "infernalist" },
                    [4] = { name = "infernalist" }
                }
        },
        textColor = COLOR_TEAL,
        creatures = {},
        storage = 1540, -- storage value
        SpawnTime = 5 -- how much time should you wait to spawn the creatures in seconds
    }
    -- since we only have 2 rounds setup this will be the max
    local maxRounds = #c.rounds

    function spawnCreatures(c, round)
        for point, creature in ipairs(c.rounds[round]) do
            -- summon the creatures and store the cid of each one summoned
            c.creatures[point] = doSummonCreature(creature.name, c.monsterSpawnPoints[point])
        end
    end

    function countCreatures(c)
        local count = 0
        -- incase we haven't summoned any monsters yet
        if #c.creatures < 1 then
            return count, true
        end
        for i in ipairs(c.creatures) do
            -- make sure all the creatures are monsters
            if isMonster(c.creatures[i]) then
                -- and if they are within range or the area, if they are count them
                if isInRange(getCreaturePosition(c.creatures[i]), c.area.from, c.area.to) then
                    count = count + 1
                end
            else
                -- what is the value of c.creatures[i] in the console
                -- print(c.creatures[i])
            end
        end
        -- return amount of creatures
        return count, (count == 0)
    end
    function doAnimatedAllText(pos, text, color)
        local textTable = {}
        text:gsub("[0-9a-zA-Z]+", function(str) table.insert(textTable, str) end)
        for i in ipairs(textTable) do
            addEvent(doSendAnimatedText, i * 1000, pos, textTable[i], color)
        end
    end

    function initiate(cid, c, round)
        doTeleportThing(cid, c.tp)
        doAnimatedAllText(c.text.pos, c.text.say..round, c.textColor)
        addEvent(spawnCreatures, c.SpawnTime * 1000, c, round)
    end

    function onUse(cid, item, frompos, item2, topos)
        doPlayerSetNoMove(cid,0)
        addEvent(doPlayerSetNoMove,cid,5000,1)
        doSendMagicEffect({x = 1109, y = 1172, z = 9},10)     
        local round = ( getPlayerStorageValue(cid, c.storage) <= 0 ) and 1 or getPlayerStorageValue(cid, c.storage)
        local round = 1 -- i guess this is the issue
        if(item.itemid == 1946 or item.itemid == 1945) then
            doTransformItem(item.uid, (item.itemid == 1946) and item.itemid - 1 or item.itemid + 1) -- transform the switch
            local creatureCount, summonCreature  = countCreatures(c)
            if summonCreature and round ~= maxRounds then
                initiate(cid, c, round)
                setPlayerStorageValue(cid, c.storage, round + 1) -- or maybe the issue is here
            else
                doTransformItem(item.uid, (item.itemid == 1945) and item.itemid + 1 or item.itemid - 1) -- transform the switch back
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Sorry, "..getPlayerName(cid).." but there are still "..creatureCount.." creature(s) left to kill.") --this is working
            end
        end
        return true
    end

I hope you guys could help me i've been trying for many hours and cant get the solution :(
 
Solution
first off, all your functions should have local in front of them, so they don't interfere with other scripts.

second, there doesn't appear to be a reset switch built into this lever..
So it's possible your storage value is too high after testing with your character, due to how the value is checked..
"if summonCreature and round ~= maxRounds then"

There's multiple issues with the above value checking.. but let's check other stuff first.

Removing line 86 is correct, since it's not required.

Alright, I'm fairly certain the issue is something dealing with your storage value thing, and you are just getting an incorrect error message.

try this

Lua:
local c = {
    tp = {x = 1109, y = 1172, z = 9}, -- Where player will be teleported on...
first off, all your functions should have local in front of them, so they don't interfere with other scripts.

second, there doesn't appear to be a reset switch built into this lever..
So it's possible your storage value is too high after testing with your character, due to how the value is checked..
"if summonCreature and round ~= maxRounds then"

There's multiple issues with the above value checking.. but let's check other stuff first.

Removing line 86 is correct, since it's not required.

Alright, I'm fairly certain the issue is something dealing with your storage value thing, and you are just getting an incorrect error message.

try this

Lua:
local c = {
    tp = {x = 1109, y = 1172, z = 9}, -- Where player will be teleported on use.
    text = {
            pos = {x = 1109, y = 1172, z = 9}, --position for animated text
            say = "Prepare for round "
    },
    area = {
        from = {x = 1062, y = 1097, z = 9}, -- the first north-west tile pos
        to = { x = 1139, y = 1177, z = 9} -- the last south-east tile pos
    },
    monsterSpawnPoints = {
        [1] = {x = 1067, y = 1111, z = 9}, -- spawn point 1
        [2] = {x = 1068, y = 1150, z = 9}, -- spawn point 2
        [3] = {x = 1125, y = 1150, z = 9}, -- spawn point 3
        [4] = {x = 1111, y = 1116, z = 9} -- spawn point 4
    },
    rounds = {
        [1] = { -- round 1
                [1] = { name = "warlock" }, -- will spawn at spawn point 1
                [2] = { name = "warlock" }, -- will spawn at spawn point 2
                [3] = { name = "warlock" }, -- will spawn at spawn point 3
                [4] = { name = "demon" } -- will spawn at spawn point 4
            },
        [2] = { -- round 2
                [1] = { name = "infernalist" },
                [2] = { name = "infernalist" },
                [3] = { name = "infernalist" },
                [4] = { name = "infernalist" }
            }
    },
    textColor = COLOR_TEAL,
    creatures = {},
    storage = 1540, -- storage value
    SpawnTime = 5 -- how much time should you wait to spawn the creatures in seconds
}
-- since we only have 2 rounds setup this will be the max
local maxRounds = #c.rounds

local function spawnCreatures(c, round)
    for point, creature in ipairs(c.rounds[round]) do
        -- summon the creatures and store the cid of each one summoned
        c.creatures[point] = doSummonCreature(creature.name, c.monsterSpawnPoints[point])
    end
end

local function countCreatures(c)
    local count = 0
    -- incase we haven't summoned any monsters yet
    if #c.creatures < 1 then
        return count, true
    end
    for i in ipairs(c.creatures) do
        -- make sure all the creatures are monsters
        if isMonster(c.creatures[i]) then
            -- and if they are within range or the area, if they are count them
            if isInRange(getCreaturePosition(c.creatures[i]), c.area.from, c.area.to) then
                count = count + 1
            end
        else
            -- what is the value of c.creatures[i] in the console
            -- print(c.creatures[i])
        end
    end
    -- return amount of creatures
    return count, (count == 0)
end
local function doAnimatedAllText(pos, text, color)
    local textTable = {}
    text:gsub("[0-9a-zA-Z]+", function(str) table.insert(textTable, str) end)
    for i in ipairs(textTable) do
        addEvent(doSendAnimatedText, i * 1000, pos, textTable[i], color)
    end
end

local function initiate(cid, c, round)
    doTeleportThing(cid, c.tp)
    doAnimatedAllText(c.text.pos, c.text.say..round, c.textColor)
    addEvent(spawnCreatures, c.SpawnTime * 1000, c, round)
end

function onUse(cid, item, frompos, item2, topos)
    doPlayerSetNoMove(cid,0)
    addEvent(doPlayerSetNoMove,cid,5000,1)
    doSendMagicEffect({x = 1109, y = 1172, z = 9},10)    
    local round = ( getPlayerStorageValue(cid, c.storage) <= 0 ) and 1 or getPlayerStorageValue(cid, c.storage)
    if(item.itemid == 1946 or item.itemid == 1945) then
        doTransformItem(item.uid, (item.itemid == 1946) and item.itemid - 1 or item.itemid + 1) -- transform the switch
        local creatureCount = countCreatures(c)
        if creatureCount == 0 then
            if round <= maxRounds then
                initiate(cid, c, round)
                setPlayerStorageValue(cid, c.storage, round + 1) -- or maybe the issue is here
            else
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Sorry, you've reached the final wave of monsters. No other waves exist.")
            end
        else
            doTransformItem(item.uid, (item.itemid == 1945) and item.itemid + 1 or item.itemid - 1) -- transform the switch back
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Sorry, "..getPlayerName(cid).." but there are still "..creatureCount.." creature(s) left to kill.") --this is working
        end
    end
    return true
end
 
Last edited:
Solution
first off, all your functions should have local in front of them, so they don't interfere with other scripts.

second, there doesn't appear to be a reset switch built into this lever..
So it's possible your storage value is too high after testing with your character, due to how the value is checked..
"if summonCreature and round ~= maxRounds then"

There's multiple issues with the above value checking.. but let's check other stuff first.

Removing line 86 is correct, since it's not required.

Alright, I'm fairly certain the issue is something dealing with your storage value thing, and you are just getting an incorrect error message.

try this

Lua:
local c = {
    tp = {x = 1109, y = 1172, z = 9}, -- Where player will be teleported on use.
    text = {
            pos = {x = 1109, y = 1172, z = 9}, --position for animated text
            say = "Prepare for round "
    },
    area = {
        from = {x = 1062, y = 1097, z = 9}, -- the first north-west tile pos
        to = { x = 1139, y = 1177, z = 9} -- the last south-east tile pos
    },
    monsterSpawnPoints = {
        [1] = {x = 1067, y = 1111, z = 9}, -- spawn point 1
        [2] = {x = 1068, y = 1150, z = 9}, -- spawn point 2
        [3] = {x = 1125, y = 1150, z = 9}, -- spawn point 3
        [4] = {x = 1111, y = 1116, z = 9} -- spawn point 4
    },
    rounds = {
        [1] = { -- round 1
                [1] = { name = "warlock" }, -- will spawn at spawn point 1
                [2] = { name = "warlock" }, -- will spawn at spawn point 2
                [3] = { name = "warlock" }, -- will spawn at spawn point 3
                [4] = { name = "demon" } -- will spawn at spawn point 4
            },
        [2] = { -- round 2
                [1] = { name = "infernalist" },
                [2] = { name = "infernalist" },
                [3] = { name = "infernalist" },
                [4] = { name = "infernalist" }
            }
    },
    textColor = COLOR_TEAL,
    creatures = {},
    storage = 1540, -- storage value
    SpawnTime = 5 -- how much time should you wait to spawn the creatures in seconds
}
-- since we only have 2 rounds setup this will be the max
local maxRounds = #c.rounds

local function spawnCreatures(c, round)
    for point, creature in ipairs(c.rounds[round]) do
        -- summon the creatures and store the cid of each one summoned
        c.creatures[point] = doSummonCreature(creature.name, c.monsterSpawnPoints[point])
    end
end

local function countCreatures(c)
    local count = 0
    -- incase we haven't summoned any monsters yet
    if #c.creatures < 1 then
        return count, true
    end
    for i in ipairs(c.creatures) do
        -- make sure all the creatures are monsters
        if isMonster(c.creatures[i]) then
            -- and if they are within range or the area, if they are count them
            if isInRange(getCreaturePosition(c.creatures[i]), c.area.from, c.area.to) then
                count = count + 1
            end
        else
            -- what is the value of c.creatures[i] in the console
            -- print(c.creatures[i])
        end
    end
    -- return amount of creatures
    return count, (count == 0)
end
local function doAnimatedAllText(pos, text, color)
    local textTable = {}
    text:gsub("[0-9a-zA-Z]+", function(str) table.insert(textTable, str) end)
    for i in ipairs(textTable) do
        addEvent(doSendAnimatedText, i * 1000, pos, textTable[i], color)
    end
end

local function initiate(cid, c, round)
    doTeleportThing(cid, c.tp)
    doAnimatedAllText(c.text.pos, c.text.say..round, c.textColor)
    addEvent(spawnCreatures, c.SpawnTime * 1000, c, round)
end

function onUse(cid, item, frompos, item2, topos)
    doPlayerSetNoMove(cid,0)
    addEvent(doPlayerSetNoMove,cid,5000,1)
    doSendMagicEffect({x = 1109, y = 1172, z = 9},10)    
    local round = ( getPlayerStorageValue(cid, c.storage) <= 0 ) and 1 or getPlayerStorageValue(cid, c.storage)
    if(item.itemid == 1946 or item.itemid == 1945) then
        doTransformItem(item.uid, (item.itemid == 1946) and item.itemid - 1 or item.itemid + 1) -- transform the switch
        local creatureCount, summonCreature = countCreatures(c)
        if summonCreature == 0 then
            if round <= maxRounds then
                initiate(cid, c, round)
                setPlayerStorageValue(cid, c.storage, round + 1) -- or maybe the issue is here
            else
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Sorry, you've reached the final wave of monsters. No other waves exist.")
            end
        else
            doTransformItem(item.uid, (item.itemid == 1945) and item.itemid + 1 or item.itemid - 1) -- transform the switch back
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Sorry, "..getPlayerName(cid).." but there are still "..creatureCount.." creature(s) left to kill.") --this is working
        end
    end
    return true
end
still saying "Sorry, Nelson but there are still 0 creature(s) left to kill." and no creature is spawning
 
Back
Top