• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua Help needed with custom quest script!

  • Thread starter Thread starter LordVissie
  • Start date Start date
L

LordVissie

Guest
Hey guys, I just maked my 3rd own script (I'm pretty proud of that :D:p)

This is the script
Code:
local config = {
tp = {x=1035, y=895, z=9}
}
    function onUse(cid, item, frompos, item2, topos)
    doTeleportThing(cid, config.tp)
    doSummonCreature("morgaroth", {x=1032, y=892, z=9})
    doSummonCreature("ghazbaran", {x=1037, y=897, z=9})
    doSummonCreature("apocalypse", {x=1038, y=892, z=9})
    doSummonCreature("zugurosh", {x=1032, y=898, z=9})
return true
end

So It TPS me over here. https://gyazo.com/ece9d89da37f21caf2f8efb9ecee0b4b

But I want to add some delay between spawning and pulling the lever. Like a 1/2 second delay and when all creatures are dead there's going to come a round 2 and round 3. Then there will spawn a TP wich teleports you to a spot at the chest room. This is kinda my idea.

Something like that.

Ofc. There should be a much easier/better script then this and feel free to tell me. I don't know if storage was needed here but I don't how to make that either so I don't know :p

So actually I would like to know is:

  1. How to add delay between the spawning creatures.
  2. How to check if the creatures are dead so a next round can begin.
  3. How to spawn a TP with coordinates.
I think this was it.

Please don't make the script or make the script with a lot of notations with -- so I can understand what you are doing cuz I'm trying to learn scripting. I would really appreciate that ;);)

Kind Regards,

LordVissie

~~~ Edit ~~~

Using 0.3.6
 
Last edited by a moderator:
Thanks, I'm testing it out atm :)

btw "addEvent(functionname, 1000, parameters)" is 1 second right?

And I've no idea how getSpectators work. I don't understand it but does it check if monsters are living or something?
 
Last edited by a moderator:
Okay atm I have this:

Code:
local config = {
tp = {x=1035, y=895, z=9} -- Change XXXX to the location you want.
}
    function onUse(cid, item, frompos, item2, topos)
    doTeleportThing(cid, config.tp)
    doSummonCreature("morgaroth", {x=1032, y=892, z=9})
    doSummonCreature("ghazbaran", {x=1037, y=897, z=9})
    doSummonCreature("apocalypse", {x=1038, y=892, z=9})
    doSummonCreature("zugurosh", {x=1032, y=898, z=9})

-- Round 2
local monster = "apocalypse"
local area = {
frompos = {x=1031,y=891,z=9}, -- the first north-west tile pos
topos = {x=1039,y=898,z=9} -- the last south-east tile pos
}
addEvent(onKill, 1500, cid)

function onKill(cid,target,lastHit)
if isMonster(target) then -- checks if killed thing is monster
if isInRange(getThingPos(target) , area.frompos, area.topos) then -- check for area killed in
if string.lower(getCreatureName(target)) == string.lower(monster) then -- check for monster name
    doSendAnimatedText({x=1035, y=895, z=9}, "Prepare for round 2!", 2)
    doSummonCreature("morgaroth", {x=1032, y=892, z=9})
    doSummonCreature("ghazbaran", {x=1037, y=897, z=9})
    doSummonCreature("cobra", {x=1038, y=892, z=9})
    doSummonCreature("cobra", {x=1032, y=898, z=9})
    return true
end
end
end
return true
end
end

But it doesn't go to the next round on line 17 "addEvent(onKill, 1500, cid)" it gives an error:
Code:
 [Error - Action Interface]
data/actions/scripts/Ultimate Quest.lua:onUse
Description:
(luaAddEvent) Callback parameter should be a function.

I'm trying to fix it but It doesn't really work '_'. Maybe I'm fcked up the whole script but I'm just it gives no other errors then that one.

Anyone an idea?
 
You can't mix actions (function onUse) and creaturescripts (function onKill) like this :p
Can you explain step by step how it's supposed to work?
Oh, okay :p

So how it supposed to be going is: You click a lever you'll get teleported and round 1 starts. I got so far and then if every monster is dead round 2 starts (and it says: Prepare for round 2 and then after 1/2 seconds: Round 2 begins! and then the monsters spawn same as round 3. After round 3 it's supposed to say: Congratulations, You've finished this quest then a Teleport will spawn and that will lead you to a quest room with the reward.

This is what I want to make :p
 
