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

Script Arena Help

Dorianek

Member
Joined
Nov 29, 2018
Messages
247
Reaction score
10
Location
Poland
Hello, how to convert this script to:

Monster disappeared automatically after leaving the arena? so that another person can enter

np :

local nazwyPotworow = {"Pirate Corsair"} -- Nazwy potworów, jakie skrypt może robić
local exh = 2 -- Ile sekund exhaused
local storage = 10016
function onUse(cid, item, frompos, item2, topos)
local monster = nazwyPotworow[math.random(1,#nazwyPotworow)]

if(getPlayerStorageValue(cid,storage) <= os.time()) then
local summon = doSummonCreature(monster,getPlayerPosition(cid))
doChallengeCreature(cid, summon)
doChallengeCreature(summon, cid)
setPlayerStorageValue(cid,storage,os.time()+exh)
doPlayerSendTextMessage(cid,MESSAGE_INFO_DESCR,"Czeka cie walka z ".. monster .."!")
else
doPlayerSendCancel(cid,"You are exhausted.")
end
return TRUE
end
 
Solution
This one should work, 99% sure
Code:
local storage = 30001 -- used to display remaining time
local area = {
    fromPos = {x = 360, y = 7, z = 9},
    toPos = {x = 371, y = 10, z = 9}
}
local playerPos = {x = 366, y = 8, z = 9}
local areaTimer = 10 * 60

local function getPlayerFromArea()
    for x = area.fromPos.x, area.toPos.x do
        for y = area.fromPos.y, area.toPos.y do
            for z = area.fromPos.z, area.toPos.z do
                local t = Tile(x,y,z)
                if t and t:getTopCreature() and t:getTopCreature():isPlayer() then
                    return t:getTopCreature()
                elseif t:getTopCreature() and t:getTopCreature():isMonster() then
                    local monster = Monster(t:getTopCreature())...
im trying this too, lol lets get this

im trying with this way, but it does not read when there are no players in the area x.x

Lua:
addEvent(function() -- making this loop later, so it will check each X seconds if there are players
  local spec = getSpectators(position, 50, 50) --50 is the radius
                if spec ~= nil then
                     for _, x in pairs(spec) do
                        if isMonster(x) and not(isPlayer(x) == true) then -- this check if there are monsters but not players, but this is the part we must work on
                           doRemoveCreature(x) --this remove creatures in x area
                           print(2)
                        end
                    end  
                end
end, 3500) --3500 is the duration in ms

BTW dude, just 1 bump per day make the ban away


--------------


EDIT:: i found the solution =)
this function is sloppy but will remove monsters if there are no players in the area (just add the loop, im still working on it)

Lua:
addEvent(function()
  local area = { --square of your room, top left, bottom right)
    fromPos = {x = 683, y = 605, z = 11}, --top left
    toPos = {x = 706, y = 628, z = 11} --bottom right
    }
local position = {x = 688, y = 621, z = 11} -- centre of room
if not isPlayer(cid) then --dont move
        return true
    end
    for _, pid in ipairs(getPlayersOnline()) do --dont move if u dont know
        local xpos = getPlayerPosition(pid) --dont move
        if isInRange(xpos, area.fromPos, area.toPos) then -- check if there are players
      print(1) --you can remove this. and add wathever u want
    else
      local spec = getSpectators(position, 50, 50) --50 is the radius in SQM
                if spec ~= nil then
                     for _, s in pairs(spec) do
                         if isMonster(s) then -- check if there are monsters
                             doRemoveCreature(s) --remove creatures on the area
                         end  
                     end
                 end
        print(2) --remove this is just a checkpoint
    end
end  
end, 3500) --add a loop or something here to constantly check players in area
 
Last edited:
Welcome to the beginning, I'm sorry for these bumps I will not.

I would like to compile the above script under my but I probably do something wrong because I get some errors in the console that want me to delete "if" or "elease" I do not know how to stick it together with the script below to have arms and legs

Code:
 local storage = 30001 - used to display remaining time
local area = {
    fromPos = {x = 360, y = 7, z = 9},
    toPos = {x = 371, y = 10, z = 9}
}
local playerPos = {x = 366, y = 8, z = 9}
local areaTimer = 10 * 60
 
local function getPlayerFromArea ()
    for x = area.fromPos.x, area.toPos.x to
        for y = area.fromPos.y, area.toPos.y do
            for z = area.fromPos.z, area.toPos.z to
                local t = Tile (x, y, z)
                if t and t: getTopCreature () and t: getTopCreature (): isPlayer () then
                    return t: getTopCreature ()
                end
            end
        end
    end
    return nil
