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

Lua do not move or push !afk

darkmu

Well-Known Member
Joined
Aug 26, 2007
Messages
274
Solutions
1
Reaction score
50
Location
Paraná,Brazil
Recently I got this script from the forum, but I would like to know if it is possible to adapt it so that I cannot move or be pulled, can someone help me?


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)
    mayNotMove(player,true)
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
 
Solution
tfs 1.3 doesn't have the mayNotMove function by @kor , so you will need to add the following:


and use:
player:setMovementBlocked(true)
Less efficient but i have 2 ways to do this, you can do speed = 0 so player can't move pushed or even if afk is activated (he should be AFK), another way that i'am not sure if it will work
<event class="Player" method="onMoveCreature" enabled="0" />
can enable this and in player.lua under the function onMoveCreature add
Lua:
if creature:isAfk() then -- or creature:getStorageValue(X) X is the storage for AFK effect to appear
  --not sure if it needs a function to return to the same position
  return false
end
 
Less efficient but i have 2 ways to do this, you can do speed = 0 so player can't move pushed or even if afk is activated (he should be AFK), another way that i'am not sure if it will work
<event class="Player" method="onMoveCreature" enabled="0" />
can enable this and in player.lua under the function onMoveCreature add
Lua:
if creature:isAfk() then -- or creature:getStorageValue(X) X is the storage for AFK effect to appear
  --not sure if it needs a function to return to the same position
  return false
end
speed 0 they can still be pushed, it will just happen more slowly 😁 but yeah the onMovecreature should work too
 
Back
Top