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

Lua Dugeon Lever

zabuzo

Well-Known Member
Joined
Jun 10, 2016
Messages
238
Reaction score
54
I want to make a full server based in dugeons but idk how to do the lever system, so i need some help

I made this scripts by searching and copy from others scripts, i need 4 things that i asked in comments -- how to
So just ctrl+f in scripts "-- how to" in scripts
My questions are in the code
-- 1 how to: if there is a team doing players cant go in
-- 2 how to: only accept different IPs
-- 3 how to: after enter have 15 min to do a quest, if dont teleport to 956/1039/7
-- 4 how to: after go in have a exausted of 24 hours to go again

Even help with 1 would help a lot

dungeon_lever.lua
Code:
-- positions and where go
local p = {
    [1] = {
        player = {
            position = {x = 952, y = 1039, z = 7},
            toPos = {x = 953, y = 1047, z = 6}
        }
    },
    [2] = {
        player = {
            position = {x = 953, y = 1039, z = 7},
            toPos = {x = 954, y = 1047, z = 6}
        }
    },
    [3] = {
        player = {
            position = {x = 954, y = 1039, z = 7},
            toPos = {x = 955, y = 1047, z = 6}
        }
    },
    [4] = {
        player = {
            position = {x = 955, y = 1039, z = 7},
            toPos = {x = 956, y = 1047, z = 6}
        }
    }
}

-- min lvl
local minLevel = 10
local maxLevel = 20

-- get a vocation's base vocation
function getBaseVocation(vocation)
    if vocation >= 5 and vocation <= 8 then
        return vocation - 4
    elseif vocation >= 9 and vocation <= 12 then
        return vocation - 8
    end
    return vocation
end

-- 3 how to: after enter have 15 min to do a quest, if dont teleport to 956/1039/7


function onUse(cid)
    -- 1 how to: if there is a team doing players cant go in
    -- 2 how to: only accept different IPs
    local questPlayers = {}
    for i = 1, #p do
        local pid = getTopCreature(p[i].player.position).uid
        if isPlayer(pid) then
            if getPlayerLevel(pid) >= minLevel and getPlayerLevel(pid) <= maxLevel then
                if getBaseVocation( getPlayerVocation(pid) ) == i then
                    -- 3 how to: remove tile per vocation, only accept if have 4 vocation, but dosent matter the position
                else
                    doPlayerSendCancel(cid, "A vocation is on the wrong spot.")
                    return false
                end
            else
                doPlayerSendCancel(cid, getCreatureName(pid) .. ", is not high enough in level, the level to enter have to be between " .. minLevel .. "~ " .. maxLevel .. ". ")
                return false
            end
        else
            doPlayerSendCancel(cid, "A player is missing.")
            return false
        end
    end
    for x = 1, #questPlayers do
        -- 4 how to: after go in have a exausted of 24 hours to go again
        doPlayerSendTextMessage(questPlayers[x], MESSAGE_INFO_DESCR, "Good luck!")
        doTeleportThing(questPlayers[x], p[x].player.toPos)
    end
    return true
end
 
Solution
Code:
[13:17:05.067] [Error - Action Interface]
[13:17:05.067] data/actions/scripts/dungeon_lever.lua:onUse
[13:17:05.067] Description:
[13:17:05.067] data/actions/scripts/dungeon_lever.lua:53: attempt to index global 'Game' (a nil value)
[13:17:05.067] stack traceback:
[13:17:05.067]     data/actions/scripts/dungeon_lever.lua:53: in function <data/actions/scripts/dungeon_lever.lua:51>

[13:17:06.305] [Error - Action Interface]
[13:17:06.305] data/actions/scripts/dungeon_lever.lua:onUse
[13:17:06.305] Description:
[13:17:06.305] data/actions/scripts/dungeon_lever.lua:53: attempt to index global 'Game' (a nil value)
[13:17:06.305] stack traceback:
[13:17:06.305]     data/actions/scripts/dungeon_lever.lua:53: in function...
Violating Rules of Otland (2. Spamming / Double post)
lets fix it:

Lua:
local kickTo = {x = 956, y = 1039, z = 7} -- kick players after 15 minutes to this position
local centerPos = {x = 1000, y = 1000, z = 7}
local xRange = 5
local yRange = 4