end
 
local function kickPlayer ()
    local p = getPlayerFromArea ()
    if not p then return end
    p: teleportTo (p: getTown (): getTemplePosition ())
    p: getPosition (): sendMagicEffect (CONST_ME_TELEPORT)
end
 
function onUse (player, item, frompos, item2, topos)
    local p = getPlayerFromArea ()
    if not p then
        Player: teleportTo (playerPos)
        Player: getPosition (): sendMagicEffect (CONST_ME_TELEPORT)
        Game.setStorageValue (storage, os.time () + areaTimer)
        item: transform (item.itemid == 1946 and 1945 or 1946)
        stopEvent (kickPlayer)
        addEvent (kickPlayer, areaTimer * 1000)
        return true
    end
    player: sendCancelMessage ("A player is inside the area & has" ..Game.getStorageValue (storage) - os.time () .. "seconds remaining")
    return true
end
 
You have erased a lot of "do" and uncommented the first line, a comment should cointains two -- instead of one, else the server will try to load it as part of the code
Code:
local storage = 30001 -- used to display remaining time
local area = {
    fromPos = {x = 360, y = 7, z = 9},
    toPos = {x = 371, y = 10, z = 9}
}
local playerPos = {x = 366, y = 8, z = 9}
local areaTimer = 10 * 60

local function getPlayerFromArea()
    for x = area.fromPos.x, area.toPos.x do
        for y = area.fromPos.y, area.toPos.y do
            for z = area.fromPos.z, area.toPos.z do
                local t = Tile(x,y,z)
                if t and t:getTopCreature() and t:getTopCreature():isPlayer() then
                    return t:getTopCreature()
                elseif t and t:getTopCreature() and t:getTopCreature():isMonster() then
                    t:remove()
                end
            end
        end
    end
    return nil
end

local function kickPlayer()
    local p = getPlayerFromArea()
    if not p then return end
    p:teleportTo(p:getTown():getTemplePosition())
    p:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
end

function onUse(player, item, frompos, item2, topos)
    local p = getPlayerFromArea()
    if not p then
        player:teleportTo(playerPos)
        player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
        Game.setStorageValue(storage,os.time()+areaTimer)
        item:transform(item.itemid == 1946 and 1945 or 1946)
        stopEvent(kickPlayer)
        addEvent(kickPlayer, areaTimer * 1000)
        return true
    end
    player:sendCancelMessage("A player is inside the area & has "..Game.getStorageValue(storage) - os.time().." seconds remaining")
    return true
end

Try that one out, it should remove any monster left in the area from a previous battle when a new player uses the lever to get inside the arena
 
Unfortunately. after leaving the Arena they are still staying

Edit :

after leaving the Arena the monster is left when the new player attempts to enter Arene can not make a mistake


Code:
Lua Script Error: [Action Interface]
data/actions/scripts/switchtp1.lua:onUse
data/actions/scripts/switchtp1.lua:17: attempt to call method 'remove' (a nil value)
stack traceback:
        [C]: in function 'remove'
        data/actions/scripts/switchtp1.lua:17: in function 'getPlayerFromArea'
        data/actions/scripts/switchtp1.lua:33: in function <data/actions/scripts/switchtp1.lua:32>

Lua Script Error: [Action Interface]
data/actions/scripts/switchtp1.lua:onUse
data/actions/scripts/switchtp1.lua:17: attempt to call method 'remove' (a nil value)
stack traceback:
        [C]: in function 'remove'
        data/actions/scripts/switchtp1.lua:17: in function 'getPlayerFromArea'
        data/actions/scripts/switchtp1.lua:33: in function <data/actions/scripts/switchtp1.lua:32>

Lua Script Error: [Action Interface]
data/actions/scripts/switchtp1.lua:onUse
data/actions/scripts/switchtp1.lua:17: attempt to call method 'remove' (a nil value)
stack traceback:
        [C]: in function 'remove'
        data/actions/scripts/switchtp1.lua:17: in function 'getPlayerFromArea'
        data/actions/scripts/switchtp1.lua:33: in function <data/actions/scripts/switchtp1.lua:32>

