• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua Old tfs rail by mock to tfs 1.0

Thorn

Spriting since 2013
Joined
Sep 24, 2012
Messages
2,203
Solutions
1
Reaction score
923
Location
Chile
Hello guys, im trying to update the rail by mock system to tfs 1.0, and i have change a couple of functions to newer ones, but im stuck now, i reached an error i can't solve, plz guys help :(

LUA:
--Script by mock the bear
--Config
local SPEED = 50
local PLAYERSPEED = 1050
--End
local RAILS = {7121, 7122, 7123, 7124, 7125, 7126, 7127, 7128, 7129, 7130} --Thxy rails itemid by nord :P
local CART = {[0] = 7132, [2] = 7132, [3] =7131, [1] =7131}
local CONFIG = {
    [7121] = 0,[7122] = 0,
    [7123] = {EAST, SOUTH},
    [7124] = {WEST, SOUTH},
    [7125] = {EAST, NORTH},
    [7126] = {WEST, NORTH},
    [7127] = 0,[7128] = 0,
    [7129] = 0,[7130] = 0,
    --Random
}
local reverse = {[0] = 2, 3, 0, 1} -- All that table was made by nord.
local function moveTrain(cid, frompos, direc)
    local tab
    if not isPlayer(cid) then
        return
    end
    local pos = player:getPosition(cid)
    local rar = findRail(pos)
    if not rar then
        doPlayerSetNoMove(cid, false)
        doRemoveCondition(cid, CONDITION_OUTFIT)
        doChangeSpeed(cid, -PLAYERSPEED)
        doMoveCreature(cid, direc)
    else
        tab = CONFIG[rar]
        if tab and type(tab) == 'table' then
            direc =  tab[tab[1] == reverse[direc] and 2 or 1] -- by nord here
        end
        doSetItemOutfit(cid, CART[direc], -1)
        doMoveCreature(cid, direc)
        addEvent(moveTrain, SPEED, cid, pos,direc)
    end
end
function findRail(p)
    local p_ = {x=p.x, y=p.y, z=p.z}
    for i=0,10 do
        p_.stackpos = i
        local t = getTileThingByPos(p_)
        if isInArray(RAILS, t.itemid) then
            return t.itemid,t.uid
        end
    end
end
function onUse(cid, item, frompos) --Script by mock the bear
    if player:getPosition(cid, CONDITION_OUTFIT) or (item.actionid < 500 and item.actionid > 503) then
        return false
    end
    doTeleportThing(cid, frompos, false)
    doPlayerSetNoMove(cid, true)
    doChangeSpeed(cid, PLAYERSPEED)
    addEvent(moveTrain, SPEED, cid, frompos, item.actionid-500)
    return true
end



this is the error

Code:
Lua Script Error: [Action Interface]
data/actions/scripts/railbymock.lua:onUse
data/actions/scripts/railbymock.lua:52: attempt to index global 'player' (a nil value)
stack traceback:
        [C]: in function '__index'
        data/actions/scripts/railbymock.lua:52: in function <data/actions/scripts/railbymock.lua:51>
 
Code:
--Script by mock the bear
--Config
local SPEED = 110
local PLAYERSPEED = 250
--End
local RAILS = {7121, 7122, 7123, 7124, 7125, 7126, 7127, 7128, 7129, 7130} --Thxy rails itemid by nord :P
local CART = {[0] = 7132, [2] = 7132, [3] =7131, [1] =7131}
local CONFIG = {
    [7121] = 0,[7122] = 0,
    [7123] = {EAST, SOUTH},
    [7124] = {WEST, SOUTH},
    [7125] = {EAST, NORTH},
    [7126] = {WEST, NORTH},
    [7127] = 0,[7128] = 0,
    [7129] = 0,[7130] = 0,
    --Random
}
local reverse = {[0] = 2, 3, 0, 1} -- All that table was made by nord.
local function moveTrain(cid, frompos, direc)
    local tab
    if not isPlayer(cid) then
        return
    end
    local pos = getCreaturePosition(cid)
    local rar = findRail(pos)
    if not rar then
        --doPlayerSetNoMove(cid, false)
        doRemoveCondition(cid, CONDITION_OUTFIT)
        doChangeSpeed(cid, -PLAYERSPEED)
        doMoveCreature(cid, direc)
    else
        tab = CONFIG[rar]
        if tab and type(tab) == 'table' then
            direc =  tab[tab[1] == reverse[direc] and 2 or 1] -- by nord here
        end
        doSetItemOutfit(cid, CART[direc], -1)
        doMoveCreature(cid, direc)
        addEvent(moveTrain, SPEED, cid, pos,direc)
    end
