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

Action [TFS 1.X] Train/Ore Wagon System

Apollos

Dude who does stuff
Joined
Apr 22, 2009
Messages
829
Solutions
123
Reaction score
655
Location
United States
Features:
  • Set your own speed of wagon
  • Option to prohibit player from leaving track during transit
  • Goes up and down stairs/holes
  • Supports multiple uses at the same time
Credit to @Mock for the inspiration to rewrite my own version.

35811

Notes:
  • Using loops in track may cause infinite looping
  • Does not support tracks with more than two possible directions
  • Will not work if id of wagons are not 7131 and 7132
  • If you use TFS 1.2 and would like to use setNoMove then implement this system: setNoMove(bool)
  • If you use TFS 1.3 and would like to use setNoMove then implement from PDF attached at bottom of thread
data/actions/actions.xml
XML:
<action actionid="ACTIONID_OF_WAGON" script="other/ore_wagon.lua" />

data/actions/scripts/other/ore_wagon.lua
Lua:
local config = {
    move_interval = 200, -- milliseconds until next movement (used in addEvent)
    no_move = false -- stop players from moving off of track
}

local condition = Condition(CONDITION_OUTFIT)
condition:setTicks(-1)

local rails = {
    [7121] = {NORTH, SOUTH}, [7122] = {EAST, WEST}, [7123] = {EAST, SOUTH},
    [7124] = {WEST, SOUTH}, [7125] = {NORTH, EAST}, [7126] = {NORTH, WEST},
}

local previous = {} -- DO NOT CHANGE

function onMoveWagon(cid)
    local player = Player(cid)
    if not player then previous[cid] = nil return end

    local tile, current_rail = Tile(player:getPosition())
    for i = 1, tile:getTopItemCount() do
        local top_item = tile:getItemByTopOrder(i)
        if top_item and rails[top_item.itemid] then
            current_rail = top_item
            break
        end
    end

    if current_rail and rails[current_rail.itemid] then
        for _, direction in pairs(rails[current_rail.itemid]) do
            local next_pos = player:getPosition()
            next_pos:getNextPosition(direction, 1)

            if previous[cid] == next_pos then goto continue end

            local next_tile = Tile(next_pos)
            if not next_tile then goto continue end

            local next_rail
            for i = 1, next_tile:getTopItemCount() do
                local top_item = next_tile:getItemByTopOrder(i)
                if top_item and rails[top_item.itemid] then
                    next_rail = top_item
                    break
                end
            end

            local floor_change = next_tile:hasFlag(TILESTATE_FLOORCHANGE)
            if floor_change or (next_rail and rails[next_rail.itemid]) then
                if floor_change then
                    if next_tile:hasFlag(TILESTATE_FLOORCHANGE_DOWN) then
                        previous[cid] = Position(next_pos.x, next_pos.y, next_pos.z + 1)
                    else
                        previous[cid] = Position(next_pos.x, next_pos.y, next_pos.z - 1)
                    end
                else
                    previous[cid] = player:getPosition()
                end
                player:move(direction)

                local outfit, wagon_id = player:getOutfit(), 7132 - (direction % 2)
                if player:getOutfit().lookTypeEx ~= wagon_id then
                    condition:setOutfit({lookTypeEx = wagon_id})
                    player:addCondition(condition)
                end

                addEvent(onMoveWagon, config.move_interval, cid)
                return
            end
            ::continue::
        end
    end

    player:removeCondition(CONDITION_OUTFIT)
    previous[cid] = nil
    if config.no_move then
        player:setNoMove(false)
    end
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if previous[player.uid] then return false end

    player:teleportTo(toPosition)
    previous[player.uid] = toPosition
    if config.no_move then
        player:setNoMove(true)
    end

    condition:setOutfit({lookTypeEx = item.itemid})
    player:addCondition(condition)

    addEvent(onMoveWagon, config.move_interval, player.uid)
    return true
end
 

Attachments

  • [TFS 1.3] setNoMove and canMove.pdf
    153.5 KB · Views: 73 · VirusTotal
Yes this is exactly what I was looking for!
Needed something to make certain skips a bit more interesting and this will jsut do that!

<3
 
Back
Top