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

RevScripts How to add Exhaustion to this talkaction?

Hyagosrs

Member
Joined
Mar 10, 2018
Messages
88
Solutions
1
Reaction score
9
How to add exshaut to this talkaction !online? revscriptsys


Lua:
local maxPlayersPerMessage = 10
local playersOnline = TalkAction("!online")

function playersOnline.onSay(player, words, param)   
    local hasAccess = player:getGroup():getAccess()
    local players = Game.getPlayers()
    local onlineList = {}

    for _, targetPlayer in ipairs(players) do
        if hasAccess or not targetPlayer:isInGhostMode() then
            table.insert(onlineList, ("%s [%d]"):format(targetPlayer:getName(), targetPlayer:getLevel()))
        end
    end

    local playersOnlineList = #onlineList
    player:sendTextMessage(MESSAGE_ATTENTION, ("%d players online!"):format(playersOnlineList))

    for i = 1, playersOnlineList, maxPlayersPerMessage do
        local j = math.min(i + maxPlayersPerMessage - 1, playersOnlineList)
        local msg = table.concat(onlineList, ", ", i, j) .. "."
        player:sendTextMessage(MESSAGE_ATTENTION, msg)
    end
    return false
end

playersOnline:register()
 
Solution
Lua:
if player:getStorageValue(52523) >= os.time() then
   player:sendCancelMessage("You cant use it now")
   return true
end
  
player:setStorageValue(52523, os.time() + 10) -- 10 means 10 seconds
For short timers like this, I prefer to use a table instead of a storage value
Both methods have their ups/downs. xP
Lua:
-- outside of main function
local exhaust = {}
local exhaustTime = 10 -- seconds

-- inside function
local playerId = player:getId()
local currentTime = os.time()
if exhaust[playerId] and exhaust[playerId] > currentTime then
    player:sendCancelMessage("This command is still on cooldown. (S:" .. exhaust[playerId] - currentTime .. ")")
    return true
end
exhaust[playerId] = currentTime + exhaustTime

Levi999x

AoT
Joined
Dec 14, 2017
Messages
1,868
Solutions
37
Reaction score
1,083
Location
Germany
Lua:
if player:getStorageValue(52523) >= os.time() then
   player:sendCancelMessage("You cant use it now")
   return true
end
    
player:setStorageValue(52523, os.time() + 10) -- 10 means 10 seconds
 

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,803
Solutions
431
Reaction score
3,935
Lua:
if player:getStorageValue(52523) >= os.time() then
   player:sendCancelMessage("You cant use it now")
   return true
end
  
player:setStorageValue(52523, os.time() + 10) -- 10 means 10 seconds
For short timers like this, I prefer to use a table instead of a storage value
Both methods have their ups/downs. xP
Lua:
-- outside of main function
local exhaust = {}
local exhaustTime = 10 -- seconds

-- inside function
local playerId = player:getId()
local currentTime = os.time()
if exhaust[playerId] and exhaust[playerId] > currentTime then
    player:sendCancelMessage("This command is still on cooldown. (S:" .. exhaust[playerId] - currentTime .. ")")
    return true
end
exhaust[playerId] = currentTime + exhaustTime
 
Solution

Ramon Bernardo

Active Member
Joined
Oct 7, 2018
Messages
88
Solutions
2
Reaction score
47
@Xikini vgood!
  • storage: for times that cannot be missed, such 1-day delay.
  • table: for times that might be lost when restarting server, such as using !online cmd with 5s delay
 
Top