• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

[Release] Train system

Master-m

Need help? Just ask!
Senator
Joined
May 28, 2007
Messages
4,338
Reaction score
16
Location
The Netherlands
This system is not created by me, the credits go to the creator.

Instruction:

  • put Talkaction Train.lua inisde talkactions/scripts
  • put Movement Train.lua inside movements.scripts
  • in talkactions.xml add
    Code:
    <talkaction words="train" script="Talkaction Train.lua" />
  • in movements.xml add
    Code:
    <movevent event="StepIn" itemid="7131" script="Movement Train.lua" />
    <movevent event="StepIn" itemid="7132" script="Movement Train.lua" />


~~Controls~~
  • train "left change your direction to the west.
  • train "right change your direction to the east.
  • train "up change your direction to the north.
  • train "down change your direction to the south.

Movement Train.lua
Code:
local storage = 242526
local interval = 500

local function movetrain(p)
	p.pos.stackpos = 2
	doCreateItem(p.t,1,p.new)
	doTeleportThing(p.cid, p.new, FALSE)
	doRemoveItem(getThingfromPos(p.pos).uid)
end	

function onStepIn(cid, item, pos)
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) == 1 then
		pos.stackpos = 1
		local Rail = getThingfromPos(pos)
		local Move = Rails[Rail.itemid]
		if Move then
			local Direction = Move[getPlayerStorageValue(cid,storage)]
			if Direction then
				setPlayerStorageValue(cid, storage, Direction.ns)
				doSetItemOutfit(cid, Direction.t, 600)
				addEvent(movetrain, interval, {cid=cid, new=Direction.n, t=Direction.t, pos=pos})
			end		
		end
	end
	return TRUE
end

Talkaction Train.lua
Code:
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
end

Have Fun!
 
LOL I like how a global moderator of Otland, took this script from your biggest Rival in forums!

LMFAO!
 
You can ride a train with it, just like carts scripts.
 
Again.. should cost money or something. Too beneficiary or whatever you want to call it. Also, you use this wherever you want? Would look kind of interesting to see a train passing through town.. o_O
 
Is it possible to make this on a set path instead of making it controlled by the user e.g. WoW trains in Ironforge

And can the user step off?
 
Is it possible to make this on a set path instead of making it controlled by the user e.g. WoW trains in Ironforge

And can the user step off?

You could remove the talk action for it, and add an 'onStepIn' on the tile next to the cart so when the player steps on the tile it sets the storage value to 2
or whatever direction it starts heading in, that would make it follow the path and stop players controlling it


p.s this script rox ;D​
 
Back
Top