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

TFS 0.X [LUA] Svargrond Arena - Bug after jump in with GM

potinho

Advanced OT User
Joined
Oct 11, 2009
Messages
1,403
Solutions
17
Reaction score
151
Location
Brazil
Hello everyone, everything good? I'm using this @Gesior.pl Arena system, but I had a bug: When teleporting with the GM into the arena and trying to go to the next level, the players who came next to the arena bugged to go to the next teleport. Used system bellow:


Console error:
2022-07-18 17:57:23 - [Error - MoveEvents Interface]
2022-07-18 17:57:23 - data/movements/scripts/arenaroom.lua:eek:nStepIn
2022-07-18 17:57:23 - Description:
2022-07-18 17:57:23 - (luaDoCreateMonster) Monster with name '' not found
2022-07-18 18:02:03 -
2022-07-18 18:02:03 - [Error - MoveEvents Interface]
2022-07-18 18:02:03 - data/movements/scripts/arenaroom.lua:eek:nStepIn
2022-07-18 18:02:03 - Description:
2022-07-18 18:02:03 - data/movements/scripts/arenaroom.lua:16: attempt to compare number with string
2022-07-18 18:02:03 - stack traceback:
2022-07-18 18:02:03 - data/movements/scripts/arenaroom.lua:16: in function <data/movements/scripts/arenaroom.lua:1>

arenaroom.lua
Lua:
function onStepIn(cid, item, position, fromPosition)
    if InitArenaScript == 0 then
        InitArenaScript = 1
        -- make arena rooms free
        for i = 0,9 do
            setGlobalStorageValue(42300+i, 0)
            setGlobalStorageValue(42400+i, 0)
        end
        checkArenaRooms({})
    end
    local arena_room = item.actionid
    local player_arena = getPlayerStorageValue(cid, 42355)
    if getPlayerStorageValue(cid, arena_room+getPlayerStorageValue(cid, 42355)*10-1) == 1 or arena_room+getPlayerStorageValue(cid, 42355)*10-1 == 42299 then
        if getGlobalStorageValue(cid, arena_room) == 0 then
            local monster_uid = getGlobalStorageValue(arena_room+100)
            if monster_uid > 0 then
                if isCreature(monster_uid) == true then
                    doRemoveCreature(monster_uid)
                end
            end
            local spawn_pos = getThingPos(arena_room)
            local monster = doCreateMonster(arena_monsters[arena_room+getPlayerStorageValue(cid, 42355)*10], {x=spawn_pos.x-1,y=spawn_pos.y-1,z=spawn_pos.z})
            setGlobalStorageValue(arena_room+100, monster)
            doTeleportThing(cid, spawn_pos, true)
            setGlobalStorageValue(arena_room, cid)
            setGlobalStorageValue(arena_room-1, 0)
            setPlayerStorageValue(cid, 42350, os.time()+arena_room_max_time)
        else
            doTeleportThing(cid, fromPosition, true)
            doPlayerSendTextMessage(cid,MESSAGE_STATUS_CONSOLE_ORANGE,getCreatureName(getGlobalStorageValue(cid, arena_room))..' is now in next room. Wait a moment and try again.')
        end
    else
        doTeleportThing(cid, fromPosition, true)
        doPlayerSendTextMessage(cid,MESSAGE_STATUS_CONSOLE_ORANGE,'First kill monster!')
    end
    if arena_room == 42300 then
        setPlayerStorageValue(cid, 42351, 0)
        setPlayerStorageValue(cid, 42352, 1)
    end
    return true
end

function checkArenaRooms(param)
    addEvent(checkArenaRooms, 1000, {})
    for i = 42300, 42309 do
        local player = getGlobalStorageValue(i)
        if isPlayer(player) == true then
            local player_storage = getPlayerStorageValue(player, 42350)
            if player_storage <= os.time() then
                doTeleportThing(player, arenaKickPosition, true)
                setPlayerStorageValue(player, 42350, 0)
                setGlobalStorageValue(i, 0)
                doPlayerSendTextMessage(player,MESSAGE_STATUS_CONSOLE_ORANGE,'You have been kicked from arena! You have only ' .. arena_room_max_time .. ' seconds for one room.')
            elseif player_storage - 10 <= os.time() then
                doPlayerSendTextMessage(player,MESSAGE_EVENT_DEFAULT,'You have ' .. player_storage - os.time() .. ' seconds to go to the next room!')
            end
        else
            setGlobalStorageValue(i, 0)
        end
    end
