MoveEvent Rollercoaster System

Master-m

Need help? Just ask!
Joined
May 28, 2007
Messages
4,339
Best answers
0
Reaction score
15
Location
The Netherlands
This rollercoaster system is made by Collex.

Readme:
README.txt said:
Script Developed by Colex

[actions.xml]
<action fromid="7131" toid="7132" script="RollerCoaster.lua"/>
[/actions.xml]

[ActionIDs no Trem]
1001 e 1002 -> Train's Actionid, 1001 starts to one side and 1002 starts to the other

[Train Tracks' ActionIDs]
1001 -> Brakes (Decreases the speed)
1002 -> Impeller (Increases the speed)

[Additional Functions That You Can Use in RollerCoasterEvents.lua]
getSpeed(cid)
setSpeed(cid, newSpeed)

[Extra Information]
The RollerCoaster script was developed in a OTServer 8.1
but it's easy to update the IDs to any version just by editing 2 variables:

local TRAINS = {7131, 7132}
local all = {7121, 7122, 7123, 7124, 7125, 7126, 7133, 7134, 7135, 7136}


"local TRAINS" saves the 2 train's id, I think there's no problem on updating that...
"local all" saves the tracks' id, you just have to update it matching those ids with the ids of the version you are using.
Actions.xml
Actions.xml said:
<action fromid="7131" toid="7132" script="RollerCoaster.lua"/>
RollerCoaster.lua
Code:
dofile('data\\actions\\scripts\\RollerCoasterEvents.lua')

local TRAINS = {7131, 7132}
local all = {7121, 7122, 7123, 7124, 7125, 7126, 7133, 7134, 7135, 7136}

local ACTION_TRAIN = {1001, 1002}

local RAILS = {
{id = all[1], dirs = {{dir = SOUTH, out = 2},{dir = NORTH, out = 2}}}, 
{id = all[2], dirs = {{dir = EAST, out = 1},{dir = WEST, out = 1}}},
{id = all[3], dirs = {{dir = EAST, out = 1},{dir = SOUTH, out = 2}}},
{id = all[4], dirs = {{dir = WEST, out = 1},{dir = SOUTH, out = 2}}},
{id = all[5], dirs = {{dir = EAST, out = 1},{dir = NORTH, out = 2}}},
{id = all[6], dirs = {{dir = WEST, out = 1},{dir = NORTH, out = 2}}},
{id = all[7], stop = 1},
{id = all[8], stop = 1},
{id = all[9], stop = 1},
{id = all[10], stop = 1},
}

local SLOW = 500
local FAST = 200
local INCREASE = 50
local DECREASE = 50
local DOWN_INCREASE = 450
local UP_DECREASE = 155

local INFOS = {}

TRUE = 1
FALSE = 0

 
function getRail(pos)
  local stack = 1 
  local found = 0
  repeat
    pos.stackpos = stack
    rail = getThingfromPos(pos)
    if (rail.itemid == 0) then break end   
    for i, r in ipairs(RAILS) do
      if (rail.itemid == r.id) then
        found = 1
        break
      end   
    end
    stack = stack + 1
  until (found == 1)
  return rail
end

function moveTrain(cid)
  params = INFOS[cid]
  pos = getCreaturePosition(cid)
  rail = getRail(pos)
  dir = -1
  for i,r in ipairs(RAILS) do
    if (rail.itemid == r.id) then
      if (RollerCoaster:onMove(cid, rail, r, pos) == FALSE) then table.remove(INFOS, cid) return 1 end 
      if (r.stop ~= nil) then
        if (r.stop == 1) then
          RollerCoaster:onExitQuery(cid)
          addEvent(exitTrain, 2000, cid)
          return 1
        end
      end 
      change = rail.actionid - 1000 
      power = 0    
      power = change

      doChangeType(cid, r.id, INFOS[cid].beforeid)                 
      info = r.dirs[INFOS[cid].type]
      dir = info.dir  
      if ((power == 1) or (power == 2)) then
        if (RollerCoaster:onChangeSpeed(cid, power) == TRUE) then
          if (power == 2) then
            INFOS[cid].speed = INFOS[cid].speed - INCREASE
          elseif (power == 1) then
            INFOS[cid].speed = INFOS[cid].speed + DECREASE
          end 
        end
      end
      if (INFOS[cid].currZ ~= pos.z) then
        if (RollerCoaster:onChangeLevel(cid, INFOS[cid].currZ, pos.z) == TRUE) then
          if (INFOS[cid].currZ > pos.z) then
             INFOS[cid].speed = INFOS[cid].speed + UP_DECREASE
          elseif (params.currZ < pos.z) then 
             params.speed = params.speed - DOWN_INCREASE
          end  
        end 
      end
      if (params.speed < 1) then params.speed = 1 end
      params.currZ = pos.z
      newid = TRAINS[info.out]  
      INFOS[cid].beforeid = r.id
      break
    end  
  end      
  if (dir ~= -1) then
    doSetItemOutfit(cid, newid, -1)
    doMoveCreature(cid, dir)
    addEvent(moveTrain,params.speed,cid)
  else
    RollerCoaster:onExitQuery(cid)
    addEvent(exitTrain, 2000, cid)
  end
end

function exitTrain(cid)
  table.remove(INFOS, cid)
  RollerCoaster:onExit(cid)
  doSetItemOutfit(cid, TRAINS[1], 0)
  pos = getCreaturePosition(cid)
  pos.y = pos.y - 1
  doTeleportThing(cid, pos, 1)
  mayNotMove(cid, 0)
end

function enterTrain(params)   
  if (RollerCoaster:onEnter(cid, params[2]) == TRUE) then
    doSetItemOutfit(params[1], params[2], -1)
    pos = getCreaturePosition(params[1])
    table.insert(INFOS, params[1],{type = params.type, speed = SLOW, currZ = pos.z}) 
    addEvent(moveTrain,1000,params[1])
  end
end

function getSpeed(cid)
  if (INFOS[cid].speed ~= nil) then return INFOS[cid].speed end
  return FALSE
end

function setSpeed(cid, speed)
  if (INFOS[cid].speed ~= nil) then INFOS[cid].speed = speed return TRUE end
  return FALSE
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
  if (isInArray(ACTION_TRAIN, item.actionid) == TRUE) then
    if (RollerCoaster:onEnterQuery(cid, item) == TRUE) then
      doTeleportThing(cid, toPosition, 1)
      mayNotMove(cid, 1)
      addEvent(enterTrain,500,{cid, item.itemid, type=(item.actionid-1000)})
    end
  end
  return TRUE
end


----"No Scripting Needed" System-----
local change = {}
change[all[1]] = {all[3], all[4]}
change[all[2]] = {all[4], all[6]}
change[all[3]] = {all[1], all[4], all[6]}
change[all[4]] = {all[1], all[2], all[3], all[5], all[6]}
change[all[5]] = {all[4]}
change[all[6]] = {all[2], all[3], all[4]}
change[all[7]] = {}
change[all[8]] = {}
change[all[9]] = {}
change[all[10]] = {}
 
function doChangeType(cid, id, beforeID)
  if (table.getn(change[id]) > 0) then
    if (isInArray(change[id],beforeID) == TRUE) then
      if (INFOS[cid].type == 1) then INFOS[cid].type = 2 else INFOS[cid].type = 1 end
    end   
  end
end
RollerCoasterEvents.lua
Code:
RollerCoaster = {}

function RollerCoaster:onChangeLevel(cid, fromZ, toZ)
  return TRUE
end

function RollerCoaster:onMove(cid, rail, railInfo, pos)
  return TRUE
end

function RollerCoaster:onChangeSpeed(cid, power)
  if (power == 2) then
    doSendAnimatedText(getCreaturePosition(cid),"TROC TROC",210)
  else
    doSendAnimatedText(getCreaturePosition(cid),"TSSSIIIIII",210)
  end
  return TRUE
end

function RollerCoaster:onTypeChange(cid, fromType, toType)
  return TRUE
end

function RollerCoaster:onExitQuery(cid)
  return TRUE
end

function RollerCoaster:onExit(cid)
  return TRUE
end

function RollerCoaster:onEnterQuery(cid, cart)
  return TRUE
end

function RollerCoaster:onEnter(cid, cartID)
  return TRUE
end

Or Download the full package in the atachment.
 

Attachments

Last edited by a moderator:

Gut

Collapser Zulu Creator
Joined
Jun 14, 2007
Messages
578
Best answers
0
Reaction score
42
Location
USA
That is epic.
 

Orodonis

New Member
Joined
Apr 21, 2008
Messages
7
Best answers
0
Reaction score
0
Wow

wow that is absolutely amazeing looking i would love to test it :) gratz to the original maker
 

