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

MoveEvent Updated Train System

Jano

oturhaN
Joined
Feb 21, 2008
Messages
876
Solutions
1
Reaction score
68
Location
Chile
reScripted and tested using latest TFS (0.3.4)

movements/ scripts

train.lua

Lua:
local storage = 242526
local interval = 500

function tileChecker(pos)
    local myTable = {}
    if (type(pos) == 'table') then
        for i = 1, 5 do
            pos.stackpos = i
            local thisID = getThingFromPos(pos).itemid
            if thisID > 1 then
                table.insert(myTable, thisID)
            end
        end
    end
    return #myTable > 0 and myTable or nil
end

local function findItem(pos, t)
    if (type(pos) == 'table' and type(t) == 'table') then
        for _i, i in ipairs(tileChecker(pos)) do
            if isInArray(t, i) then
                pos.stackpos = _i
                ret = getThingFromPos(pos).uid
                break
            end
        end
    end
    return ret
end

local function moveTrain(p)
    doCreateItem(p.t, 1, p.new)
    doTeleportThing(p.cid, p.new, FALSE)
    doRemoveItem(findItem(p.pos, {7131, 7132}))
end    

function onStepIn(cid, item, pos)
    local Rail = false
    local Rails = 
    {
        [7122]={
            [1]={n={x=pos.x-1, y=pos.y, z=pos.z}, t=7131, ns=1},
            [2]={n={x=pos.x+1, y=pos.y, z=pos.z}, t=7131, ns=2}
                },
        [7121]={
            [3]={n={x=pos.x, y=pos.y-1, z=pos.z}, t=7132, ns=3},
            [4]={n={x=pos.x, y=pos.y+1, z=pos.z}, t=7132, ns=4}
                },
        [7123]={
            [3]={n={x=pos.x+1, y=pos.y, z=pos.z}, t=7131, ns=2},
            [1]={n={x=pos.x, y=pos.y+1, z=pos.z}, t=7132, ns=4}
                },
        [7124]={
            [3]={n={x=pos.x-1, y=pos.y, z=pos.z}, t=7131, ns=1},
            [2]={n={x=pos.x, y=pos.y+1, z=pos.z}, t=7131, ns=4}
                },
        [7125]={
            [4]={n={x=pos.x+1, y=pos.y, z=pos.z}, t=7131, ns=2},
            [1]={n={x=pos.x, y=pos.y-1, z=pos.z}, t=7132, ns=3}
                },
        [7126]={
            [4]={n={x=pos.x-1, y=pos.y, z=pos.z}, t=7131, ns=1},
            [2]={n={x=pos.x, y=pos.y-1, z=pos.z}, t=7132, ns=3}
                },
        [7127]={
            [4]={n={x=pos.x-1, y=pos.y, z=pos.z}, t=7131, ns=1},
            [3]={n={x=pos.x, y=pos.y-1, z=pos.z}, t=7132, ns=3},
            [2]={n={x=pos.x, y=pos.y-1, z=pos.z}, t=7132, ns=3}
                },
        [7128]={
            [3]={n={x=pos.x-1, y=pos.y, z=pos.z}, t=7131, ns=1},
            [1]={n={x=pos.x-1, y=pos.y, z=pos.z}, t=7131, ns=1},
            [2]={n={x=pos.x, y=pos.y+1, z=pos.z}, t=7132, ns=4}
                },
        [7130]={
            [4]={n={x=pos.x+1, y=pos.y, z=pos.z}, t=7131, ns=2},
            [3]={n={x=pos.x, y=pos.y-1, z=pos.z}, t=7132, ns=3},
            [1]={n={x=pos.x, y=pos.y-1, z=pos.z}, t=7132, ns=3}
                },
        [7129]={
            [1]={n={x=pos.x-1, y=pos.y, z=pos.z}, t=7131, ns=1},
            [2]={n={x=pos.x, y=pos.y-1, z=pos.z}, t=7132, ns=3},
            [4]={n={x=pos.x-1, y=pos.y, z=pos.z}, t=7131, ns=1}
                }
    }
    if isPlayer(cid) == TRUE then
        local tileItems = tileChecker(pos)
        if tileItems ~= nil then
            for _, i in ipairs(tileItems) do
                if Rails[i] then
                    Rail = Rails[i]
                    break
                end
            end
        end
        if Rail ~= false then
            local Direction = Rail[getPlayerStorageValue(cid,storage)]
            if Direction then
                setPlayerStorageValue(cid, storage, Direction.ns)
                doSetItemOutfit(cid, Direction.t, 1000)
                addEvent(moveTrain, interval, {cid=cid, new=Direction.n, t=Direction.t, pos=pos})
            end        
        end
    end
    return TRUE
end

movements.xml

PHP:
    <movevent type="StepIn" itemid="7131" event="script" value="train.lua"/>
    <movevent type="StepIn" itemid="7132" event="script" value="train.lua"/>

talkactions / scripts

train.lua

Lua:
local storage = 242526
local directions = 
    {
        ["up"] = {new = 3, name = "Up"},
        ["down"] = {new = 4, name = "Down"}, 
        ["left"] = {new = 1, name = "Left"}, 
        ["right"] = {new = 2, name = "Right"},
        ["stop"] = {new = 0, name = "Stop"}
    } 
function onSay(cid, words, param)
    local ndir = directions[param]
    if (ndir ~= nil) then
        setPlayerStorageValue(cid, storage, ndir.new)
        doCreatureSay(cid, ndir.name, TALKTYPE_SAY)
        doPlayerSendTextMessage(cid,22,"New Direction Set, your new direction is " .. ndir.name .. ".")
    else
        doSendMagicEffect(getPlayerPosition(cid), 2)
        doPlayerSendCancel(cid, "Invalid dirextion.")
    end
    return TRUE
end

talkactions.xml

PHP:
    <talkaction words="train" script="train.lua" />



you should use at least one time train up / left / right / down
use train stop to stop the train

the train is not walkeable but you can use other script for walk in the train
example
Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
    doTeleportThing(cid, fromPosition, TRUE)
    return TRUE
end
 
Cool, thanks for updating...
 
Actually it should be without talking but arrows, if possible but i believe it is. Anyway nice script.
__________________
klekSu.png

You are welcome on kleksoria.com!
Please visit new open tibia forum with it's own ots list. otservers.net!
 
Last edited:
where I need to add> function onUse(cid, item, fromPosition, itemEx, toPosition)
doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
doTeleportThing(cid, fromPosition, TRUE)
return TRUE
end
 
where i need to add

function onUse(cid, item, fromPosition, itemEx, toPosition)
doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
doTeleportThing(cid, fromPosition, TRUE)
return TRUE
end

??
 
Code:
[18/04/2011 20:49:54] Lua Script Error: [MoveEvents Interface] 
[18/04/2011 20:49:54] data/movements/scripts/Movement Train.lua:onStepIn
[18/04/2011 20:49:54] data/movements/scripts/Movement Train.lua:9: attempt to call global 'getThingFromPos' (a nil value)
[18/04/2011 20:49:54] stack traceback:
[18/04/2011 20:49:54] 	[C]: in function 'getThingFromPos'
[18/04/2011 20:49:54] 	data/movements/scripts/Movement Train.lua:9: in function 'tileChecker'
[18/04/2011 20:49:54] 	data/movements/scripts/Movement Train.lua:87: in function <data/movements/scripts/Movement Train.lua:37>

Help?
 
Back
Top