Moving Platforms
Posted: Fri Feb 05, 2016 12:54 am
Hey everyone,
I've been using the forums around here for a bit to help guide me with the editor and thought I'd return the favor and share my moving platforms code with y'all.
These platforms will carry the player on the x,y, and z axis.
Here is a link to my mod forEverQuest:A Link to the Past. http://steamcommunity.com/sharedfiles/f ... =616038736
Here is the steps to implement moving platforms, like the ones I used inside Ak'Anon, into your own dungeons...
First create a new mod then create the timer by pasting this code into init.lua inside the Dungeons\'your mod here'\mod_assets\scripts. This will act as your portal into the engine.
Create a script inside the editor named gameLoop and paste this code. Use the gameLoop run() to access your scripts that will run your platforms.
Create a script inside the editor named level1Platform. Paste this code into it; you will never need to touch it again until you copy it for another level.
Create a platform and name it but make sure to follow it by a number to keep things in order because we will be using it to make our call to the platforms script. This platform can be any object you want but I would recommend a floor or more specifically a magic bridge; since I allowed for it to go through the player when running down. In this example we call them platform1,platform2,platform3.
Create another script named level1Platforms and paste this code into it. This script is where we will initialize and run our platforms.
All spaces are divisions of 30 to create a fluent motion. When initializing vertical runs -3 to 6, -3 being 0 hence -2 would be 30. By initializing it at 30*3 we tell it to start at position 0 on the z axis.
The x and y axis is simply the starting number multiplied by 30.
Next step would only need to be done to reverse the direction that the platform is initially running.
The final step is the call that moves the platforms. Our initializing variable is what keeps track of this. Pass the platform's ID, the platform's starting x, platform's starting y, etc...
You would simply repeat this process on different levels using all unique IDs for the scripts and the platforms.
gameLoop --> level1Platforms --> level1Platform
gameLoop --> level2Platforms --> level2Platform
If you have any questions feel free to ask. I have a sample program of this built but no way to distribute atm.
I've been using the forums around here for a bit to help guide me with the editor and thought I'd return the favor and share my moving platforms code with y'all.
These platforms will carry the player on the x,y, and z axis.
Here is a link to my mod forEverQuest:A Link to the Past. http://steamcommunity.com/sharedfiles/f ... =616038736
Here is the steps to implement moving platforms, like the ones I used inside Ak'Anon, into your own dungeons...
First create a new mod then create the timer by pasting this code into init.lua inside the Dungeons\'your mod here'\mod_assets\scripts. This will act as your portal into the engine.
Code: Select all
----------------------------------------------------------------
-----------------------------------------------------------Party
defineObject{
name = "party",
baseObject = "party",
components =
{
----------------------------------
-----------------------------Timer
{
class = "Timer",
timerInterval = 0.001,
triggerOnStart = true,
onActivate = function(self)
gameLoop.script:run()
end
},
}
}
Create a script inside the editor named gameLoop and paste this code. Use the gameLoop run() to access your scripts that will run your platforms.
Code: Select all
function run()
level1Platforms.script.run()
endCreate a script inside the editor named level1Platform. Paste this code into it; you will never need to touch it again until you copy it for another level.
Code: Select all
init = {}
X = {}
c = {}
es = {}
switch = {}
counter = {}
for int = 1, 99 do --99 possible elevators
init[int] = false
X[int] = 0
counter[int] = 0
c[int] = 1
es[int] = false
switch[int] = false
end
----------------------------------------------------------------
----------------------------------------------------------------
function runV(entity,x,y,u,d,l,i,e,f) --entity,X,Y,U,D,L,I,E
if party.x == x and party.y == y then
if party.elevation < d then
switch[i] = false
end
else
switch[i] = false
end
counter[i] = counter[i] + 1
if counter[i] == c[i] then
counter[i] = 0
c[i] = 1
if es[i] == false then e=e+ 1 else e=e-1 end
sete = true
setp=false
---------------------party
if party.x == x and party.y == y then
if party.elevation >= entity.elevation and party.elevation < entity.elevation + 1 then
if e < 30 and party.elevation == -3
or e < 60 and e > 30 and party.elevation == -2
or e < 90 and e > 60 and party.elevation == -1
or e < 120 and e > 90 and party.elevation == 0
or e < 150 and e > 120 and party.elevation == 1
or e < 180 and e > 150 and party.elevation == 2
or e < 210 and e > 180 and party.elevation == 3
or e < 250 and e > 210 and party.elevation == 4
or e < 280 and e > 250 and party.elevation == 5
or e < 310 and e > 280 and party.elevation == 6
or switch[i] == true then
switch[i] = true
setp=true
if e == 0 then
party:setPosition(x,y,party.facing,-3,l)
setp =false
end
if e == 30 then
party:setPosition(x,y,party.facing,-2,l)
setp = false
end
if e == 60 then
party:setPosition(x,y,party.facing,-1,l)
setp = false
end
if e == 90 then
party:setPosition(x,y,party.facing,0,l)
setp = false
end
if e == 120 then
party:setPosition(x,y,party.facing,1,l)
setp = false
end
if e == 150 then
party:setPosition(x,y,party.facing,2,l)
setp = false
end
if e == 180 then
party:setPosition(x,y,party.facing,3,l)
setp = false
end
if e == 210 then
party:setPosition(x,y,party.facing,4,l)
setp = false
end
if e == 240 then
party:setPosition(x,y,party.facing,5,l)
setp = false
end
if e == 270 then
party:setPosition(x,y,party.facing,6,l)
setp = false
end
if setp == true then party:setWorldPosition(x*3+1.5,-9+e/10,(31-y)*3+1.5,0) end
end
end
end
---------------elevator
if e == 0 then
if u == -3 then es[i] = true end
if d == -3 then es[i] = false end
entity:setPosition(x,y,0,-3,l)
if d == -3 and f == true then entity:setWorldPosition(x*3+1.5,-8.75+e/10,(31-y)*3+1.5,0) end
c[i] = 50
sete = false
end
if e == 30 then
if u == -2 then es[i] = true end
if d == -2 then es[i] = false end
entity:setPosition(x,y,0,-2,l)
if d == -2 and f == true then entity:setWorldPosition(x*3+1.5,-8.75+e/10,(31-y)*3+1.5,0) end
c[i] = 50
sete = false
end
if e == 60 then
if u == -1 then es[i] = true end
if d == -1 then es[i] = false end
entity:setPosition(x,y,0,-1,l)
if d == -1 and f == true then entity:setWorldPosition(x*3+1.5,-8.75+e/10,(31-y)*3+1.5,0) end
c[i] = 50
sete = false
end
if e == 90 then
if u == 0 then es[i] = true end
if d == 0 then es[i] = false end
entity:setPosition(x,y,0,0,l)
if d == 0 and f == true then entity:setWorldPosition(x*3+1.5,-8.75+e/10,(31-y)*3+1.5,0) end
c[i] = 50
sete = false
end
if e == 120 then
if u == 1 then es[i] = true end
if d == 1 then es[i] = false end
entity:setPosition(x,y,0,1,l)
if d == 1 and f == true then entity:setWorldPosition(x*3+1.5,-8.75+e/10,(31-y)*3+1.5,0) end
c[i] = 50
sete = false
end
if e == 150 then
if u == 2 then es[i] = true end
if d == 2 then es[i] = false end
entity:setPosition(x,y,0,2,l)
if d == 2 and f == true then entity:setWorldPosition(x*3+1.5,-8.75+e/10,(31-y)*3+1.5,0) end
c[i] = 50
sete = false
end
if e == 180 then
if u == 3 then es[i] = true end
if d == 3 then es[i] = false end
entity:setPosition(x,y,0,3,l)
if d == 3 and f == true then entity:setWorldPosition(x*3+1.5,-8.75+e/10,(31-y)*3+1.5,0) end
c[i] = 50
sete = false
end
if e == 210 then
if u == 4 then es[i] = true end
if d == 4 then es[i] = false end
entity:setPosition(x,y,0,4,l)
if d == 4 and f == true then entity:setWorldPosition(x*3+1.5,-8.75+e/10,(31-y)*3+1.5,0) end
c[i] = 50
sete = false
end
if e == 240 then
if u == 5 then es[i] = true end
if d == 5 then es[i] = false end
entity:setPosition(x,y,0,5,l)
if d == 5 and f == true then entity:setWorldPosition(x*3+1.5,-8.75+e/10,(31-y)*3+1.5,0) end
c[i] = 50
sete = false
end
if e == 270 then
if u == 6 then es[i] = true end
if d == 6 then es[i] = false end
entity:setPosition(x,y,0,6,l)
if d == 6 and f == true then entity:setWorldPosition(x*3+1.5,-8.75+e/10,(31-y)*3+1.5,0) end
c[i] = 50
sete = false
end
if sete == true then entity:setWorldPosition(x*3+1.5,-9+e/10,(31-y)*3+1.5,0) end
end
return e
end
----------------------------------------------------------------
----------------------------------------------------------------
function runX(entity,x,y,u,d,h,l,i,e) --entity,X,Y,U,D,H,L,I,E
initlize(entity,i,x,y,h,l)
counter[i] = counter[i] + 1
if counter[i] == c[i] then
counter[i] = 0
c[i] = 1
if es[i] == false then e=e+ 1 else e=e-1 end
setp=false
if party.elevation >= entity.elevation and party.elevation < entity.elevation + 1 and party.y == entity.y and party.x == entity.x then setp = true end
---------------elevator
if e == 0 or e/30 == 1 or e/30 == 2 or e/30 == 3 or e/30 == 4 or e/30 == 5 or e/30 == 6 or e/30 == 7 or e/30 == 8 or e/30 == 9
or e/30 == 10 or e/30 == 11 or e/30 == 12 or e/30 == 13 or e/30 == 14 or e/30 == 15 or e/30 == 16 or e/30 == 17 or e/30 == 18
or e/30 == 19 or e/30 == 20 or e/30 == 21 or e/30 == 22 or e/30 == 23 or e/30 == 24 or e/30 == 25 or e/30 == 26 or e/30 == 27
or e/30 == 28 or e/30 == 29 or e/30 == 30 or e/30 == 31 then
if u == e/30 then es[i] = false c[i] = 50 end
if d == e/30 then es[i] = true c[i] = 50 end
end
entity:setWorldPosition(e/10+1.5,h*3,(31-y)*3+1.5,0)
if party.elevation >= entity.elevation and party.elevation < entity.elevation + 1 and party.y == entity.y and party.x == entity.x or setp == true then party:setWorldPosition(e/10+1.5,h*3,(31-y)*3+1.5,0) end
end
return e
end
----------------------------------------------------------------
----------------------------------------------------------------
function runY(entity,x,y,u,d,h,l,i,e) --entity,X,Y,U,D,H,L,I,E
initlize(entity,i,x,y,h,l)
counter[i] = counter[i] + 1
if counter[i] == c[i] then
counter[i] = 0
c[i] = 1
if es[i] == false then e=e- 1 else e=e+1 end
setp=false
if party.elevation >= entity.elevation and party.elevation < entity.elevation + 1 and party.y == entity.y and party.x == entity.x then setp = true end
---------------elevator
if e == 0 or e/30 == 1 or e/30 == 2 or e/30 == 3 or e/30 == 4 or e/30 == 5 or e/30 == 6 or e/30 == 7 or e/30 == 8 or e/30 == 9
or e/30 == 10 or e/30 == 11 or e/30 == 12 or e/30 == 13 or e/30 == 14 or e/30 == 15 or e/30 == 16 or e/30 == 17 or e/30 == 18
or e/30 == 19 or e/30 == 20 or e/30 == 21 or e/30 == 22 or e/30 == 23 or e/30 == 24 or e/30 == 25 or e/30 == 26 or e/30 == 27
or e/30 == 28 or e/30 == 29 or e/30 == 30 or e/30 == 31 then
if u == e/30 then es[i] = true c[i] = 50 end
if d == e/30 then es[i] = false c[i] = 50 end
end
entity:setWorldPosition(x*3+1.5,h*3,(31-e/30)*3+1.5,0)
if party.elevation >= entity.elevation and party.elevation < entity.elevation + 1 and party.x == entity.x and party.y == entity.y or setp == true then party:setWorldPosition(x*3+1.5,h*3,(31-e/30)*3+1.5,0) end
end
return e
end
----------------------------------------------------------------
----------------------------------------------------------------
function elevatorswitch(i)
es[i] = true
end
----------------------------------------------------------------
----------------------------------------------------------------
function initlize(entity,i,x,y,h,l)
if init[i] == false then
init[i] = true
entity:setPosition(x,y,0,h,l)
end
endCreate a platform and name it but make sure to follow it by a number to keep things in order because we will be using it to make our call to the platforms script. This platform can be any object you want but I would recommend a floor or more specifically a magic bridge; since I allowed for it to go through the player when running down. In this example we call them platform1,platform2,platform3.
Create another script named level1Platforms and paste this code into it. This script is where we will initialize and run our platforms.
All spaces are divisions of 30 to create a fluent motion. When initializing vertical runs -3 to 6, -3 being 0 hence -2 would be 30. By initializing it at 30*3 we tell it to start at position 0 on the z axis.
The x and y axis is simply the starting number multiplied by 30.
Next step would only need to be done to reverse the direction that the platform is initially running.
The final step is the call that moves the platforms. Our initializing variable is what keeps track of this. Pass the platform's ID, the platform's starting x, platform's starting y, etc...
Code: Select all
switch = false --initalize switch
--------------------------------------------------
---------------------------------------- initalize
e = {}
for i = 1, 99 do --1-99 possible elevators
e[i] = 0
end
e[1] = 30*3 --up/down platform. 0 = -3, every 1 elevation takes +30
e[2] = 30*14
e[3] = 15*30
---------------------------------------------
----------------------------------------- run
function run()
----------------------------------------- run initalize switch
if switch == false then
switch = true
--start in reverse X changes from ---> to <--- and Y changes from ^ to v
level1Platform.script.elevatorswitch(3) --switch starting direction
end
----------------------------------------- run platforms
--PlatformCounter = platform.script.runV(Entity.id,PositionX,PositionY,UpMax,DownMax,Entity.Level,instance,PlatformCounter,Is there a floor on DownMax true or false)
--PlatformCounter = platform.script.runX(Entity.id,PositionX,PositionY,LeftMax,RightMax,Height,Entity.Level,instance,PlatformCounter)
--PlatformCounter = platform.script.runY(Entity.id,PositionX,PositionY,UpMax,DownMax,Height,Entity.Level,instance,PlatformCounter)
e[1] = level1Platform.script.runV(platform1,15,16,1,0,1,1,e[1],true)
e[2] = level1Platform.script.runX(platform2,14,15,14,15,1,1,2,e[2])
e[3] = level1Platform.script.runY(platform3,16,15,15,16,1,1,3,e[3])
endYou would simply repeat this process on different levels using all unique IDs for the scripts and the platforms.
gameLoop --> level1Platforms --> level1Platform
gameLoop --> level2Platforms --> level2Platform
If you have any questions feel free to ask. I have a sample program of this built but no way to distribute atm.