MoveEvent Updated Train System

Jano

oturhaN
Joined
Feb 21, 2008
Messages
876
Best answers
0
Reaction score
67
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
 

JDB

OtLand Veteran
Joined
Jun 1, 2009
Messages
4,145
Best answers
2
Reaction score
109
Cool, thanks for updating...
 

klekSu

Stroke my ego.
Joined
Nov 4, 2008
Messages
1,285
Best answers
0
Reaction score
18
Actually it should be without talking but arrows, if possible but i believe it is. Anyway nice script.
__________________

You are welcome on kleksoria.com!
Please visit new open tibia forum with it's own ots list. otservers.net!
 
Last edited:

D3lta

New Member
Joined
Apr 12, 2009
Messages
46
Best answers
0
Reaction score
0
how to delete train when i write "stop"?
 

9903286

New Member
Joined
Mar 24, 2010
Messages
6
Best answers
0
Reaction score
0
Every time i try TRAIN it be Invalid dirextion
 

Zorinhi

New Member
Joined
Apr 29, 2009
Messages
53
Best answers
0
Reaction score
1
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
 

Exedion

Active Member
Joined
Jun 11, 2007
Messages
628
Best answers
0
Reaction score
28
stop bumping old threads -.-
 

Zorinhi

New Member
Joined
Apr 29, 2009
Messages
53
Best answers
0
Reaction score
1
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

??
 

Kynami

¸.´)(`·[Ķɥɳɋɱɩ]·´)(` .¸
Joined
Jun 26, 2010
Messages
30
Best answers
0
Reaction score
0
Location
C:\Your ass
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?
 
Top