end

Can u guys help me to fix?
 
I would rewrite it. It's 13 years old. There are soooo many new Lua functions available.
Thats a nice thing that u have done, seems work perfectly, just this bug i found.
Post automatically merged:

I would rewrite it. It's 13 years old. There are soooo many new Lua functions available.
Got another error:

One player was doing so when he jump in tp:

2022-07-18 21:07:11 - [Error - MoveEvents Interface]
2022-07-18 21:07:11 - data/movements/scripts/arenaroom.lua:eek:nStepIn
2022-07-18 21:07:11 - Description:
2022-07-18 21:07:11 - (luaDoCreateMonster) Cannot create monster: the pit lord

But i can summon this monster "The Pit Lord".

And then, he leaves and try again, in one tp he got:

2022-07-18 21:11:18 - [Error - MoveEvents Interface]
2022-07-18 21:11:18 - data/movements/scripts/arenaroom.lua:eek:nStepIn
2022-07-18 21:11:18 - Description:
2022-07-18 21:11:18 - data/movements/scripts/arenaroom.lua:16: attempt to compare number with string
2022-07-18 21:11:18 - stack traceback:
2022-07-18 21:11:18 - data/movements/scripts/arenaroom.lua:16: in function <data/movements/scripts/arenaroom.lua:1>
 
Last edited:
Other thing i've got:

When a player dies in arena and come back, script dont remove first monster, duplicating:

1658234130633.png
 
Other thing i noticed @Gesior.pl , after did all level arenas, if i say "hi, arena, yes", console returns error:

2022-07-29 15:04:53 - [Error - NpcScript Interface]
2022-07-29 15:04:53 - data/npc/scripts/arena.lua : onCreatureSay
2022-07-29 15:04:53 - Description:
2022-07-29 15:04:53 - data/npc/scripts/arena.lua:30: attempt to compare nil with number
2022-07-29 15:04:53 - stack traceback:
2022-07-29 15:04:53 - data/npc/scripts/arena.lua:30: in function 'callback'
2022-07-29 15:04:53 - data/npc/lib/npcsystem/keywordhandler.lua:42: in function 'processMessage'
2022-07-29 15:04:53 - data/npc/lib/npcsystem/keywordhandler.lua:177: in function 'processNodeMessage'
2022-07-29 15:04:53 - data/npc/lib/npcsystem/keywordhandler.lua:129: in function 'processMessage'
2022-07-29 15:04:53 - data/npc/lib/npcsystem/npchandler.lua:360: in function 'onCreatureSay'
2022-07-29 15:04:53 - data/npc/scripts/arena.lua:7: in function <data/npc/scripts/arena.lua:7>

npc arena.lua
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

function onCreatureAppear(cid)                npcHandler:onCreatureAppear(cid)            end
function onCreatureDisappear(cid)             npcHandler:onCreatureDisappear(cid)            end
function onCreatureSay(cid, type, msg)         npcHandler:onCreatureSay(cid, type, msg)    end
function onThink()                             npcHandler:onThink()                        end

function enterArena(cid, message, keywords, parameters, node)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
    local cost = 0
    local levelname = ''
    if getPlayerStorageValue(cid, 42355) < 1 then
        cost = 1000
        levelname = 'greenshore'
        levelneeded = 30
    elseif getPlayerStorageValue(cid, 42355) == 1 then
        cost = 50000
        levelname = 'scrapper'
        levelneeded = 200
    elseif getPlayerStorageValue(cid, 42355) == 2 then
        cost = 100000
        levelname = 'warlord'
        levelneeded = 400
    end
    if string.lower(keywords[1]) == 'yes' and parameters.prepare ~= 1 then
        if(getPlayerLevel(cid) >= levelneeded) then
            if(getPlayerMoney(cid) >= cost) then
                doPlayerRemoveMoney(cid, cost)
                npcHandler:say('Now you can go to test.', cid)
                setPlayerStorageValue(cid, 42351, 1)
            else
                npcHandler:say('You don\'t have ' .. cost .. ' gp! Come back when you will be ready!', cid)
            end
        else
            npcHandler:say('You don\'t have ' .. levelneeded .. ' level! Come back when you will be ready!', cid)
        end
        npcHandler:resetNpc()
    elseif string.lower(keywords[1]) == 'no' then
        npcHandler:say('Come back later then!', cid)
        npcHandler:resetNpc()
    else
        if getPlayerStorageValue(cid, 42355) < 3 then
            npcHandler:say('You test will be ' .. levelname .. ' level. If you want enter you must pay ' .. cost .. ' gp and have ' .. levelneeded .. ' level. Wanna try?', cid)
        else
            npcHandler:say('You did all arena levels.',cid)
        end
    end
    return true
