Lua Dugeon Lever

zabuzo

Member
Joined
Jun 10, 2016
Messages
128
Reaction score
18
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
 

mackerel

Active Member
Joined
Apr 26, 2017
Messages
328
Reaction score
31
I did the first one, it seems like the easiest. See picture below on how to setup the x, y ranges and the centerPos variablees. It is just an area that it scans for players, so in your case it will be the room where the players are after teleporting. Make sure you cover the entire area (any tile the player can step on)

Lua:
local centerPos = Position(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

-- 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
    spectators = Game.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 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


36915
 
OP
zabuzo

zabuzo

Member
Joined
Jun 10, 2016
Messages
128
Reaction score
18
I did the first one, it seems like the easiest. See picture below on how to setup the x, y ranges and the centerPos variablees. It is just an area that it scans for players, so in your case it will be the room where the players are after teleporting. Make sure you cover the entire area (any tile the player can step on)

Lua:
local centerPos = Position(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

-- 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
    spectators = Game.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 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


View attachment 36915
THANK YOU

(X) 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
 

mackerel

Active Member
Joined
Apr 26, 2017
Messages
328
Reaction score
31
THANK YOU

(X) 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
You are welcome! Here; no 2.

Lua:
local centerPos = Position(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

-- 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
    spectators = Game.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 = {}
    for i = 1, #p do
        local pid = getTopCreature(p[i].player.position).uid   
        if isPlayer(pid) then
            local newIp = getPlayerIp(pid)
            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 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
 
Top