• 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:
Code:
This video is private.
Sorry about that.
Its still private.. this is a public forum i don't know why you made the video private to begin with... the script I wrote is public why shouldn't your video be public as well?
 
The point here is it works, the only issue now is maybe rearranging the the time when the creatures should spawn and setting the round value

Try this version, i changed it so it has a spawn time, so you will see the text 1st before the creatures spawn, adjust the spawn time as needed
right now its set to execute the spawn after 5 seconds
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
        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)
        --local round = ( getPlayerStorageValue(cid, c.storage) <= 0 ) and 1 or getPlayerStorageValue(cid, c.storage)
        local round = 1 -- we will fix this later
        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

We can create a tp and change the way it executes later on
 
Last edited by a moderator:
Try this version, i changed it so it has a spawn time, so you will see the text 1st before the creatures spawn, adjust the spawn time as needed
right now its set to execute the spawn after 5 seconds
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
        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)
        --local round = ( getPlayerStorageValue(cid, c.storage) <= 0 ) and 1 or getPlayerStorageValue(cid, c.storage)
        local round = 1 -- we will fix this later
        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
This version works nice :) Maybe we can also make that there is a door and you can only open it when it you passed all 2/3 the rounds maybe it's easier then a TP. I don't really know :p

Thx for the help.
 
Hey :),So how can we make a round 2/3 and a spawning tp :P

Btw, If a 2nd guy starts the quest right after another guy will still be everything all right? (Maybe stupid question :oops:)
 
Back
Top