justin234

New Member
Joined
Jan 22, 2008
Messages
999
Best answers
0
Reaction score
3
No hands needed to use this,
It goes by itself...:D
 

Tony

New Member
Joined
Sep 23, 2007
Messages
81
Best answers
0
Reaction score
0
Nice Script i will use! :p
 

Tufte

Member
Joined
Nov 19, 2007
Messages
652
Best answers
0
Reaction score
23
Location
Norway
huge bug on it... if u click many times on the wagon when jumping up in it, you will go with insane speed, then when u are gonna leave the wagon u'll go like 20 sqm above the position ur supposed to go so ppl gets stuck.. useless on public servers with such a bug
 

wiirgy

New Member
Joined
Mar 29, 2008
Messages
9
Best answers
0
Reaction score
0
I can´t use it :( I have put all the things in right positions but it doesnt work. What client ?
#edit
Make an 8.21 RollerCoaster, and put it on this site. ;)
 

Tachi

New Member
Joined
Aug 4, 2007
Messages
376
Best answers
0
Reaction score
2
Location
USA, Missouri
Humm dosent seem to work.. 8.2 lastest tfs server(or really close)

[30/09/2008 13:56:36] The Forgotten Server - Version 0.3 (Pre-Alpha).


Did everything exactly as asked.(no id's to change..)

Still nothing... Help?
 

Zerville

New Member
Joined
Sep 19, 2008
Messages
47
Best answers
0
Reaction score
0
Ye awesome! heard about this script and i look forward to try it.
 

wiirgy

New Member
Joined
Mar 29, 2008
Messages
9
Best answers
0
Reaction score
0
I use deadtouch 2 alpha cuz, my forgotten server says Fatal Header OUtdated When I am Trying To Load MY Map!
 

Rappine

Empire will back
Joined
Feb 6, 2009
Messages
106
Best answers
0
Reaction score
0
Location
Brazil
It will work with the latest tfs version? ;D
anyone can tell me how to 'configure speedy' of the car? :D

thx
 

hon

New Member
Joined
Sep 19, 2008
Messages
104
Best answers
0
Reaction score
0
all i can say is GREAT JOB!!!
 

Herpicus

Web Developer
Joined
Jun 21, 2008
Messages
1,644
Best answers
0
Reaction score
85
Location
British Columbia
I tried recoding it to work for 8.42 but I am failing.. Can someone make it for elfs tfs? xD
 
Top