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

Afk command

Mera Mero

Guess Who?
Joined
Dec 27, 2014
Messages
417
Reaction score
86
I've got problem with afk command which makes you to be afk in game if you switch it on , Now i'm trying to setconditionobject but i found some errors
Code:
local condition1 = createConditionObject(CONDITION_INFIGHT)
    local condition2 = createConditionObject(CONDITION_EXHAUST)
    local condition3 = createConditionObject(CONDITION_MUTED)
    setConditionParam(condition1, CONDITION_PARAM_TICKS, -1)
    setConditionParam(condition2, CONDITION_PARAM_TICKS, -1)
    setConditionParam(condition3, CONDITION_PARAM_TICKS, -1)
local time = 3    -- 1 = 1 sec, 2 = 2 sec, ...
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", TEXTCOLOR_ORANGE)
                 doSendMagicEffect(getPlayerPosition(cid), CONST_ME_MAGIC_BLUE)
             end
             say_events[getPlayerGUID(cid)] = addEvent(SayText, time * 1000 / 2, cid)      
         end                                                      
    end
    return TRUE
end
function onSay(cid, words, param, channel)
    if(param == '') then
      doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Command param required.")
     return true
     end
     if param == "on" then
        if isPlayer(cid) == TRUE then
            doSendAnimatedText(getPlayerPosition(cid),"AFK", TEXTCOLOR_ORANGE)
            doSendMagicEffect(getPlayerPosition(cid), CONST_ME_MAGIC_BLUE)
            createConditionObject(CONDITION_MUTED)
            createConditionObject(CONDITION_EXHAUST)
            createConditionObject(CONDITION_INFIGHT)
        end
        say_events[getPlayerGUID(cid)] = addEvent(SayText, time * 1000, cid)
        doPlayerSendTextMessage(cid,MESSAGE_STATUS_WARNING,"Afk mode is [ON].")
     elseif param == "off" then
            stopEvent(say_events[getPlayerGUID(cid)])
            say_events[getPlayerGUID(cid)] = nil
            doPlayerSendTextMessage(cid,MESSAGE_STATUS_WARNING,"Afk mode is [OFF].")
        doRemoveCondition(cid, CONDITION_INFIGHT)
        doRemoveCondition(cid, CONDITION_EXHAUST)
        doRemoveCondition(cid, CONDITION_MUTED)
    end
    return TRUE
end
and this is the erros appeared to me when i spelled !afk on
Code:
[08/03/2015 14:58:14] [Error - TalkAction Interface]
[08/03/2015 14:58:14] data/talkactions/scripts/custom/all/afk.lua:onSay
[08/03/2015 14:58:14] Description:
[08/03/2015 14:58:14] (luaCreateConditionObject) This function can only be used while loading the script.

[08/03/2015 14:58:15] [Error - TalkAction Interface]
[08/03/2015 14:58:15] data/talkactions/scripts/custom/all/afk.lua:onSay
[08/03/2015 14:58:15] Description:
[08/03/2015 14:58:15] (luaCreateConditionObject) This function can only be used while loading the script.

[08/03/2015 14:58:15] [Error - TalkAction Interface]
[08/03/2015 14:58:15] data/talkactions/scripts/custom/all/afk.lua:onSay
[08/03/2015 14:58:15] Description:
[08/03/2015 14:58:15] (luaCreateConditionObject) This function can only be used while loading the script.
 
Add the conditions with doAddCondition.
Code:
doAddCondition(cid, condition1)
But i still can walk with it? :S may you tell me which condition for do not able to move? if i make afk on? plus i can spell afk off without have afk on already :(
I need to use this command to make afk for player to not move him btw this command cannot use with combat and must be have afk on to be able to use afk off
 
Sorry but i don't know where can i past this one :( this is my exhausted.lua on lib
Code:
exhaustion =
{
    check = function (cid, storage)
        if(getPlayerFlagValue(cid, PLAYERFLAG_HASNOEXHAUSTION)) then
            return false
        end

        return getPlayerStorageValue(cid, storage) >= os.time(t)
    end,

    get = function (cid, storage)
        if(getPlayerFlagValue(cid, PLAYERFLAG_HASNOEXHAUSTION)) then
            return false
        end

        local exhaust = getPlayerStorageValue(cid, storage)
        if(exhaust > 0) then
            local left = exhaust - os.time(t)
            if(left >= 0) then
                return left
            end
        end

        return false
    end,

    set = function (cid, storage, time)
        setPlayerStorageValue(cid, storage, os.time(t) + time)
    end,

    make = function (cid, storage, time)
        local exhaust = exhaustion.get(cid, storage)
        if(not exhaust) then
            exhaustion.set(cid, storage, time)
            return true
        end

        return false
    end
}
 
You're not supposed to add anything there, it's just where this function is added.
Look at the part I posted, first 3 lines is to check if a player is still exhausted, last line is to set the exhaustion.
 
I have a working one :) May be posting it later if I find it @Mera Mero :)

Update:
@Mera Mero

This is my talkactions afk.lua:

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
 
Last edited:
Back
Top