end

npcHandler:setMessage(MESSAGE_GREET, 'Hello |PLAYERNAME|! Do you want to make arena?')

local yesNode = KeywordNode:new({'yes'}, enterArena, {})
local noNode = KeywordNode:new({'no'}, enterArena, {})

local node1 = keywordHandler:addKeyword({'arena'}, enterArena, {prepare=1})
    node1:addChildKeywordNode(yesNode)
    node1:addChildKeywordNode(noNode)
    
local node1 = keywordHandler:addKeyword({'fight'}, enterArena, {prepare=1})
    node1:addChildKeywordNode(yesNode)
    node1:addChildKeywordNode(noNode)
local node1 = keywordHandler:addKeyword({'yes'}, enterArena, {prepare=1})
    node1:addChildKeywordNode(yesNode)
    node1:addChildKeywordNode(noNode)
npcHandler:addModule(FocusModule:new())
 
Other thing i noticed @Gesior.pl , after did all level arenas, if i say "hi, arena, yes", console returns error:

2022-07-29 15:04:53 - [Error - NpcScript Interface]
2022-07-29 15:04:53 - data/npc/scripts/arena.lua : onCreatureSay
2022-07-29 15:04:53 - Description:
2022-07-29 15:04:53 - data/npc/scripts/arena.lua:30: attempt to compare nil with number
2022-07-29 15:04:53 - stack traceback:
2022-07-29 15:04:53 - data/npc/scripts/arena.lua:30: in function 'callback'
2022-07-29 15:04:53 - data/npc/lib/npcsystem/keywordhandler.lua:42: in function 'processMessage'
2022-07-29 15:04:53 - data/npc/lib/npcsystem/keywordhandler.lua:177: in function 'processNodeMessage'
2022-07-29 15:04:53 - data/npc/lib/npcsystem/keywordhandler.lua:129: in function 'processMessage'
2022-07-29 15:04:53 - data/npc/lib/npcsystem/npchandler.lua:360: in function 'onCreatureSay'
2022-07-29 15:04:53 - data/npc/scripts/arena.lua:7: in function <data/npc/scripts/arena.lua:7>

npc arena.lua
Above:
Lua:
if string.lower(keywords[1]) == 'yes' and parameters.prepare ~= 1 then
Add:
Lua:
    if levelname == '' then
        npcHandler:say('You did all arena levels.',cid)
        npcHandler:resetNpc()
        return true
    end
 
Above:
Lua:
if string.lower(keywords[1]) == 'yes' and parameters.prepare ~= 1 then
Add:
Lua:
    if levelname == '' then
        npcHandler:say('You did all arena levels.',cid)
        npcHandler:resetNpc()
        return true
    end
Works, thanks! How to remove monster from arena level if player die or leave?
 
Doesn't script remove it, when next player gets into arena?
It doesn't. Prevent player enter in arena if another is doing, but if the first player die or leave, just create another monster, up to 2, 3, etc...follow arenaroom.lua, no errors in console.