Lua Script Error: [Action Interface]
data/actions/scripts/switchtp1.lua:onUse
data/actions/scripts/switchtp1.lua:17: attempt to call method 'remove' (a nil value)
stack traceback:
        [C]: in function 'remove'
        data/actions/scripts/switchtp1.lua:17: in function 'getPlayerFromArea'
        data/actions/scripts/switchtp1.lua:33: in function <data/actions/scripts/switchtp1.lua:32>

Lua Script Error: [Action Interface]
data/actions/scripts/switchtp1.lua:onUse
data/actions/scripts/switchtp1.lua:17: attempt to call method 'remove' (a nil value)
stack traceback:
        [C]: in function 'remove'
        data/actions/scripts/switchtp1.lua:17: in function 'getPlayerFromArea'
        data/actions/scripts/switchtp1.lua:33: in function <data/actions/scripts/switchtp1.lua:32>

Lua Script Error: [Action Interface]
data/actions/scripts/switchtp1.lua:onUse
data/actions/scripts/switchtp1.lua:17: attempt to call method 'remove' (a nil value)
stack traceback:
        [C]: in function 'remove'
        data/actions/scripts/switchtp1.lua:17: in function 'getPlayerFromArea'
        data/actions/scripts/switchtp1.lua:33: in function <data/actions/scripts/switchtp1.lua:32>

Lua Script Error: [Action Interface]
data/actions/scripts/switchtp1.lua:onUse
data/actions/scripts/switchtp1.lua:17: attempt to call method 'remove' (a nil value)
stack traceback:
        [C]: in function 'remove'
        data/actions/scripts/switchtp1.lua:17: in function 'getPlayerFromArea'
        data/actions/scripts/switchtp1.lua:33: in function <data/actions/scripts/switchtp1.lua:32>

Lua Script Error: [Action Interface]
data/actions/scripts/switchtp1.lua:onUse
data/actions/scripts/switchtp1.lua:17: attempt to call method 'remove' (a nil value)
stack traceback:
        [C]: in function 'remove'
        data/actions/scripts/switchtp1.lua:17: in function 'getPlayerFromArea'
        data/actions/scripts/switchtp1.lua:33: in function <data/actions/scripts/switchtp1.lua:32>

Lua Script Error: [Action Interface]
data/actions/scripts/switchtp1.lua:onUse
data/actions/scripts/switchtp1.lua:17: attempt to call method 'remove' (a nil value)
stack traceback:
        [C]: in function 'remove'
        data/actions/scripts/switchtp1.lua:17: in function 'getPlayerFromArea'
        data/actions/scripts/switchtp1.lua:33: in function <data/actions/scripts/switchtp1.lua:32>

Lua Script Error: [Action Interface]
data/actions/scripts/switchtp1.lua:onUse
data/actions/scripts/switchtp1.lua:17: attempt to call method 'remove' (a nil value)
stack traceback:
        [C]: in function 'remove'
        data/actions/scripts/switchtp1.lua:17: in function 'getPlayerFromArea'
        data/actions/scripts/switchtp1.lua:33: in function <data/actions/scripts/switchtp1.lua:32>

Lua Script Error: [Action Interface]
data/actions/scripts/switchtp1.lua:onUse
data/actions/scripts/switchtp1.lua:17: attempt to call method 'remove' (a nil value)
stack traceback:
        [C]: in function 'remove'
        data/actions/scripts/switchtp1.lua:17: in function 'getPlayerFromArea'
        data/actions/scripts/switchtp1.lua:33: in function <data/actions/scripts/switchtp1.lua:32>

Lua Script Error: [Action Interface]
data/actions/scripts/switchtp1.lua:onUse
data/actions/scripts/switchtp1.lua:17: attempt to call method 'remove' (a nil value)
stack traceback:
        [C]: in function 'remove'
        data/actions/scripts/switchtp1.lua:17: in function 'getPlayerFromArea'
        data/actions/scripts/switchtp1.lua:33: in function <data/actions/scripts/switchtp1.lua:32>

Lua Script Error: [Action Interface]
data/actions/scripts/switchtp1.lua:onUse
data/actions/scripts/switchtp1.lua:17: attempt to call method 'remove' (a nil value)
stack traceback:
        [C]: in function 'remove'
        data/actions/scripts/switchtp1.lua:17: in function 'getPlayerFromArea'
        data/actions/scripts/switchtp1.lua:33: in function <data/actions/scripts/switchtp1.lua:32>

