• 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 Afk Status

Aleada

Unknown Member
Joined
Mar 14, 2013
Messages
231
Reaction score
7
Heya everyone, I'm trying to make a script that indicates you're afk when you declare it. It will also show the message you want to display every interval on the specified time:

Code:
function onSay(cid, words, param, channel)
local interval = 5
local words = ""
local pos = getPlayerPosition(cid)

    if(param == '') then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Why are you going AFK?")
        return true
    elseif(param == 'off') then
        if (getPlayerStorageValue(cid, 9876) == 1) then
            doSendAnimatedText(getPlayerPosition(cid), "I'm back!", 200)
            setPlayerStorageValue(cid, 9876, 0)
        else
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You weren't ever AFK")
        end
    else
        if (getPlayerStorageValue(cid, 9876) == 0) then
            words = param
            doSendAnimatedText(getPlayerPosition(cid), "Brb!", 200)
            setPlayerStorageValue(cid, 9876, 1)
        else
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You are already AFK")
        end
    end
   
    while (getPlayerStorageValue(cid, 9876) == 1) do
        doSendAnimatedText(getPlayerPosition(cid), words, 200)
        pause(time*1000)
    end
    return true
end

The only thing is at line 28, I don't know how to make a wait/pause in LUA :/
If anyone can help, that'd be great! :D Thank you!
 
i'm feeling sleepy right now , but i can give you an afk script and you should compare :D
Code:
local time = 3 -- Seconds
local say_events = {}
local function SayText(cid)
    if isPlayer(cid) == TRUE then
        if say_events[getPlayerGUID(cid)] ~= nil then
            if isPlayer(cid) == TRUE then
                doSendAnimatedText(getPlayerPosition(cid),"AFK", math.random(01,255))
            end
            say_events[getPlayerGUID(cid)] = addEvent(SayText, time * 1000 / 2, cid)     
        end                                                     
    end
    return TRUE
end
local storage = 38417
function onSay(cid, words, param, channel)
local afkCheck = getPlayerStorageValue(cid, storage)
    if(param == "") then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Command param required.")
    return TRUE
    end
    if (param == "on") then
        if (afkCheck == -1) then
            if (isPlayer(cid) == TRUE) then
                doSendAnimatedText(getPlayerPosition(cid),"AFK", math.random(01,255))
            end
            say_events[getPlayerGUID(cid)] = addEvent(SayText, time * 1000, cid)
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "You are now AFK.")
            doCreatureSetNoMove(cid, true)
            setPlayerStorageValue(cid, storage, 1)
        else
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You are already AFK.")
        end
    elseif (param == "off") then
        stopEvent(say_events[getPlayerGUID(cid)])
        say_events[getPlayerGUID(cid)] = nil
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "Welcome Back!")
        doCreatureSetNoMove(cid, false)
        setPlayerStorageValue(cid, storage, -1)
    end
    return TRUE
end
 
Yeah that's the one I'm trying to base it off of just re-write it but with the "addevent" I couldn't get it to pass the "words/param" over :/

------------ Edit --------------

Woot! Thank you! I figured it out! :D
Here's the code if anyone wants to use it :)
Code:
local interval = 5
local array = {}

local function AfkText(cid)
    if array[1] ~= nil then
        doSendAnimatedText(getPlayerPosition(cid), array[2] , math.random(175,215))
        array[1] = addEvent(AfkText, interval * 1000, cid)  
    end
end

function onSay(cid, words, param, channel)
    if(param == '') then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Include AFK Reason")
        return true
    elseif(param == 'off') then
        if (getPlayerStorageValue(cid, 9876) == 1) then
            doSendAnimatedText(getPlayerPosition(cid), "I'm back!", 200)
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Welcome back")
            stopEvent(array[1])
            array[1] = nil
            setPlayerStorageValue(cid, 9876, 0)
        else
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You weren't ever AFK")
        end
    else
        if (getPlayerStorageValue(cid, 9876) == 0) then
            array[2] = param
            doSendAnimatedText(getPlayerPosition(cid), "Brb!", 200)
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "AFK Reason: " .. array[2])
            array[1] = addEvent(AfkText, interval * 1000 / 2, cid)
            setPlayerStorageValue(cid, 9876, 1)
        else
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You are already AFK")
        end
    end
    return true
end

I'll still have to change it up but it still works :D
 
Last edited:
Back
Top