• 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 How to add delay

sick

Member
Joined
Feb 5, 2009
Messages
258
Reaction score
6
Location
Lithuania, Vilnius
I got this script: when you walk on tile it summons monster, but how to make it so the tile would have delay for summoning again,
Lets say i step on it and monsters are spawned, if i step again it doesn't summon them, but after 1min it works again.

Code:
local config = {
    tile = 354,
	uniqueid= 1663,
    monster = "Vampire",
    spawn = {
        { x = 830, y = 901, z = 7, stackpos = 1 },
		{ x = 828, y = 899, z = 7, stackpos = 1 },
		{ x = 828, y = 902, z = 7, stackpos = 1 },
		{ x = 832, y = 899, z = 7, stackpos = 1 }
		
    }
}
 
function onStepIn(cid, item, frompos, item2, topos)
    if item.uid == config.uniqueid and item.itemid == config.tile then
        for i = 1, table.maxn(config.spawn) do
            doSummonCreature(config.monster, config.spawn[i])
        end
    else
        doPlayerSendCancel(cid, "Grrrr.")
	end
    return TRUE
end
 
try : -- Dont test with GM --

LUA:
local config = {
    tile = 354,
	uniqueid= 1663,
    monster = "Vampire",
    spawn = {
        { x = 830, y = 901, z = 7, stackpos = 1 },
		{ x = 828, y = 899, z = 7, stackpos = 1 },
		{ x = 828, y = 902, z = 7, stackpos = 1 },
		{ x = 832, y = 899, z = 7, stackpos = 1 }
	storage = 1010	
	cooldown = 60   -- in seconds
    }
}
 
function onStepIn(cid, item, frompos, item2, topos)
    if item.uid == config.uniqueid and item.itemid == config.tile then
	   if exhaustion.get(cid, config.storage) then
	                         doPlayerSendCancel(cid,"You must wait another "..exhaustion.get(cid, config.storage).." seconds to summon a monster.")
	   else
                    for i = 1, table.maxn(config.spawn) do
                                doSummonCreature(config.monster, config.spawn[i])
                    end
			       exhaustion.set(cid, config.storage, config.cooldown)
	   end
    else
                               doPlayerSendCancel(cid, "Grrrr.")
    end
    return TRUE
end
 
Nah, something is wrong i'm getting this error when i step on it:

PHP:
data/movements/scripts/summontile.lua:onStepIn
[15/09/2010 13:18:01] Description: 
[15/09/2010 13:18:01] data/lib/034-exhaustion.lua:28: attempt to perform arithmetic on local 'time' (a nil value)
[15/09/2010 13:18:01] stack traceback:
[15/09/2010 13:18:01] 	data/lib/034-exhaustion.lua:28: in function 'set'
[15/09/2010 13:18:01] 	data/movements/scripts/summontile.lua:24: in function <data/movements/scripts/summontile.lua:16>
 
LUA:
local config = {
    tile = 354,
    uniqueid= 1663,
    monster = "Vampire",
    spawn = {
        { x = 830, y = 901, z = 7, stackpos = 1 },
        { x = 828, y = 899, z = 7, stackpos = 1 },
        { x = 828, y = 902, z = 7, stackpos = 1 },
        { x = 832, y = 899, z = 7, stackpos = 1 }
    },
    storage = 1010,
    cooldown = 60 -- in seconds
}
 
function onStepIn(cid, item, frompos, item2, topos)
    if item.uid == config.uniqueid and item.itemid == config.tile then
        if exhaustion.get(cid, config.storage) then
            doPlayerSendCancel(cid,"You must wait another "..exhaustion.get(cid, config.storage).." seconds to summon a monster.")
	else
            for i = 1, table.maxn(config.spawn) do
                doSummonCreature(config.monster, config.spawn[i])
            end
            exhaustion.set(cid, config.storage, config.cooldown)
        end
    else
        doPlayerSendCancel(cid, "Grrrr.")
    end
    return TRUE
end
 
Noob style, brotha

LUA:
local config = {
    tile = 354,
    uniqueid= 1663,
    monster = "Vampire",
    spawn = {
        { x = 830, y = 901, z = 7, stackpos = 1 },
        { x = 828, y = 899, z = 7, stackpos = 1 },
        { x = 828, y = 902, z = 7, stackpos = 1 },
        { x = 832, y = 899, z = 7, stackpos = 1 }
    },
    storage = 1010,
}
 
function onStepIn(cid, item, frompos, item2, topos)
    if item.uid == config.uniqueid and item.itemid == config.tile then
        if getGlobalStorageValue(45000) >= os.time() then
            doPlayerSendCancel(cid,"You must wait another ".. getGlobalStorageValue(45000) - os.time() .." seconds to summon a monster.")
	else
            for i = 1, table.maxn(config.spawn) do
                doSummonCreature(config.monster, config.spawn[i])
				setGlobalStorageValue(45000, os.time() + 60)
            end
        end
    else
        doPlayerSendCancel(cid, "Grrrr.")
    end
    return TRUE
end
 
Just found out one thing that i can't make more tiles with this script, because when i walk on one others automatically got exhaust for 1min (all the tiles have a new script just edited a little), how to fix that they would all work independent?
 
All the tiles got a new script made for them, but i don't get it why all the others get delay( lets say tile 1, tile 2, tile 3 and tile 4 gets delayed) when it is walked on totally other one ( lets say it is stepped on tile 4) :S
 
Just change globstorage variable for each tile (u must make another script file for each tile)...
LUA:
local globstorage = 45000
local config = {
    tile = 354,
    uniqueid= 1663,
    monster = "Vampire",
    spawn = {
        { x = 830, y = 901, z = 7, stackpos = 1 },
        { x = 828, y = 899, z = 7, stackpos = 1 },
        { x = 828, y = 902, z = 7, stackpos = 1 },
        { x = 832, y = 899, z = 7, stackpos = 1 }
    },
    storage = 1010,
}
 
function onStepIn(cid, item, frompos, item2, topos)
    if item.uid == config.uniqueid and item.itemid == config.tile then
        if getGlobalStorageValue(globstorage) >= os.time() then
            doPlayerSendCancel(cid,"You must wait another ".. getGlobalStorageValue(globstorage) - os.time() .." seconds to summon a monster.")
	else
            for i = 1, table.maxn(config.spawn) do
                doSummonCreature(config.monster, config.spawn[i])
				setGlobalStorageValue(globstorage, os.time() + 60)
            end
        end
    else
        doPlayerSendCancel(cid, "Grrrr.")
    end
    return TRUE
end
 
Back
Top