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

Solved Stepin, wait 10 second and respawn

Szafi

www.rookwar.pl
Joined
Mar 2, 2009
Messages
165
Reaction score
10
Location
Poland
tfs 0.4

Hello, i have easy script

Code:
function onStepIn(cid, pos)
if isPlayer(cid) then
doSummonCreature("Rotworm", {x=974, y=938, z=7})
doSendMagicEffect({x=974, y=938, z=7}, 10)
end
return TRUE
end

How to add time to spawn example Rotworm?
 
Code:
local delay = 10 -- seconds

local function doDelayedSpawn(monster, pos)
    doSummonCreature(monster, pos)
    doSendMagicEffect(pos, 10)
end

function onStepIn(cid, pos)
    if isPlayer(cid) then
        addEvent(doDelayedSpawn, delay * 1000, "Rotworm", {x=974, y=938, z=7})
    end
    return TRUE
end
 
Thanks my friend!
How can add more monster's?

Code:
local delay = 10 -- seconds

local function doDelayedSpawn(monster, pos)
    doSummonCreature(monster, pos)
    doSendMagicEffect(pos, 10)
end

function onStepIn(cid, pos)
    if isPlayer(cid) then
        addEvent(doDelayedSpawn, delay * 1000, "Rotworm", {x=974, y=938, z=7})
        addEvent(doDelayedSpawn, delay * 1000, "Rotworm", {x=997, y=938, z=7})
    end
    return TRUE
end

dont work :/


@edit

My bad, wrong postion in code - working

Thanks again!
 
Here are a few ways you can achieve players not being able to do this over and over again.

Using storage values:
Prevent a player from doing this more than once.
Code:
local config = {
    delay = 10, -- Time for monsters to spawn
    storage = 5000, -- Storage
    monsters = {
        {name = "Rotworm", pos = {x=974, y=938, z=7}},
        {name = "Rotworm", pos = {x=997, y=938, z=7}}
    }
}

local function doDelayedSpawn()
    for _, mob in ipairs(config.monsters) do
        doSummonCreature(mob.name, mob.pos)
        doSendMagicEffect(mob.pos, 10)
    end
end

function onStepIn(cid, pos)
    if isPlayer(cid) and getPlayerStorageValue(cid, config.storage) <= 0 then
        addEvent(doDelayedSpawn, config.delay * 1000)
        setPlayerStorageValue(cid, config.storage, 1)
    end
    return TRUE
end

Using a delay:
The tile can only be activated every x seconds.
Code:
local config = {
    delay = 10, -- Time for monsters to spawn
    useDelay = 30, -- Time between each time you can spawn monsters when stepping on the tile
    monsters = {
        {name = "Rotworm", pos = {x=974, y=938, z=7}},
        {name = "Rotworm", pos = {x=997, y=938, z=7}}
    }
}

local lastTime = 0
local function doDelayedSpawn()
    for _, mob in ipairs(config.monsters) do
        doSummonCreature(mob.name, mob.pos)
        doSendMagicEffect(mob.pos, 10)
    end
end

function onStepIn(cid, pos)
    if isPlayer(cid) then
        local t = os.time()
        if lastTime <= t then
            addEvent(doDelayedSpawn, config.delay * 1000)
            lastTime = t + config.useDelay
        end
    end
    return TRUE
end
 
Last edited:
Back
Top