Lua Script Error: [Action Interface]
data/actions/scripts/switchtp1.lua:onUse
data/actions/scripts/switchtp1.lua:17: attempt to call method 'remove' (a nil value)
stack traceback:
        [C]: in function 'remove'
        data/actions/scripts/switchtp1.lua:17: in function 'getPlayerFromArea'
        data/actions/scripts/switchtp1.lua:33: in function <data/actions/scripts/switchtp1.lua:32>

Lua Script Error: [Action Interface]
data/actions/scripts/switchtp1.lua:onUse
data/actions/scripts/switchtp1.lua:17: attempt to call method 'remove' (a nil value)
stack traceback:
        [C]: in function 'remove'
        data/actions/scripts/switchtp1.lua:17: in function 'getPlayerFromArea'
        data/actions/scripts/switchtp1.lua:33: in function <data/actions/scripts/switchtp1.lua:32>
 
I just can't test this and don't really know the exact way to remove a monster, maybe with this one?
Code:
local storage = 30001 -- used to display remaining time
local area = {
    fromPos = {x = 360, y = 7, z = 9},
    toPos = {x = 371, y = 10, z = 9}
}
local playerPos = {x = 366, y = 8, z = 9}
local areaTimer = 10 * 60

local function getPlayerFromArea()
    for x = area.fromPos.x, area.toPos.x do
        for y = area.fromPos.y, area.toPos.y do
            for z = area.fromPos.z, area.toPos.z do
                local t = Tile(x,y,z)
                if t and t:getTopCreature() and t:getTopCreature():isPlayer() then
                    return t:getTopCreature()
                elseif t:getTopCreature():isMonster() then
                    local monster = Monster(t:getTopCreature())
                    monster:remove()
                end
            end
        end
    end
    return nil
end

local function kickPlayer()
    local p = getPlayerFromArea()
    if not p then return end
    p:teleportTo(p:getTown():getTemplePosition())
    p:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
end

function onUse(player, item, frompos, item2, topos)
    local p = getPlayerFromArea()
    if not p then
        player:teleportTo(playerPos)
        player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
        Game.setStorageValue(storage,os.time()+areaTimer)
        item:transform(item.itemid == 1946 and 1945 or 1946)
        stopEvent(kickPlayer)
        addEvent(kickPlayer, areaTimer * 1000)
        return true
    end
    player:sendCancelMessage("A player is inside the area & has "..Game.getStorageValue(storage) - os.time().." seconds remaining")
    return true
end
 
Code:
Lua Script Error: [Action Interface]
data/actions/scripts/switchtp1.lua:onUse
data/actions/scripts/switchtp1.lua:16: attempt to index a nil value
stack traceback:
        [C]: in function '__index'
        data/actions/scripts/switchtp1.lua:16: in function 'getPlayerFromArea'
        data/actions/scripts/switchtp1.lua:34: in function <data/actions/scripts/switchtp1.lua:33>
 
This one should work, 99% sure
Code:
local storage = 30001 -- used to display remaining time
local area = {
    fromPos = {x = 360, y = 7, z = 9},
    toPos = {x = 371, y = 10, z = 9}
}
local playerPos = {x = 366, y = 8, z = 9}
local areaTimer = 10 * 60

local function getPlayerFromArea()
    for x = area.fromPos.x, area.toPos.x do
        for y = area.fromPos.y, area.toPos.y do
            for z = area.fromPos.z, area.toPos.z do
                local t = Tile(x,y,z)
                if t and t:getTopCreature() and t:getTopCreature():isPlayer() then
                    return t:getTopCreature()
                elseif t:getTopCreature() and t:getTopCreature():isMonster() then
                    local monster = Monster(t:getTopCreature())
                    monster:remove()
                end
            end
        end
    end
    return nil
end

local function kickPlayer()
    local p = getPlayerFromArea()
    if not p then return end
    p:teleportTo(p:getTown():getTemplePosition())
    p:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
end

function onUse(player, item, frompos, item2, topos)
    local p = getPlayerFromArea()
    if not p then
        player:teleportTo(playerPos)
        player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
        Game.setStorageValue(storage,os.time()+areaTimer)
        item:transform(item.itemid == 1946 and 1945 or 1946)
        stopEvent(kickPlayer)
        addEvent(kickPlayer, areaTimer * 1000)
        return true
    end
    player:sendCancelMessage("A player is inside the area & has "..Game.getStorageValue(storage) - os.time().." seconds remaining")
    return true
end
 
Solution
Back
Top