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

TalkAction [GM] /stalk player

Colandus

Advanced OT User
Senator
Joined
Jun 6, 2007
Messages
2,434
Solutions
19
Reaction score
219
Location
Sweden
This command will allow GM's to easier follow other players as they walk around the map.

Usage:
  • /stalk Colandus (enable stalking on player Colandus)
  • /stalk stop (stop stalking)
In data/talkactions/talkactions.xml add:
XML:
<talkaction words="/stalk" script="stalk.lua" separator=" " />

In data/talkactions/scripts create a file called stalk.lua:
Lua:
STALKED_PLAYERS = STALKED_PLAYERS or {}
STALKING_ACTIVE = STALKING_ACTIVE or false

local function stalkPlayer(player, target)
    if player and not target then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'Stalked player lost.')
        return false
    end

    if not player then
        return false
    end

    if not player:getPathTo(target:getPosition()) then
        player:teleportTo(target:getPosition())
    end

    if player:getFollowCreature() ~= target then
        player:setFollowCreature(target)
    end
    return true
end

local function stalkPlayers()
    local stalkingActive = false
    for playerId, targetId in pairs(STALKED_PLAYERS) do
        local stalkSuccess = stalkPlayer(Player(playerId), Player(targetId))
        if not stalkSuccess then
            STALKED_PLAYERS[playerId] = nil
        end
        stalkingActive = stalkingActive or stalkSuccess
    end

    STALKING_ACTIVE = stalkingActive

    if STALKING_ACTIVE then
        addEvent(stalkPlayers, 500)
    end
end

function onSay(player, words, param)
    if not player:getGroup():getAccess() then
        return true
    end

    if param == 'stop' then
        if not STALKED_PLAYERS[player:getId()] then
            return false
        end

        local target = Player(STALKED_PLAYERS[player:getId()])
      
        STALKED_PLAYERS[player:getId()] = nil
        player:setFollowCreature(nil)

        if target then
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You are no longer stalking ' .. target:getName() .. '.')
        end
        return false
    end

    local target = Player(param)
    if not target then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'Player not found.')
        return false
    end

    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You are now stalking ' .. target:getName() .. '.')
    if not player:isInGhostMode() then
        player:setGhostMode(true)
    end

    STALKED_PLAYERS[player:getId()] = target:getId()

    if not STALKING_ACTIVE then
        STALKING_ACTIVE = true
        stalkPlayers()
    end

    return false
end

Have fun stalking your players!
 
Last edited:
very good, I have a similar script that I created but yours is much better, mine kept teleporting to the player.
Just one question: if in the square where the god is invisible the player tries to USE an item, for example, it's not possible, any light on how to solve this?
 
very good, I have a similar script that I created but yours is much better, mine kept teleporting to the player.
Just one question: if in the square where the god is invisible the player tries to USE an item, for example, it's not possible, any light on how to solve this?
I made a fix for the bug you mention today and it works in the few test cases I made. If you know how to compile I can PM you the instructions for the fix. (If anyone needs the fix, please PM me and don't ask about it in this thread, you will need to compile on your own, I won't do that for you)
 
Tip:
Add this to your /t /goto /up /down /a /town to make sure stalk is automatically cancelled when using those commands:
Lua:
STALKED_PLAYERS[player:getId()] = nil

This could however bug a bit if your new position is next to the old stalked player as it will still have follow on them. So a solution could be to add this function somewhere and call it instead:
Lua:
function Player:stopStalk()
    STALKED_PLAYERS[self:getId()] = nil
    self:setFollowCreature(nil)
end
 
Last edited:
Back
Top