Lua:
function onStepIn(cid, item, position, fromPosition)
    if InitArenaScript == 0 then
        InitArenaScript = 1
        -- make arena rooms free
        for i = 0,9 do
            setGlobalStorageValue(42300+i, 0)
            setGlobalStorageValue(42400+i, 0)
        end
        checkArenaRooms({})
    end
    local arena_room = item.actionid
    local player_arena = getPlayerStorageValue(cid, 42355)
    if getPlayerStorageValue(cid, arena_room+getPlayerStorageValue(cid, 42355)*10-1) == 1 or arena_room+getPlayerStorageValue(cid, 42355)*10-1 == 42299 then
        if getGlobalStorageValue(cid, arena_room) == 0 then
            local monster_uid = getGlobalStorageValue(arena_room+100)
            if not monster_uid then
                if isCreature(monster_uid) == true then
                    doRemoveCreature(monster_uid)
                end
            end
            local spawn_pos = getThingPos(arena_room)
            local monster = doCreateMonster(arena_monsters[arena_room+getPlayerStorageValue(cid, 42355)*10], {x=spawn_pos.x-1,y=spawn_pos.y-1,z=spawn_pos.z})
            setGlobalStorageValue(arena_room+100, monster)
            doTeleportThing(cid, spawn_pos, true)
            setGlobalStorageValue(arena_room, cid)
            setGlobalStorageValue(arena_room-1, 0)
            setPlayerStorageValue(cid, 42350, os.time()+arena_room_max_time)
        else
            doTeleportThing(cid, fromPosition, true)
            doPlayerSendTextMessage(cid,MESSAGE_STATUS_CONSOLE_ORANGE,getCreatureName(getGlobalStorageValue(cid, arena_room))..' is now in next room. Wait a moment and try again.')
        end
    else
        doTeleportThing(cid, fromPosition, true)
        doPlayerSendTextMessage(cid,MESSAGE_STATUS_CONSOLE_ORANGE,'First kill monster!')
    end
    if arena_room == 42300 then
        setPlayerStorageValue(cid, 42351, 0)
        setPlayerStorageValue(cid, 42352, 1)
    end
    return true
end

function checkArenaRooms(param)
    addEvent(checkArenaRooms, 1000, {})
    for i = 42300, 42309 do
        local player = getGlobalStorageValue(i)
        if isPlayer(player) == true then
            local player_storage = getPlayerStorageValue(player, 42350)
            if player_storage <= os.time() then
                doTeleportThing(player, arenaKickPosition, true)
                setPlayerStorageValue(player, 42350, 0)
                setGlobalStorageValue(i, 0)
                doPlayerSendTextMessage(player,MESSAGE_STATUS_CONSOLE_ORANGE,'You have been kicked from arena! You have only ' .. arena_room_max_time .. ' seconds for one room.')
            elseif player_storage - 10 <= os.time() then
                doPlayerSendTextMessage(player,MESSAGE_EVENT_DEFAULT,'You have ' .. player_storage - os.time() .. ' seconds to go to the next room!')
            end
        else
            setGlobalStorageValue(i, 0)
        end
    end
end

1659186097804.png
 
Last edited:
What engine are you using? TFS 0.4?

I don't know where you get that arena script.
Replace:
Lua:
            local monster_uid = getGlobalStorageValue(arena_room+100)
            if not monster_uid then
with (code from my post):
Lua:
            local monster_uid = getGlobalStorageValue(arena_room+100)
            if monster_uid > 0 then
Right now it tries to remove monster, when it does not find it in globalStorage (never? as storage always return number or string, both are always true).
 
What engine are you using? TFS 0.4?

I don't know where you get that arena script.
Replace:
Lua:
            local monster_uid = getGlobalStorageValue(arena_room+100)
            if not monster_uid then
with (code from my post):
Lua:
            local monster_uid = getGlobalStorageValue(arena_room+100)
            if monster_uid > 0 then
Right now it tries to remove monster, when it does not find it in globalStorage (never? as storage always return number or string, both are always true).
Using OTX 2 (based on 0.3.7). I changed this line because the first error on thread:

Thread '[LUA] Svargrond Arena - Bug after jump in with GM' TFS 0.X - [LUA] Svargrond Arena - Bug after jump in with GM (https://otland.net/threads/lua-svargrond-arena-bug-after-jump-in-with-gm.281719/)
Post automatically merged:

When i changed lines u said, the first error stopped
Post automatically merged:

What engine are you using? TFS 0.4?

I don't know where you get that arena script.
Replace:
Lua:
            local monster_uid = getGlobalStorageValue(arena_room+100)
            if not monster_uid then
with (code from my post):
Lua:
            local monster_uid = getGlobalStorageValue(arena_room+100)
            if monster_uid > 0 then
Right now it tries to remove monster, when it does not find it in globalStorage (never? as storage always return number or string, both are always true).
Give this error randomly, but always after some players do arena:

Console error:
[Error - MoveEvents Interface]
data/movements/scripts/arenaroom.lua:eek:nStepIn
escription:
(luaDoCreateMonster) Monster with name '' not found
Error - MoveEvents Interface]
data/movements/scripts/arenaroom.lua:eek:nStepIn
Description:
data/movements/scripts/arenaroom.lua:16: attempt to compare number with string
stack traceback:
data/movements/scripts/arenaroom.lua:16: in function <data/movements/scripts/arenaroom.lua:1>
 
Last edited:
Back
Top