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

RevScripts use item spawn monster, smarter

Lbtg

Advanced OT User
Joined
Nov 22, 2008
Messages
2,394
Reaction score
162
Hey i want to ask if someone could make, that if plaeyr use item x on any x/y/z with has no pz , where monsters can walk, and
by using item on some place, it spawns a monster lets say Wolf, and it makes that there spawns a wolf every 15 seconds for a 2 hours ?

does it possible ? would be cool
 
I don't have a 1.4 server to test it, sorry


LUA:
local monsterName = "Wolf"
local spawnInterval = 15 -- in seconds
local duration = 2 * 60 * 60 -- in seconds (2 hours)
local itemId = ITEM_ID -- Replace for the item ID
local checkRadius = 1 -- Radius check to see if can create the monster

local function canSpawnMonster(position)
    local creatures = getCreaturesInRange(position, checkRadius, checkRadius, false)
    return #creatures == 0
end

local function spawnMonster(position)
    if canSpawnMonster(position) then
        local monster = Game.createMonster(monsterName, position)
        if not monster then
            print("Failed to spawn monster at position: ", position)
        end
    else
        print("Cannot spawn monster at position: ", position, " - space occupied.")
    end
end

local function startSpawning(position)
    local endTime = os.time() + duration

    addEvent(function()
        if os.time() < endTime then
            spawnMonster(position)
            addEvent(startSpawning, spawnInterval * 1000, position)
        end
    end, spawnInterval * 1000)
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if target and not Tile(target:getPosition()):hasFlag(TILESTATE_PROTECTIONZONE) and not Tile(target:getPosition()):hasFlag(TILESTATE_BLOCKSOLID) then
        startSpawning(target:getPosition())
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Spawning started!")
    else
        player:sendTextMessage(MESSAGE_STATUS_WARNING, "You cannot use this item here.")
    end
    return true
end
 
I don't have a 1.4 server to test it, sorry


LUA:
local monsterName = "Wolf"
local spawnInterval = 15 -- in seconds
local duration = 2 * 60 * 60 -- in seconds (2 hours)
local itemId = ITEM_ID -- Replace for the item ID
local checkRadius = 1 -- Radius check to see if can create the monster

local function canSpawnMonster(position)
    local creatures = getCreaturesInRange(position, checkRadius, checkRadius, false)
    return #creatures == 0
end

local function spawnMonster(position)
    if canSpawnMonster(position) then
        local monster = Game.createMonster(monsterName, position)
        if not monster then
            print("Failed to spawn monster at position: ", position)
        end
    else
        print("Cannot spawn monster at position: ", position, " - space occupied.")
    end
end

local function startSpawning(position)
    local endTime = os.time() + duration

    addEvent(function()
        if os.time() < endTime then
            spawnMonster(position)
            addEvent(startSpawning, spawnInterval * 1000, position)
        end
    end, spawnInterval * 1000)
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if target and not Tile(target:getPosition()):hasFlag(TILESTATE_PROTECTIONZONE) and not Tile(target:getPosition()):hasFlag(TILESTATE_BLOCKSOLID) then
        startSpawning(target:getPosition())
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Spawning started!")
    else
        player:sendTextMessage(MESSAGE_STATUS_WARNING, "You cannot use this item here.")
    end
    return true
end
will test it asap, big thanks for your time!
Post automatically merged:

Im suprised you haven't checked that and you joined otland 2009 :D


View attachment 85932


View attachment 85933
still if browser on, it usualy counts me as i loged in i think xd cuz my browser kinda 24/7 on, and sometimes on otland page left on.

just to wider the mind xd
Post automatically merged:

I don't have a 1.4 server to test it, sorry


LUA:
local monsterName = "Wolf"
local spawnInterval = 15 -- in seconds
local duration = 2 * 60 * 60 -- in seconds (2 hours)
local itemId = ITEM_ID -- Replace for the item ID
local checkRadius = 1 -- Radius check to see if can create the monster

local function canSpawnMonster(position)
    local creatures = getCreaturesInRange(position, checkRadius, checkRadius, false)
    return #creatures == 0
end

local function spawnMonster(position)
    if canSpawnMonster(position) then
        local monster = Game.createMonster(monsterName, position)
        if not monster then
            print("Failed to spawn monster at position: ", position)
        end
    else
        print("Cannot spawn monster at position: ", position, " - space occupied.")
    end
end

