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

[TFS 1.x] Run with CTRL (Advanced Version)

Colandus

Advanced OT User
Senator
Joined
Jun 6, 2007
Messages
2,434
Solutions
19
Reaction score
219
Location
Sweden
Hey. This code will allow GM's to run with CTRL. It has some special features too, unlike the regular ones.

Features
  • Ghost while running. Because I believe it looks ugly and not serious to run through walls in front of regular players, and also GM's running in general (in front of players), I made it ghost while you run and turn you back to normal as you stop. Will remain ghost if you stop in a wall or similar and return to normal once you leave it.
  • Smooth turning. If you have used a similar script, you know the turns are not smooth.
  • Throws you down roofs etc if you try to run out from it (but never below ground floor).

Only thing that could be better in my opinion is removing the "teleport" effect when the GM is shown again. This requires a very simple source edit and if you want to know how to do it, I can show you (if you know how to compile).


Installation

1. Open events/events.xml

Find method="onTurn" for class="Player" and set it to enabled="1". If you cannot find it then paste this:
XML:
<event class="Player" method="onTurn" enabled="1" />


2. Place this in events/scripts/player.lua
(Replace current onTurn if it's not used, or if it only has another version of a onLook-run script.)
Lua:
-- Used in onTurn.
local tempGhostPlayerEvents = tempGhostPlayerEvents or {}
local function removeGhost(cid)
    local player = Player(cid)
    if tempGhostPlayerEvents[cid] then
        if player then
            local tile = Tile(player:getPosition())
            if tile:hasFlag(TILESTATE_FLOORCHANGE) then
                tempGhostPlayerEvents[cid] = addEvent(removeGhost, 350, cid)
                return
            end

            local tileItems = tile:getItems() or {}
            table.insert(tileItems, tile:getGround())
         
            for _, item in ipairs(tileItems) do
                if item:hasProperty(CONST_PROP_BLOCKSOLID) then
                    tempGhostPlayerEvents[cid] = addEvent(removeGhost, 350, cid)
                    return
                end
            end
            player:setGhostMode(false, false)
        end

        tempGhostPlayerEvents[cid] = nil
    end
end

local playerLastTurn = playerLastTurn or {}
function Player:onTurn(direction)
    if not self:getGroup():getAccess() or self:getAccountType() < ACCOUNT_TYPE_GOD then
        return true
    end

    local lastTurn = playerLastTurn[self:getId()]
    if self:getDirection() ~= direction and (not lastTurn or os.mtime() - lastTurn > 200) then
        return true
    end

    local cid = self:getId()
    if not self:isInGhostMode() or tempGhostPlayerEvents[cid] then
        self:setGhostMode(true, false)
        stopEvent(tempGhostPlayerEvents[cid]) -- Stop previous event
        tempGhostPlayerEvents[cid] = addEvent(removeGhost, 350, self:getId())
    end

    playerLastTurn[self:getId()] = os.mtime()

    local pos = self:getPosition()
    pos:getNextPosition(direction)
    while not Tile(pos) and pos.z < 7 do
        pos.z = pos.z + 1
    end
    self:teleportTo(pos, true)

    return true
end
 
Last edited:
This uses a lot of resources when any player press ctrl + arrow (hold), and with a few players dancing you will notice the resource ussage, I recommend to disable onTurn.

Btw thanks for the idea.
 
This uses a lot of resources when any player press ctrl + arrow (hold), and with a few players dancing you will notice the resource ussage, I recommend to disable onTurn.

Btw thanks for the idea.
it doesn't use a lot of resources (if any)
only thing that the player would be doing when holding turn or dancing, is sending a bunch of small packets (14 bytes in size)
+ if you have packet limit in your server, this wouldn't matter anyways (even though it's such a small packet size, which you should be able to handle)
 
how much resources
are you talking about memory?

As integrated many custom functions, the server with 250+ players started to get lag, and the system that were using more memory was: onWalk, onTurn and the reward boss system the participation part on damage. The amount can't remember. But disabled them aND then was working pretty well.
 
Back
Top