• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

Dungeon System [ 0.4 / 0.3.7 / 0.3.6 ]

  • Thread starter Thread starter Xikini
  • Start date Start date
Loving this, could someone add that when we enter it brings the party members? so you can enter as a team, or putting a limit, like there NEEDS to be 3-4 ppl
 
Great job, works

Is there any chance for multiplayer dungeon?

Like 3ppl inside etc?
 
Great job, works

Is there any chance for multiplayer dungeon?

Like 3ppl inside etc?
instead of movement script you can use lever to get 3 or 4 players position and teleport them all at a time - but you need to add some lua in action script for storages etc. and in creaturescript to count depends on storage.
hope this will help you.
 
Thanks for the contribution, I was going to create the code from scratch, it saved me a lot of time.
Rep+
 
@Xikini there's a way to put a boss after kill all monsters? And after kill boss, player will be able to get reward and leave dungeon.
 
@Xikini there's a way to put a boss after kill all monsters? And after kill boss, player will be able to get reward and leave dungeon.

LUA:
{ {0}, {}, -- area 1 start
    {   {x = 1111, y = 1111, z = 7},
        {x = 2222, y = 2222, z = 7},
        {x = 3333, y = 3333, z = 7}
    },
    {   {"rat", {x = 1111, y = 1111, z = 7}},
        {"rat", {x = 2222, y = 2222, z = 7}},
        {"rat", {x = 3333, y = 3333, z = 7}},
        {"rat", {x = 4444, y = 4444, z = 7}}  -- the last monster in the list will become the 'Boss'
    }
}, -- area 1 end
LUA:
--[[
    movements.xml
    <movevent type="StepIn" actionid="45001-45002" event="script" value="onStepIn_xikini_dungeon_system.lua"/>
--]]


local function dungeon_system_updater(cid, storage, timer, index, bossSpawned)
    if not isCreature(cid) then
        if cid == index[1][1] then
            index[1][1] = 0 -- if player dies or logs out, reset player data to indicate dungeon is empty.
        end
        return true
    end
    
    -- checks if the player is still inside the dungeon (so if player has completed dungeon but not yet left the dungeon, we can continue timer until auto-kick)
    local creature_pos = getPlayerPosition(cid)
    if creature_pos.x >= index[3][2].x and creature_pos.x <= index[3][3].x and creature_pos.y >= index[3][2].y and creature_pos.y <= index[3][3].y and creature_pos.z >= index[3][2].z and creature_pos.z <= index[3][3].z then
    else
        if cid == index[1][1] then
            index[1][1] = 0 -- if player leaves the dungeon, reset player data to indicate dungeon is empty.
        end
        return true
    end
    
    -- check if any monsters have died, and update player storage.
    local new_count = -1
    for i = #index[2], 1, -1 do
        if not isCreature(index[2][i]) then
            new_count = getPlayerStorageValue(cid, storage) - 1
            setPlayerStorageValue(cid, storage, new_count)
            table.remove(index[2], i)
        end
    end
    
    -- tell player that monsters have died.
    if new_count > 0 then
        local monster_count = #index[4]
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "You have killed [" .. (monster_count - new_count) .. " / " .. monster_count .."]")
    elseif new_count == 0 then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "You have killed all the creatures in this dungeon. Go open the chest for your reward.")
    end
    
    -- spawn boss
    if not bossSpawned and new_count == 1 then
        bossSpawned = true
        local boss = doCreateMonster(index[4][#index[4]][1], index[4][#index[4]][2])
        table.insert(index[2], boss)
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "Boss of this dungeon has been spawned! Slay them!")
    end
    
    -- timeout timer stuff
    timer = timer + 0.5 -- timer counts every 0.5 seconds, to check if player has run out of time.
    if timer < dungeon_system_config[storage].timeout then
        addEvent(dungeon_system_updater, 500, cid, storage, timer, index, bossSpawned)
    else
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "Out of time! You've been removed from the Dungeon.")
        doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
        setPlayerStorageValue(cid, storage, -1)
        index[1][1] = 0
    end
end