Well not too sure how onKill executes but you could setup your onUse script like this
Code:
    local c = {
        tp = {x = 1035, y = 895, z = 9}, -- Change XXXX to the location you want.
        text = {
                pos = {x=1035, y=895, z=9},
                say = "Prepare for round "
        }
        area = {
            from = {x=1031,y=891,z=9}, -- the first north-west tile pos
            to = {x=1039,y=898,z=9} -- the last south-east tile pos
        }
        monsterSpawnPoints = {
            [1] = {x=1032, y=892, z=9}, -- spawn point 1
            [2] = {x=1037, y=897, z=9}, -- spawn point 1
            [3] = {x=1038, y=892, z=9}, -- spawn point 1
            [4] = {x=1032, y=898, z=9} -- spawn point 1
        },
        rounds = {
            [1] = { -- round 1
                    [1] = { name = "morgaroth" }, -- will spawn at spawn point 1
                    [2] = { name = "ghazbaran" }, -- will spawn at spawn point 2
                    [3] = { name = "apocalypse" }, -- will spawn at spawn point 3
                    [4] = { name = "zugurosh" } -- will spawn at spawn point 4
                },
            [2] = { -- round 2
                    [1] = { name = "morgaroth" },
                    [2] = { name = "ghazbaran" },
                    [3] = { name = "cobra" },
                    [4] = { name = "cobra" }
                },
        },
        textColor = 2
    }

    function spawnCreatures(c, round)
        for point, creature in ipairs(c.rounds[round]) do
            doSummonCreature(creature.name, c.monsterSpawnPoints[point])
        end
    end

    function onUse(cid, item, frompos, item2, topos)
        local round = 1
        doTeleportThing(cid, c.tp)
        doSendAnimatedText(c.text.pos, c.text.say..round, c.textColor)
        spawnCreatures(c, round)
        return true
    end

I just had a thought instead of using onKill especially since I am not sure how to implement it with a switch, why not use a storage value?
This way the you can allow the player to control the rounds, I'll write up an example for you soon :)

I can't test this stuff but maybe it will work :p (crosses fingers) :)
Code:
    --[[
        You should make the area where the creatures spawn a no log out zone
    ]]

    local c = {
        tp = { x = 1035, y = 895, z = 9 }, -- Change XXXX to the location you want.
        text = {
                pos = { x = 1035, y = 895, z = 9 },
                say = "Prepare for round "
        },
        area = {
            from = { x = 1031, y = 891,z = 9 }, -- the first north-west tile pos
            to = { x = 1039, y = 898, z = 9 } -- the last south-east tile pos
        },
        monsterSpawnPoints = {
            [1] = { x = 1032, y = 892, z = 9 }, -- spawn point 1
            [2] = { x = 1037, y = 897, z = 9 }, -- spawn point 1
            [3] = { x = 1038, y = 892, z = 9 }, -- spawn point 1
            [4] = { x = 1032, y = 898, z = 9 } -- spawn point 1
        },
        rounds = {
            [1] = { -- round 1
                    [1] = { name = "morgaroth" }, -- will spawn at spawn point 1
                    [2] = { name = "ghazbaran" }, -- will spawn at spawn point 2
                    [3] = { name = "apocalypse" }, -- will spawn at spawn point 3
                    [4] = { name = "zugurosh" } -- will spawn at spawn point 4
                },
            [2] = { -- round 2
                    [1] = { name = "morgaroth" },
                    [2] = { name = "ghazbaran" },
                    [3] = { name = "cobra" },
                    [4] = { name = "cobra" }
                }
        },
        textColor = 2,
        creatures = {},
        storage = 10000 -- change this to an unused storage value
    }
    -- 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
            end
        end
        -- return amount of creatures
        return count, (count == 0)
    end

    function initiate(cid, c, round)
        spawnCreatures(c, round)
        doTeleportThing(cid, c.tp)
        doSendAnimatedText(c.text.pos, c.text.say..round, c.textColor)
    end

    function onUse(cid, item, frompos, item2, topos)
        local round = ( getPlayerStorageValue(cid, c.storage) < 1 ) and 1 or getPlayerStorageValue(cid, c.storage)
        if(item.itemid == 1946) then
            doTransformItem(item.uid, item.itemid - 1) -- changes the lever to 1945
            local creatureCount, summonCreature  = countCreatures(c)
            if summonCreature and round ~= maxRounds then
                initiate(cid, c, round)
                setPlayerStorageValue(cid, c.storage, round + 1)
            else
                doTransformItem(item.uid, item.itemid + 1) -- changes the lever to 1946
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Sorry, "..getPlayerName(cid).." but there are still "..creatureCount.." creature(s) left to kill.")
            end
        end
        return true
    end
 
