• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua Add exhaustion onto command

Joriku

Working in the mines, need something?
Joined
Jul 16, 2016
Messages
1,175
Solutions
17
Reaction score
481
Location
Sweden
Hi,
I know this might not the the best thing to ask for but for you who's reading this. It might be as easy as writing the code as it is for me writing the therd.
I'm trying to add an exhaustion onto an !aol command, the script looks like this.
What I've seen,
if exhaustion.get(cid, 101)
But cannot manage to get it to work, any Ideas and any "solved solutions" can can be explained so I can manage to put it up myself?

LUA:
local price_aol = 0

function onSay(player, words, param)
    if player:removeMoney(price_aol) then
        player:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
        player:addItem(2173, 1)
    else
        if player:withdrawMoney(price_aol) then
            if player:removeMoney(price_aol) then
                player:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
                player:addItem(2173, 1)
            end
        else
            player:getPosition():sendMagicEffect(CONST_ME_POFF)
            player:sendCancelMessage("You don't have enought money. Not even in your bank!")
        end
    end

    return true
end
 
Solution
X
You could do it via lua tables I guess.

editing to add greentext

LUA:
local player_exhaust = {} -- table that will hold creatureid's and time. (might need to remove local from this line.. not sure.)
local exhaust_time = 5 -- seconds

local price_aol = 0

function onSay(player, words, param)

    local time, cid = os.time(), player:getId()

    if player_exhaust[cid] then -- check if anything has been added to table
        if time < player_exhaust[cid] then -- check time against what's in table.
            player:sendCancelMessage("You are exhausted.")
            return true
        end
    end
    player_exhaust[cid] = time + exhaust_time -- add / update information in table with new exhaust time
 
    if player:removeMoney(price_aol) then...
You could do it via lua tables I guess.

editing to add greentext

LUA:
local player_exhaust = {} -- table that will hold creatureid's and time. (might need to remove local from this line.. not sure.)
local exhaust_time = 5 -- seconds

local price_aol = 0

function onSay(player, words, param)

    local time, cid = os.time(), player:getId()

    if player_exhaust[cid] then -- check if anything has been added to table
        if time < player_exhaust[cid] then -- check time against what's in table.
            player:sendCancelMessage("You are exhausted.")
            return true
        end
    end
    player_exhaust[cid] = time + exhaust_time -- add / update information in table with new exhaust time
 
    if player:removeMoney(price_aol) then
        player:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
        player:addItem(2173, 1)
    else
        if player:withdrawMoney(price_aol) then
            if player:removeMoney(price_aol) then
                player:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
                player:addItem(2173, 1)
            end
        else
            player:getPosition():sendMagicEffect(CONST_ME_POFF)
            player:sendCancelMessage("You don't have enought money. Not even in your bank!")
        end
    end

    return true
end
 
Last edited by a moderator:
Solution
You could do it via lua tables I guess.

editing to add greentext

LUA:
local player_exhaust = {} -- table that will hold creatureid's and time. (might need to remove local from this line.. not sure.)
local exhaust_time = 5 -- seconds

local price_aol = 0

function onSay(player, words, param)

    local time, cid = os.time(), player:getId()

    if player_exhaust[cid] then -- check if anything has been added to table
        if time < player_exhaust[cid] then -- check time against what's in table.
            player:sendCancelMessage("You are exhausted.")
            return true
        end
    end
    player_exhaust[cid] = time + exhaust_time -- add / update information in table with new exhaust time

    if player:removeMoney(price_aol) then
        player:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
        player:addItem(2173, 1)
    else
        if player:withdrawMoney(price_aol) then
            if player:removeMoney(price_aol) then
                player:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
                player:addItem(2173, 1)
            end
        else
            player:getPosition():sendMagicEffect(CONST_ME_POFF)
            player:sendCancelMessage("You don't have enought money. Not even in your bank!")
        end
    end

    return true
end
This worked pretty well, didn't stop the command but it doesn't allow the item spam which was the whole issue.
Thanks alot, and that descs are just pure gold! It'll surley help me alot in future, thanks alot agin Xikini <3
 
Back
Top