Checkpoints (Dynamically Changing a Teleporter's Output)
Posted: Sun Nov 30, 2014 2:13 am
Hi everyone,
As far as scripts go, I'm pretty clueless. But I found a neat little script in Bobdaduck's map, The Emperor's Revenge (a remix of Arctic's original classic) and adapted it to solve a really big problem in one of my levels. The way it works is it reconfigures a teleporter's output as soon as a player crosses over a trigger. With multiple triggers placed I was able to create a series of checkpoints that would actively adjust the teleporter path as players progressed!
How to use script: First, go into your level and place a teleporter. Click on it and press Shift-3 (the # key) to enter an ID. You can use whatever number you'd like, but be sure it corresponds to TeleportDest in the level editor. In the above code the ID is 50.
Set the teleporter's output to its starting location. Then, place RepairItems at the locations of where you want new teleporter outputs to be. Go into the level file and find the matching RepairItem. It will look something like this:
The first two numbers represent the X and the Y coordinates. These are the numbers you'll need. Disregard the third number which is the delay time for how long the repair item takes to respawn after use and irrelevant for our use.
In fact, we just need the RepairItem for its coordinates. You can delete the RepairItem now. You can achieve the same thing by placing your cursor over the desired spot in the level editor and looking at the bottom left corner for a reading, but I've found the RepairItem method to be more exact.
Once you have the X and Y coordinates of a desired teleporter output location, enter those into the lines "local x" and "local y". Do this for just the first block of code. Then repeat the steps to enter in another output for the second block of code. You can add more code blocks if you need more teleporter outputs or remove some if you need less.
Once the teleporter outputs are all configured, you'll need to place triggers. These utilize the Levelgen Zone, which is marked by a gray box in the lower section of the toolbar on the right side of your screen. Drag a Zone onto the level and place it where you want. When players cross over that Zone, it will trigger the teleporter output to change location. Don't worry, the Zones are invisible in-game and only visible to the level editor.
Before you finish be sure to change the order of the triggers by clicking a Zone and entering Shift-3 (the # key) to change its ID. Match the ID of each zone to the corresponding "zoneId" text in each code block. Make the IDs something easy like 1, 2, 3 which can be easily matched to the Zones in the level editor. After doing all this test the level to ensure everything's working and in the right order!
As far as scripts go, I'm pretty clueless. But I found a neat little script in Bobdaduck's map, The Emperor's Revenge (a remix of Arctic's original classic) and adapted it to solve a really big problem in one of my levels. The way it works is it reconfigures a teleporter's output as soon as a player crosses over a trigger. With multiple triggers placed I was able to create a series of checkpoints that would actively adjust the teleporter path as players progressed!
- Code:
--Levelgen script adapted from The Emperor's Revenge by bobdaduck
function changeTeleportDest(teleporterId, dest)
local teleporter = levelgen:findObjectById(teleporterId)
if(teleporter ~= nil) then -- if the teleporter exists
teleporter:clearDests()
teleporter:addDest(dest)
end
end
function onShipEnteredZone(ship, zone, zoneType, zoneId)
if(zoneId == 1) then
local x = 2
local y = 2
changeTeleportDest(50, point.new(x, y))
elseif(zoneId == 2) then
local x = 3
local y = 4
changeTeleportDest(50, point.new(x, y))
elseif(zoneId == 3) then
local x = -6
local y = -6
changeTeleportDest(50, point.new(x, y))
end
end
function main()
subscribe(Event.ShipEnteredZone)
end
How to use script: First, go into your level and place a teleporter. Click on it and press Shift-3 (the # key) to enter an ID. You can use whatever number you'd like, but be sure it corresponds to TeleportDest in the level editor. In the above code the ID is 50.
Set the teleporter's output to its starting location. Then, place RepairItems at the locations of where you want new teleporter outputs to be. Go into the level file and find the matching RepairItem. It will look something like this:
The first two numbers represent the X and the Y coordinates. These are the numbers you'll need. Disregard the third number which is the delay time for how long the repair item takes to respawn after use and irrelevant for our use.
In fact, we just need the RepairItem for its coordinates. You can delete the RepairItem now. You can achieve the same thing by placing your cursor over the desired spot in the level editor and looking at the bottom left corner for a reading, but I've found the RepairItem method to be more exact.
Once you have the X and Y coordinates of a desired teleporter output location, enter those into the lines "local x" and "local y". Do this for just the first block of code. Then repeat the steps to enter in another output for the second block of code. You can add more code blocks if you need more teleporter outputs or remove some if you need less.
Once the teleporter outputs are all configured, you'll need to place triggers. These utilize the Levelgen Zone, which is marked by a gray box in the lower section of the toolbar on the right side of your screen. Drag a Zone onto the level and place it where you want. When players cross over that Zone, it will trigger the teleporter output to change location. Don't worry, the Zones are invisible in-game and only visible to the level editor.
Before you finish be sure to change the order of the triggers by clicking a Zone and entering Shift-3 (the # key) to change its ID. Match the ID of each zone to the corresponding "zoneId" text in each code block. Make the IDs something easy like 1, 2, 3 which can be easily matched to the Zones in the level editor. After doing all this test the level to ensure everything's working and in the right order!