Last edited:
@Codex NG

First script gave me some errors but I fixed them. but it doesn't spawn monsters. I press the lever it TPS me to the spot and it says only "Prepare f"

It can also be that I make the script worse :oops:.

This is the script atm:
Code:
    local c = {
        tp = {x = 1035, y = 895, z = 9}, -- Change XXXX to the location you want.
        text = {
                pos = {x=1035, y=895, z=9},
                say = "Prepare for round "
        }    }
        area = {
            from = {x=1031,y=891,z=9}, -- the first north-west tile pos
            to = {x=1039,y=898,z=9} -- the last south-east tile pos
        }
        monsterSpawnPoints = {
            [1] = {x=1032, y=892, z=9}, -- spawn point 1
            [2] = {x=1037, y=897, z=9}, -- spawn point 2
            [3] = {x=1038, y=892, z=9}, -- spawn point 3
            [4] = {x=1032, y=898, z=9} -- spawn point 4
        }
        rounds = {
            [1] = { -- round 1
                    [1] = { name = "morgaroth" }, -- will spawn at spawn point 1
                    [2] = { name = "ghazbaran" }, -- will spawn at spawn point 2
                    [3] = { name = "apocalypse" }, -- will spawn at spawn point 3
                    [4] = { name = "zugurosh" } -- will spawn at spawn point 4
                },
            [2] = { -- round 2
                    [1] = { name = "morgaroth" },
                    [2] = { name = "ghazbaran" },
                    [3] = { name = "cobra" },
                    [4] = { name = "cobra" }
                },
        },
        {textcolor = 2
    }

    function spawnCreatures(c, round)
        for point, creature in ipairs(c.rounds[round]) do
            doSummonCreature(creature.name, c.monsterSpawnPoints[point])
        end
    end

    function onUse(cid, item, frompos, item2, topos)
        local round = 1
        doTeleportThing(cid, c.tp)
        doSendAnimatedText(c.text.pos, c.text.say..round, c.textColor)
        spawnCreatures(c, round)
        return true
    end

And it gives me these errors when I use it:
Code:
[11/09/2015 17:32:17] [Error - Action Interface]
[11/09/2015 17:32:17] data/actions/scripts/Ultimate Quest.lua:onUse
[11/09/2015 17:32:17] Description:
[11/09/2015 17:32:17] data/actions/scripts/Ultimate Quest.lua:35: attempt to index field 'rounds' (a nil value)
[11/09/2015 17:32:17] stack traceback:
[11/09/2015 17:32:17]     data/actions/scripts/Ultimate Quest.lua:35: in function 'spawnCreatures'
[11/09/2015 17:32:17]     data/actions/scripts/Ultimate Quest.lua:44: in function <data/actions/scripts/Ultimate Quest.lua:40>

Second script does nothing. No errors or something just when I use the lever nothing. I didn't changed the script here. ;)

Still thanks for the help :p:D

btw, the script is harder to make then I tought lol.
 
@Codex NG
I press the lever it TPS me to the spot and it says only "Prepare f"
Lets work on one problem at a time :p

I just remembered doSendAnimatedText only prints so many characters

A way to get around this is to create a new function which will break apart the text.
Code:
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 onUse(cid, item, frompos, item2, topos)
    local round = 1
    doTeleportThing(cid, c.tp)
    doAnimatedAllText(c.text.pos, c.text.say..round, c.textColor)
    spawnCreatures(c, round)
    return true
end

