• 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 talkaction tfs 1.3

Thorn

Spriting since 2013
Joined
Sep 24, 2012
Messages
2,203
Solutions
1
Reaction score
921
Location
Chile
Hello guy, im in need of an !afk script, wich when used, it auto messages: afk
:D plzz
 
Lua:
<talkaction words="!afk" separator=" " script="afk.lua"/>

Lua:
local config = {
    msg = 'AFK',
    interval = 3000, -- in ms, 1000 ms = 1 s
    storage = 12345 -- empty storage
}

local function sendAfkMessage(pid, startPos)
    local player = Player(pid)
    if not player then
        return
    end
   
    if player:getStorageValue(config.storage) ~= 1 then
        return
    end
   
    if player:getPosition() ~= startPos then
        return player:toggleAFK()
    end
   
    local dir = player:getDirection()
    player:setDirection(dir < 3 and dir + 1 or 0)
    player:say(config.msg, TALKTYPE_MONSTER_SAY)
return addEvent(sendAfkMessage, config.interval, player.uid, startPos)
end

function Player:toggleAFK()
    if self:getStorageValue(config.storage) ~= 1 then
        self:setStorageValue(config.storage, 1)
        self:sendCancelMessage('You have enabled AFK mode.')
        sendAfkMessage(self.uid, self:getPosition())
    else
        self:setStorageValue(config.storage, 0)
        self:sendCancelMessage('You have disabled AFK mode.')
    end
end

function onSay(player, words, param)
    player:toggleAFK()
    return false
end
 
Here you have a modification that does the same thing that was published here, but adds an extra mechanic which makes it so that nobody can move the player in AFK mode

data/scripts/afk.lua
Lua:
local config = {
    talkAction = "!afk",
    text = "AFK!",
    interval = 3000,
    storage = 9999,
    canPushAfkPlayers = false
}

function TalkLoopAfk(pid, startPos)
    local player = Player(pid)
    if player and player:getStorageValue(config.storage) == 1 then
        if startPos ~= player:getPosition() then
            return TalkToogleAfk(player)
        end

        player:say(config.text, TALKTYPE_MONSTER_SAY)
        local dir = player:getDirection()
        player:setDirection(dir < 3 and dir +1 or 0)
        addEvent(TalkLoopAfk, config.interval, pid, startPos)
    end
end

function TalkToogleAfk(player)
    if player:getStorageValue(config.storage) ~= -1 then
        player:setStorageValue(config.storage, -1)
        player:sendCancelMessage("You have disabled AFK mode.")
        return false
    end

    player:setStorageValue(config.storage, 1)
    player:sendCancelMessage("You have enabled AFK mode.")
    TalkLoopAfk(player:getId(), player:getPosition())
    return false
end

local talkAfk = TalkAction(config.talkAction)
talkAfk.onSay = TalkToogleAfk
talkAfk:register()

if not config.canPushAfkPlayers then
    local ec = EventCallback
    function ec.onMoveCreature(player, creature, fromPosition, toPosition)
        if creature:isPlayer() and not player:getGroup():getAccess() then
            if creature:getStorageValue(config.storage) ~= -1 then
                player:sendCancelMessage("You cannot move player that are AFK!")
                return false
            end
        end
        return true
    end
    ec:register(-1)
end
 
Last edited:
Here you have a modification that does the same thing that was published here, but adds an extra mechanic which makes it so that nobody can move the player in AFK mode

data/scripts/afk.lua
Lua:
local config = {
    talkAction = "!afk",
    text = "AFK!",
    interval = 3000,
    storage = 9999,
    canPushAfkPlayers = false
}

function TalkLoopAfk(pid, startPos)
    local player = Player(pid)
    if player and player:getStorageValue(config.storage) == 1 then
        if startPos ~= player:getPosition() then
            return TalkToogleAfk(player)
        end

        player:say(config.text, TALKTYPE_MONSTER_SAY)
        local dir = player:getDirection()
        player:setDirection(dir < 3 and dir +1 or 0)
        addEvent(TalkLoopAfk, config.interval, pid, startPos)
    end
end

function TalkToogleAfk(player)
    if player:getStorageValue(config.storage) ~= -1 then
        player:setStorageValue(config.storage, -1)
        player:sendCancelMessage("You have disabled AFK mode.")
        return false
    end

    player:setStorageValue(config.storage, 1)
    player:sendCancelMessage("You have enabled AFK mode.")
    TalkLoopAfk(player:getId(), player:getPosition())
    return false
end

local talkAfk = TalkAction(config.talkAction)
talkAfk.onSay = TalkToogleAfk
talkAfk:register()

if not config.canPushAfkPlayers then
    local ec = EventCallback
    function ec.onMoveCreature(player, creature, fromPosition, toPosition)
        if creature:isPlayer() and not player:getGroup():getAccess() then
            if creature:getStorageValue(config.storage) ~= -1 then
                player:sendCancelMessage("You cannot move player that are AFK!")
                return false
            end
        end
        return true
    end
    ec:register(-1)
end

Amazing script, I really like it! Provides good information for the times I really need to go afk.
By any chance can I request a minor modification?

The idea is, to add more messages to different parameters. For example: !afk 1, !afk 2, !afk 3.
This would allow me to insert different messages depending on the reason of why i'm afk.

Thanks in advance,
Regards!
 
Amazing script, I really like it! Provides good information for the times I really need to go afk.
By any chance can I request a minor modification?

The idea is, to add more messages to different parameters. For example: !afk 1, !afk 2, !afk 3.
This would allow me to insert different messages depending on the reason of why i'm afk.

Thanks in advance,
Regards!
How about instead of hard coding the messages, players can put any message? (note: not sure if line #22 has the correct arguments order)
!afk Went to pick up my food delivery
Lua:
local config = {
    talkAction = "!afk",
    prefix = "[AFK]: ",
    interval = 3000,
    storage = 9999,
    canPushAfkPlayers = false
}
function TalkLoopAfk(pid, startPos, param)
    local player = Player(pid)
    if player and player:getStorageValue(config.storage) == 1 then
        if startPos ~= player:getPosition() then
            return TalkToogleAfk(player)
        end
        player:say(config.prefix .. param, TALKTYPE_MONSTER_SAY)
        local dir = player:getDirection()
        player:setDirection(dir < 3 and dir + 1 or 0)
        addEvent(TalkLoopAfk, config.interval, pid, startPos)
    end
end
function TalkToogleAfk(player, words, param)
    if player:getStorageValue(config.storage) ~= -1 then
        player:setStorageValue(config.storage, -1)
        player:sendCancelMessage("You have disabled AFK mode.")
        return false
    end
    player:setStorageValue(config.storage, 1)
    player:sendCancelMessage("You have enabled AFK mode.")
    TalkLoopAfk(player:getId(), player:getPosition(), param)
    return false
end
local talkAfk = TalkAction(config.talkAction)
talkAfk.onSay = TalkToogleAfk
talkAfk:register()
if not config.canPushAfkPlayers then
    local ec = EventCallback
    function ec.onMoveCreature(player, creature, fromPosition, toPosition)
        if creature:isPlayer() and not player:getGroup():getAccess() then
            if creature:getStorageValue(config.storage) ~= -1 then
                player:sendCancelMessage("You cannot move player that are AFK!")
                return false
            end
        end
        return true
    end
    ec:register(-1)
end
 
Back
Top