function onStepIn(cid, item, position, lastPosition, fromPosition, toPosition, actor)
    local storage = item.actionid
    local dungeon = dungeon_system_config[storage]
    if not dungeon then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "LUA ERROR: Contact Administrator. Error code: Xikini_1") -- actionid on tile is incorrect or not in table.
        return true
    end
    
    dungeon = dungeon.area_info -- re-using local when possible, to make script cleaner
    
    -- check if player is already in a dungeon, and teleport them out.
    for i = 1, #dungeon do
        if dungeon[i][1][1] == cid then
            local cur_storage = getPlayerStorageValue(cid, storage)
            if cur_storage == -1 then
                doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "Dungeon Completed Successfully.")
                return true
            else
                if cur_storage == 0 then
                    doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "You must collect your reward before exiting the dungeon.")
                else
                    doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "There is still " .. cur_storage .. " monsters that need to be killed in this dungeon.")
                end
                doTeleportThing(cid, fromPosition)
                return true
            end
        end
    end
    
    -- find a dungeon that is empty.
    local area = 0
    for i = 1, #dungeon do
        if not isCreature(dungeon[i][1][1]) then
            area = i
            break
        end
        local creature_pos = getPlayerPosition(dungeon[i][1][1])
        if creature_pos.x >= dungeon[i][3][2].x and creature_pos.x <= dungeon[i][3][3].x and creature_pos.y >= dungeon[i][3][2].y and creature_pos.y <= dungeon[i][3][3].y and creature_pos.z >= dungeon[i][3][2].z and creature_pos.z <= dungeon[i][3][3].z then
        else
            area = i
            break
        end                
    end
    
    -- if no dungeons empty
    if area == 0 then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "Sorry, no dungeons are empty. Try again later.")
        doTeleportThing(cid, fromPosition)
        return true
    end
    
    dungeon = dungeon[area]
    dungeon[1][1] = cid -- hold player data for later checking if dungeon is empty
    local monster_count = #dungeon[4]
    setPlayerStorageValue(cid, storage, monster_count) -- player storage is set as max monsters, and count down to 0 later.
    
    -- remove any monsters that are still alive in dungeon. (if a player died in the dungeon or timed out)
    for i = #dungeon[2], 1, -1 do
        if isCreature(dungeon[2][i]) then
            doRemoveCreature(dungeon[2][i])
        end
    end
    dungeon[2] = {}
    
    -- add all monsters into the dungeon, and store creatureids in table.
    for i = 1, monster_count - 1 do
        local monster = doCreateMonster(dungeon[4][i][1], dungeon[4][i][2])
        table.insert(dungeon[2], monster)
    end
    
    -- addEvent for timer and creature death tracking.
    addEvent(dungeon_system_updater, 500, cid, storage, 0, dungeon, false)
    doTeleportThing(cid, dungeon[3][1])
    return true
end
 
@Xikini Could we make it work for tfs 1.5 by nekiro? Im using the version with BOSS and I'm trying with chatgpt for like 5 hours. I succesfuly get teleported, kill monsters,get reward and get teleported to temple but it still gives those errors but I can activate the dungeon monster spawn by walking into the chest or exit pos and some monsters are spawning on invalid pos, also i cannot repeat the dungeon it says "Dungeon Completed Successfully." no matter if i go into exit pos or entry pos.
LUA:
2024-11-02_05-37-00.153762 Lua Script Error: [MoveEvents Interface]
2024-11-02_05-37-00.153941 data/movements/scripts/dungeon.lua:onStepIn
2024-11-02_05-37-00.154136 luaAddEvent(). Argument #3 is unsafe
2024-11-02_05-37-00.154167 stack traceback:
2024-11-02_05-37-00.154182      [C]: in function 'addEvent'
2024-11-02_05-37-00.154377      data/movements/scripts/dungeon.lua:135: in function <data/movements/scripts/dungeon.lua:63>
2024-11-02_05-37-04.609188
2024-11-02_05-37-04.609627 Lua Script Error: [MoveEvents Interface]
2024-11-02_05-37-04.609896 data/movements/scripts/dungeon.lua:onStepIn
2024-11-02_05-37-04.610077 attempt to index a nil value
2024-11-02_05-37-04.610107 stack traceback:
2024-11-02_05-37-04.610122      [C]: at 0x560875b64fc0
2024-11-02_05-37-04.610135      [C]: in function 'doTeleportThing'
2024-11-02_05-37-04.610328      data/movements/scripts/dungeon.lua:87: in function <data/movements/scripts/dungeon.lua:63>

Edit: I managed to get rid of Argument unsafe error. But i still encounter issue where stepping into the reward chest or exit pos teleports me into another area with the
LUA:
data/movements/scripts/dungeon.lua:87: in function <data/movements/scripts/dungeon.lua:63>
error. I guess there is some problems with handling one action id when i try to make it work in tfs 1.5
 
Last edited:
Back
Top