• Sign up for TFS Icon Competition! The prize includes Otland Premium time and a medal, as well as obviously taking part in TFS history.
  • 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 put time on lever

flakerzokejao

Member
Joined
Aug 18, 2020
Messages
38
Reaction score
7
Lua:
--------------- NÃO MEXA ---------------
leverLib = {
    minPlayers = function(self) return #self.toPos end,
    maxPlayers = function(self) return #self.area end,
    onUse = function(self)
        local players = {}
        for i, pos in ipairs(self.area) do
            local player = getTopCreature(pos).uid
            if player and getPlayerLevel(player) >= self.minLevel and #players < self:maxPlayers() then
                table.insert(players, getCreatureName(player))
            end
        end
        if #players < self:minPlayers() then
            return false, "Não há jogadores suficiente"
        end
        table.sort(players, function(a,b)
            local fromPlayer = Player(a)
            local toPlayer = Player(b)
            if fromPlayer and toPlayer then
                return toPlayer:getLevel() > fromPlayer:getLevel()
            end
        end)
        local begin = true
        local str = ''
        for i, v in ipairs(players) do
            if not begin then
                str = str..', '
            else
                begin = false
            end
            str = str..v
            player = getPlayerByName(v)
            if player then
                doTeleportThing(player, self.toPos[i])
            end
        end
        setGlobalStorageValue("Boss", str)
        doCreateMonster(bossConfig.name, bossConfig.spawnPos)
        return true
    end,
}
----------------------------------------

function onUse(cid)
    local player = Player(cid)
    for x = bossConfig.area[1].x, bossConfig.area[2].x do
        for y = bossConfig.area[1].y, bossConfig.area[2].y do
            local pos = {x=x,y=y,z=bossConfig.area[2].z}
            local creature = getTopCreature(pos).uid
            if creature > 0 and isPlayer(creature) then
                player:sendTextMessage(27,"Há jogadores matando o boss no momento.")
                return
            end
        end
    end
    Lever = setmetatable(leverConfig, {__index = leverLib})
    local bool, msg = Lever:onUse()
    if not bool then
        player:sendTextMessage(27,msg)
        return bool
    end
    return true
end

I need time on the lever for each player who uses it has to wait 20 hours.
thank you
TFS 0.4 SERVER 8.60
 

aqubjukr

Well-Known Member
Joined
Mar 13, 2013
Messages
192
Solutions
16
Reaction score
70
Location
Paraná, Brazil
Just use storages to block access, like: (25000 = Storage Value)

Storage set after using lever:
Lua:
setPlayerStorageValue(cid, 25000, os.time() + 20 * 60 * 60)

Line to use the lever again:
Lua:
if getPlayerStorageValue(cid, 25000) < os.time() then
 
OP
flakerzokejao

flakerzokejao

Member
Joined
Aug 18, 2020
Messages
38
Reaction score
7
sorry I'm new to script could you tell me where to put it if you don't mind
Post automatically merged:

bump
 
Last edited:

Xikini

I whore myself out for likes
Senator
Joined
Nov 17, 2010
Messages
5,150
Solutions
311
Reaction score
3,268
Whoever scripted this needs to be shot.
It's super annoying to read, and seems to be using TFS 0.x scripting.. and also TFS 1.x scripting combined.
Everything about it is triggering me. lmao

I'm 90% certain this is where you'd want to apply it.
Lua:
--------------- NÃO MEXA ---------------
leverLib = {
    minPlayers = function(self) return #self.toPos end,
    maxPlayers = function(self) return #self.area end,
    onUse = function(self)
        local players = {}
        for i, pos in ipairs(self.area) do
            local player = getTopCreature(pos).uid
            if player and getPlayerLevel(player) >= self.minLevel and #players < self:maxPlayers() then
                table.insert(players, getCreatureName(player))
            end
        end
        if #players < self:minPlayers() then
            return false, "Não há jogadores suficiente"
        end
        table.sort(players, function(a,b)
            local fromPlayer = Player(a)
            local toPlayer = Player(b)
            if fromPlayer and toPlayer then
                return toPlayer:getLevel() > fromPlayer:getLevel()
            end
        end)
        local begin = true
        local str = ''
        for i, v in ipairs(players) do
            if not begin then
                str = str..', '
            else
                begin = false
            end
            str = str..v
            player = getPlayerByName(v)
            if player then
                doTeleportThing(player, self.toPos[i])
            end
        end
        setGlobalStorageValue("Boss", str)
        doCreateMonster(bossConfig.name, bossConfig.spawnPos)
        return true
    end,
}
----------------------------------------

function onUse(cid)
    local player, cur_time = Player(cid), os.time()
    if player:getStorageValue(25000) >= cur_time then
        player:sendTextMessage(27, "blah blah time")
        return true
    end
    for x = bossConfig.area[1].x, bossConfig.area[2].x do
        for y = bossConfig.area[1].y, bossConfig.area[2].y do
            local pos = {x=x,y=y,z=bossConfig.area[2].z}
            local creature = getTopCreature(pos).uid
            if creature > 0 and isPlayer(creature) then
                player:sendTextMessage(27,"Há jogadores matando o boss no momento.")
                return
            end
        end
    end
    Lever = setmetatable(leverConfig, {__index = leverLib})
    local bool, msg = Lever:onUse()
    if not bool then
        player:sendTextMessage(27,msg)
        return bool
    end
    player:setStorageValue(25000, cur_time + 20 * 60 * 60)
    return true
end
 
Top