local function startSpawning(position)
    local endTime = os.time() + duration

    addEvent(function()
        if os.time() < endTime then
            spawnMonster(position)
            addEvent(startSpawning, spawnInterval * 1000, position)
        end
    end, spawnInterval * 1000)
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if target and not Tile(target:getPosition()):hasFlag(TILESTATE_PROTECTIONZONE) and not Tile(target:getPosition()):hasFlag(TILESTATE_BLOCKSOLID) then
        startSpawning(target:getPosition())
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Spawning started!")
    else
        player:sendTextMessage(MESSAGE_STATUS_WARNING, "You cannot use this item here.")
    end
    return true
end
just noticed after trying the script for 15min in diff ways that the script is not revscript xD

can i ask please to convert or someone else to convert it to revscripts ?
 
Last edited:
I don't have a 1.4 server to test it, sorry


LUA:
local monsterName = "Wolf"
local spawnInterval = 15 -- in seconds
local duration = 2 * 60 * 60 -- in seconds (2 hours)
local itemId = ITEM_ID -- Replace for the item ID
local checkRadius = 1 -- Radius check to see if can create the monster

local function canSpawnMonster(position)
    local creatures = getCreaturesInRange(position, checkRadius, checkRadius, false)
    return #creatures == 0
end

local function spawnMonster(position)
    if canSpawnMonster(position) then
        local monster = Game.createMonster(monsterName, position)
        if not monster then
            print("Failed to spawn monster at position: ", position)
        end
    else
        print("Cannot spawn monster at position: ", position, " - space occupied.")
    end
end

local function startSpawning(position)
    local endTime = os.time() + duration

    addEvent(function()
        if os.time() < endTime then
            spawnMonster(position)
            addEvent(startSpawning, spawnInterval * 1000, position)
        end
    end, spawnInterval * 1000)
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if target and not Tile(target:getPosition()):hasFlag(TILESTATE_PROTECTIONZONE) and not Tile(target:getPosition()):hasFlag(TILESTATE_BLOCKSOLID) then
        startSpawning(target:getPosition())
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Spawning started!")
    else
        player:sendTextMessage(MESSAGE_STATUS_WARNING, "You cannot use this item here.")
    end
    return true
end
Tested script via actions.


got error:
LUA:
2024-07-09 11:56:00 -  Lua Script Error: [Main Interface]
2024-07-09 11:56:00 -  in a timer event called from:
2024-07-09 11:56:00 -  (Unknown scriptfile)
2024-07-09 11:56:00 -  data/actions/scripts/monsterboxes/tarantulabox2h.lua:8: attempt to call global 'getCreaturesInRange' (a nil value)
2024-07-09 11:56:00 -  stack traceback:
2024-07-09 11:56:00 -   [C]: in function 'getCreaturesInRange'
2024-07-09 11:56:00 -   data/actions/scripts/monsterboxes/tarantulabox2h.lua:8: in function 'canSpawnMonster'
2024-07-09 11:56:00 -   data/actions/scripts/monsterboxes/tarantulabox2h.lua:13: in function 'spawnMonster'
2024-07-09 11:56:00 -   data/actions/scripts/monsterboxes/tarantulabox2h.lua:28: in function <data/actions/scripts/monsterboxes/tarantulabox2h.lua:26>

Also on use, item shoud dissapear
 
Tested script via actions.


got error:
LUA:
2024-07-09 11:56:00 -  Lua Script Error: [Main Interface]
2024-07-09 11:56:00 -  in a timer event called from:
2024-07-09 11:56:00 -  (Unknown scriptfile)
2024-07-09 11:56:00 -  data/actions/scripts/monsterboxes/tarantulabox2h.lua:8: attempt to call global 'getCreaturesInRange' (a nil value)
2024-07-09 11:56:00 -  stack traceback:
2024-07-09 11:56:00 -   [C]: in function 'getCreaturesInRange'
2024-07-09 11:56:00 -   data/actions/scripts/monsterboxes/tarantulabox2h.lua:8: in function 'canSpawnMonster'
2024-07-09 11:56:00 -   data/actions/scripts/monsterboxes/tarantulabox2h.lua:13: in function 'spawnMonster'
2024-07-09 11:56:00 -   data/actions/scripts/monsterboxes/tarantulabox2h.lua:28: in function <data/actions/scripts/monsterboxes/tarantulabox2h.lua:26>

Also on use, item shoud dissapear

I think it's a 0.4 function
Try isInRange function
 
Last edited:
Back
Top