reScripted and tested using latest TFS (0.3.4)
movements/ scripts
train.lua
movements.xml
talkactions / scripts
train.lua
talkactions.xml
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
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