end
function findRail(p)
    local p_ = {x=p.x, y=p.y, z=p.z}
    for i=0,10 do
        p_.stackpos = i
        local t = getTileThingByPos(p_)
        if isInArray(RAILS, t.itemid) then
            return t.itemid,t.uid
        end
    end
end
function onUse(cid, item, frompos) --Script by mock the bear
    --if hasCondition(cid, CONDITION_OUTFIT) or (item.actionid < 500 and item.actionid > 503) then
    --    return false
    --end
    doTeleportThing(cid, frompos, false)
    --doPlayerSetNoMove(cid, true)
    doChangeSpeed(cid, PLAYERSPEED)
    addEvent(moveTrain, SPEED, cid, frompos, item.actionid-500)
    return true
end

It should work like this, although it will throw a warning

Never had the time to look into it. Might aswell revisit this soon and try to fix it.

Edit: ok so the problem with this is that we don't have a funciont to stop players moving in tfs 1.2

doPlayerSetNoMove
mayNotMove

are gone.
 
Last edited:
Code:
--Script by mock the bear
--Config
local SPEED = 110
local PLAYERSPEED = 250
--End
local RAILS = {7121, 7122, 7123, 7124, 7125, 7126, 7127, 7128, 7129, 7130} --Thxy rails itemid by nord :P
local CART = {[0] = 7132, [2] = 7132, [3] =7131, [1] =7131}
local CONFIG = {
    [7121] = 0,[7122] = 0,
    [7123] = {EAST, SOUTH},
    [7124] = {WEST, SOUTH},
    [7125] = {EAST, NORTH},
    [7126] = {WEST, NORTH},
    [7127] = 0,[7128] = 0,
    [7129] = 0,[7130] = 0,
    --Random
}
local reverse = {[0] = 2, 3, 0, 1} -- All that table was made by nord.
local function moveTrain(cid, frompos, direc)
    local tab
    if not isPlayer(cid) then
        return
    end
    local pos = getCreaturePosition(cid)
    local rar = findRail(pos)
    if not rar then
        --doPlayerSetNoMove(cid, false)
        doRemoveCondition(cid, CONDITION_OUTFIT)
        doChangeSpeed(cid, -PLAYERSPEED)
        doMoveCreature(cid, direc)
    else
        tab = CONFIG[rar]
        if tab and type(tab) == 'table' then
            direc =  tab[tab[1] == reverse[direc] and 2 or 1] -- by nord here
        end
        doSetItemOutfit(cid, CART[direc], -1)
        doMoveCreature(cid, direc)
        addEvent(moveTrain, SPEED, cid, pos,direc)
    end
end
function findRail(p)
    local p_ = {x=p.x, y=p.y, z=p.z}
    for i=0,10 do
        p_.stackpos = i
        local t = getTileThingByPos(p_)
        if isInArray(RAILS, t.itemid) then
            return t.itemid,t.uid
        end
    end
end
function onUse(cid, item, frompos) --Script by mock the bear
    --if hasCondition(cid, CONDITION_OUTFIT) or (item.actionid < 500 and item.actionid > 503) then
    --    return false
    --end
    doTeleportThing(cid, frompos, false)
    --doPlayerSetNoMove(cid, true)
    doChangeSpeed(cid, PLAYERSPEED)
    addEvent(moveTrain, SPEED, cid, frompos, item.actionid-500)
    return true
end

It should work like this, although it will throw a warning

Never had the time to look into it. Might aswell revisit this soon and try to fix it.

Edit: ok so the problem with this is that we don't have a funciont to stop players moving in tfs 1.2

doPlayerSetNoMove
mayNotMove

are gone.
ooh damn, so that won't work? is there a workaround?
 
Back
Top