I want you to try this script again but this time take a screen shot of the console window so we can see if there are any errors
Code:
    --[[
        You should make the area where the creatures spawn a no log out zone
    ]]

    local c = {
        tp = { x = 1035, y = 895, z = 9 }, -- Change XXXX to the location you want.
        text = {
                pos = { x = 1035, y = 895, z = 9 },
                say = "Prepare for round "
        },
        area = {
            from = { x = 1031, y = 891,z = 9 }, -- the first north-west tile pos
            to = { x = 1039, y = 898, z = 9 } -- the last south-east tile pos
        },
        monsterSpawnPoints = {
            [1] = { x = 1032, y = 892, z = 9 }, -- spawn point 1
            [2] = { x = 1037, y = 897, z = 9 }, -- spawn point 1
            [3] = { x = 1038, y = 892, z = 9 }, -- spawn point 1
            [4] = { x = 1032, y = 898, z = 9 } -- spawn point 1
        },
        rounds = {
            [1] = { -- round 1
                    [1] = { name = "morgaroth" }, -- will spawn at spawn point 1
                    [2] = { name = "ghazbaran" }, -- will spawn at spawn point 2
                    [3] = { name = "apocalypse" }, -- will spawn at spawn point 3
                    [4] = { name = "zugurosh" } -- will spawn at spawn point 4
                },
            [2] = { -- round 2
                    [1] = { name = "morgaroth" },
                    [2] = { name = "ghazbaran" },
                    [3] = { name = "cobra" },
                    [4] = { name = "cobra" }
                }
        },
        textColor = 2,
        creatures = {},
        storage = 10000 -- change this to an unused storage value
    }
    -- 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)
        spawnCreatures(c, round)
        doTeleportThing(cid, c.tp)
        doAnimatedAllText(c.text.pos, c.text.say..round, c.textColor)
    end

    function onUse(cid, item, frompos, item2, topos)
        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 itemid - 1 or 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)
            else
                doTransformItem(item.uid, (item.itemid == 1945) and itemid + 1 or 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.")
            end
        end
        return true
    end
 
Last edited by a moderator:
I want you to try this script again but this time take a screen shot of the console window so we can see if there are any errors
Code:
    --[[
        You should make the area where the creatures spawn a no log out zone
    ]]

    local c = {
        tp = { x = 1035, y = 895, z = 9 }, -- Change XXXX to the location you want.
        text = {
                pos = { x = 1035, y = 895, z = 9 },
                say = "Prepare for round "
        },
        area = {
            from = { x = 1031, y = 891,z = 9 }, -- the first north-west tile pos
            to = { x = 1039, y = 898, z = 9 } -- the last south-east tile pos
        },
        monsterSpawnPoints = {
            [1] = { x = 1032, y = 892, z = 9 }, -- spawn point 1
            [2] = { x = 1037, y = 897, z = 9 }, -- spawn point 1
            [3] = { x = 1038, y = 892, z = 9 }, -- spawn point 1
            [4] = { x = 1032, y = 898, z = 9 } -- spawn point 1
        },
        rounds = {
            [1] = { -- round 1
                    [1] = { name = "morgaroth" }, -- will spawn at spawn point 1
                    [2] = { name = "ghazbaran" }, -- will spawn at spawn point 2
                    [3] = { name = "apocalypse" }, -- will spawn at spawn point 3
                    [4] = { name = "zugurosh" } -- will spawn at spawn point 4
                },
            [2] = { -- round 2
                    [1] = { name = "morgaroth" },
                    [2] = { name = "ghazbaran" },
                    [3] = { name = "cobra" },
                    [4] = { name = "cobra" }
                }
        },
        textColor = 2,
        creatures = {},
        storage = 10000 -- change this to an unused storage value
    }
    -- 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)
        spawnCreatures(c, round)
        doTeleportThing(cid, c.tp)
        doAnimatedAllText(c.text.pos, c.text.say..round, c.textColor)
    end

    function onUse(cid, item, frompos, item2, topos)
        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 itemid - 1 or 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)
            else
                doTransformItem(item.uid, (item.itemid == 1945) and itemid + 1 or 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.")
            end
        end
        return true
    end
loool
 
I want you to try this script again but this time take a screen shot of the console window so we can see if there are any errors
Code:
    --[[
        You should make the area where the creatures spawn a no log out zone
    ]]

    local c = {
        tp = { x = 1035, y = 895, z = 9 }, -- Change XXXX to the location you want.
        text = {
                pos = { x = 1035, y = 895, z = 9 },
                say = "Prepare for round "
        },
        area = {
            from = { x = 1031, y = 891,z = 9 }, -- the first north-west tile pos
            to = { x = 1039, y = 898, z = 9 } -- the last south-east tile pos
        },
        monsterSpawnPoints = {
            [1] = { x = 1032, y = 892, z = 9 }, -- spawn point 1
            [2] = { x = 1037, y = 897, z = 9 }, -- spawn point 1
            [3] = { x = 1038, y = 892, z = 9 }, -- spawn point 1
            [4] = { x = 1032, y = 898, z = 9 } -- spawn point 1
        },
        rounds = {
            [1] = { -- round 1
                    [1] = { name = "morgaroth" }, -- will spawn at spawn point 1
                    [2] = { name = "ghazbaran" }, -- will spawn at spawn point 2
                    [3] = { name = "apocalypse" }, -- will spawn at spawn point 3
                    [4] = { name = "zugurosh" } -- will spawn at spawn point 4
                },
            [2] = { -- round 2
                    [1] = { name = "morgaroth" },
                    [2] = { name = "ghazbaran" },
                    [3] = { name = "cobra" },
                    [4] = { name = "cobra" }
                }
        },
        textColor = 2,
        creatures = {},
        storage = 10000 -- change this to an unused storage value
    }
    -- 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)
        spawnCreatures(c, round)
        doTeleportThing(cid, c.tp)
        doAnimatedAllText(c.text.pos, c.text.say..round, c.textColor)
    end

    function onUse(cid, item, frompos, item2, topos)
        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 itemid - 1 or 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)
            else
                doTransformItem(item.uid, (item.itemid == 1945) and itemid + 1 or 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.")
            end
        end
        return true
    end

Okay, I used ur script and here is my console:

3b16922d3708370be54c6b1bbd51559c.png


When I use it this shows up:

2597f509d062c316d0535cee44c3f81a.png


This is what I get ;)