-- positions and where go
local p = {
    [1] = {
        player = {
            position = {x = 952, y = 1039, z = 7},
            toPos = {x = 953, y = 1047, z = 6}
        }
    },
    [2] = {
        player = {
            position = {x = 953, y = 1039, z = 7},
            toPos = {x = 954, y = 1047, z = 6}
        }
    },
    [3] = {
        player = {
            position = {x = 954, y = 1039, z = 7},
            toPos = {x = 955, y = 1047, z = 6}
        }
    },
    [4] = {
        player = {
            position = {x = 955, y = 1039, z = 7},
            toPos = {x = 956, y = 1047, z = 6}
        }
    }
}

-- min lvl
local minLevel = 10
local maxLevel = 20

-- 3 how to: after enter in the dungeon, have 15 min to open the chest, if dont teleport to 956/1039/7
local function kickPlayers(players)
    local spectators = getSpectators(centerPos, false, true, 0, xRange, 0, yRange)
    for _, spec in ipairs(spectators) do
        local specName = getPlayerName(spec)
        for _, player in ipairs(players) do
            if getPlayerName(player) == specName then
                doTeleportThing(spec, kickTo, false)
            end
        end
    end
end

function onUse(cid)
    -- 1 how to: if there is a team doing players cant go in
    local spectators = getSpectators(centerPos, false, true, 0, xRange, 0, yRange)
    for _, player in ipairs(spectators) do
        doPlayerSendCancel(cid, "There are still remaining players in the room.")
        return false
    end

    -- 2 how to: only accept different IPs
    local ipAddress = {}
    local questPlayers = {}
    local oldPlayers = {}
    local SORCERER, DRUID, PALADIN, KNIGHT = false, false, false, false

    for i = 1, #p do
        local pid = getTopCreature(p[i].player.position).uid  
        if isPlayer(pid) then
            local voc = getPlayerVocation(pid)
            if voc == 1 or voc == 5 or voc == 9 then
                SORCERER = true
            elseif voc == 2 or voc == 6 or voc == 10 then
                DRUID = true
            elseif voc == 3 or voc == 7 or voc == 11 then
                PALADIN = true
            elseif voc == 4 or voc == 8 or voc == 12 then
                KNIGHT = true
            end
           
            local newIp = getPlayerIp(pid)
            if getPlayerStorageValue(pid, 5824) >= os.time() then
                local exaustedMins = math.ceil(((getPlayerStorageValue(cid, 5824)) - os.time())/60)
                doPlayerSendCancel(cid, getPlayerName(pid) .. " have to wait " .. exaustedMins .. " minutes to do this dugeon again.")
                return false
            end

            for _, ip in ipairs(ipAddress) do
                if newIp == ip then
                    doPlayerSendCancel(cid, "Players with the same IP address detected.")
                    return false
                end
            end
            ipAddress[#ipAddress + 1] = newIp
           
            if not getPlayerLevel(pid) >= minLevel and not getPlayerLevel(pid) <= maxLevel then
                doPlayerSendCancel(cid, getCreatureName(pid) .. ", is not high enough in level, the level to enter have to be between " .. minLevel .. "~ " .. maxLevel .. ". ")
                return false
            end
            oldPlayers[#oldPlayers + 1] = pid
        else
            doPlayerSendCancel(cid, "A player is missing.")
            return false
        end
    end
   
    if SORCERER == false or DRUID == false or PALADIN == false or KNIGHT == false then
        doPlayerSendCancel(cid, "Four different vocations are required.")
        return false
    end
   
    for x = 1, #questPlayers do
        -- 4 how to: after go in have a exausted of 24 hours to go again
        setPlayerStorageValue(questPlayers[x], 5824, os.time() + 86400)
        doPlayerSendTextMessage(questPlayers[x], MESSAGE_INFO_DESCR, "Good luck!")
        doTeleportThing(questPlayers[x], p[x].player.toPos)
    end
   
    addEvent(kickPlayers, 900000, oldPlayers)
    return true
end

fyi; the code is not complete. There are some unused parts such as questPlayers. I didn't touch it because that wasn't requested

Code:
[11:10:23.345] [Error - Action Interface] 
[11:10:23.345] data/actions/scripts/dungeon_lever.lua:onUse
[11:10:23.345] Description: 
[11:10:23.345] attempt to index a number value
[11:10:23.345] stack traceback:
[11:10:23.345]     [C]: in function 'getSpectators'
[11:10:23.345]     data/actions/scripts/dungeon_lever.lua:53: in function <data/actions/scripts/dungeon_lever.lua:51>

bump

guys?
 
Back
Top