Thanks for helping :)
 
Last edited by a moderator:
My bad, I made the corrections
Code:
    --[[
        You should make the area where the creatures spawn a no log out zone
    ]]

    local c = {
        tp = { x = 1035, y = 895, z = 9 }, -- Change XXXX to the location you want.
        text = {
                pos = { x = 1035, y = 895, z = 9 },
                say = "Prepare for round "
        },
        area = {
            from = { x = 1031, y = 891,z = 9 }, -- the first north-west tile pos
            to = { x = 1039, y = 898, z = 9 } -- the last south-east tile pos
        },
        monsterSpawnPoints = {
            [1] = { x = 1032, y = 892, z = 9 }, -- spawn point 1
            [2] = { x = 1037, y = 897, z = 9 }, -- spawn point 1
            [3] = { x = 1038, y = 892, z = 9 }, -- spawn point 1
            [4] = { x = 1032, y = 898, z = 9 } -- spawn point 1
        },
        rounds = {
            [1] = { -- round 1
                    [1] = { name = "morgaroth" }, -- will spawn at spawn point 1
                    [2] = { name = "ghazbaran" }, -- will spawn at spawn point 2
                    [3] = { name = "apocalypse" }, -- will spawn at spawn point 3
                    [4] = { name = "zugurosh" } -- will spawn at spawn point 4
                },
            [2] = { -- round 2
                    [1] = { name = "morgaroth" },
                    [2] = { name = "ghazbaran" },
                    [3] = { name = "cobra" },
                    [4] = { name = "cobra" }
                }
        },
        textColor = 2,
        creatures = {},
        storage = 10000 -- change this to an unused storage value
    }
    -- 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)
        spawnCreatures(c, round)
        doTeleportThing(cid, c.tp)
        doAnimatedAllText(c.text.pos, c.text.say..round, c.textColor)
    end

    function onUse(cid, item, frompos, item2, topos)
        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 and round ~= maxRounds then
                initiate(cid, c, round)
                setPlayerStorageValue(cid, c.storage, round + 1)
            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.")
            end
        end
        return true
    end
 
for the time being comment this out
Code:
local round = ( getPlayerStorageValue(cid, c.storage) <= 0 ) and 1 or getPlayerStorageValue(cid, c.storage)

and place this underneath it
Code:
local rounds = 1
-- this is a comment incase you didn't know
 
Euhm.. I placed it under it and I get the same errors:

Code:
[13/09/2015 13:00:13] [Error - Action Interface]
[13/09/2015 13:00:13] data/actions/scripts/Ultimate Quest.lua:onUse
[13/09/2015 13:00:13] Description:
[13/09/2015 13:00:13] data/actions/scripts/Ultimate Quest.lua:43: bad argument #1 to 'ipairs' (table expected, got nil)
[13/09/2015 13:00:13] stack traceback:
[13/09/2015 13:00:13]     [C]: in function 'ipairs'
[13/09/2015 13:00:13]     data/actions/scripts/Ultimate Quest.lua:43: in function 'spawnCreatures'
[13/09/2015 13:00:13]     data/actions/scripts/Ultimate Quest.lua:81: in function 'initiate'
[13/09/2015 13:00:13]     data/actions/scripts/Ultimate Quest.lua:94: in function <data/actions/scripts/Ultimate Quest.lua:86>

Thanks for helping tho :)
 
Back
Top