Page 1 of 1

Need help simplifying teleporter puzzle via script

Posted: Thu Nov 01, 2012 8:14 am
by Jawny
Just started playing with the dungeon maker, been wanting to play with a map maker for a game as user-friendly and easy to pick up as this forever and in my over-ambitiosness, I've run into a block.

Anyways, I'm working on pretty big teleporter puzzle for my dungeon, I'm not looking foward to making it function without lua assistance (Pretty sure I can get it functional without, gonna need allot of plates and stacked tele's though) and since the extent of my coding abilities is copy pasting and editing templates (I can read, edit, but writing something from scratch eludes me), das not gonna happen.

So I thought I'd ask yah mates for some help in making a better system then switching several tele's around every few minutes via pressure plates.

I've outlined the basic premise of what I'm attempting in this image:
Image

The basic goal of this level is to retreive the key blocked off in the lower room below the diamond chamber by traversing through some teleporter shenagins. Once the player enters the central chamber, they have to head through the door in a specific direction, which then teleports them to a side room, which reaching the end of takes them back to the central chamber (Preferably from a random direction), repeat twice more and they reach a switch that turns off the lights and starts a second set of directions, completing these results in the party coming out the bottom of the room the key is in and being able to grab the key and leave the "maze". If at any point they enter the wrong door, it'll reset the current set and send em to a empty hallway.

Trying to set it all up to seem seemless, so unless the player is frequently checking thier map, they may not notice they are being teleported around, giving a sense that the place is massive.

Using the simple plate/switch logic, I think I could make it work, however not with random return directions. Having to stack teleporters if there is a way to simply use one in each spot and change destinations via scripting seems really time consuming and inneficient.

Anyways, any help, tips, or snippets yah mates can provide would be great assistance.

Re: Need help simplifying teleporter puzzle via script

Posted: Thu Nov 01, 2012 12:39 pm
by Grimwold
Here area few thoughts to get you started... I can try and add more later if I get chance.

Teleporter destinations can be changed on the fly with:

Code: Select all

teleporter_id:setTeleportTarget(x,y,facing,level)
If you want to do it multiple times in the course of a puzzle, setting up a function would really simplify things..

Code: Select all

function randomTele(teleporter_id)
  local rand_destination = math.random(1,4)
  if rand_destination == 1 then
    teleporter_id:setTeleportTarget(1,1,1,1)
  elseif rand_destination == 2 then
    teleporter_id:setTeleportTarget(2,2,1,1)
  elseif rand_destination == 3 then
    teleporter_id:setTeleportTarget(3,3,1,1)
  elseif rand_destination == 4 then
    teleporter_id:setTeleportTarget(4,4,1,1)
end
You would need to call this function with the ID of the teleporter to change and it would set it to 1 of 4 destinations at random (substitute your co-ordinates)... that would need another function (probably called by a pressure plate).

e.g.

Code: Select all

function checkPlate(plate)
  if plate == "plate_1" then
    randomTele(teleporter_1)
  elseif plate == "plate_2 then
    randomTele(teleporter_2)
-- and so on
  end
You would add a connector from each plate to this script and fill it with a long list of if's to check the plate names.


But, assuming each teleporter will only ever be entered from the same plate, We can set up pairs of teles and plates. and be a little clever with their names, to really simplify the script. i.e. Name each plate (e.g. plate_1) and then name each associated teleporter with the same name plus the word teleporter(e.g. plate_1_teleporter) then we can replace the checkPlate function with this neat little script:

Code: Select all

function checkPlate(plate)
  tele_id = plate.id .. "_teleporter"
  hudPrint(tele_id)
  findEntity(tele_id):activate()
end
and connect every plate to this same function and each plate will randomly reassign the target of it's similarly named teleporter

Re: Need help simplifying teleporter puzzle via script

Posted: Thu Nov 01, 2012 1:02 pm
by Grimwold
ok thinking on this a bit more.. here's some scripting I'm rather pleased with.

Assumptions
* each teleport is entered from only 1 side, so we only need 1 plate for each teleport to set destination.
* plates are named plate_1, plate_2 etc. (simple re-write of script if wish to name differently)
* teleports are named plate_1_teleport etc. (rename each tele according with any changes to plate names)
* you have a list of destination x,y co-ordinates

Code: Select all

function randomTele(teleporter_id)
  local rand_x = {15,17,15,17}
  local rand_y = {28,28,30,30}
  local rand = math.random(1,math.min(#rand_x,#rand_y))
  teleporter_id:setTeleportTarget(rand_x[rand],rand_y[rand],1,1)
end

function checkPlate(plate)
  tele_id = plate.id .. "_teleporter"
  local tele_port = findEntity(tele_id)
  randomTele(tele_port)
end
Connect each pressure plate to this script entity with action chechPlate.
Change the entries in rand_x and rand_y to correspond with the x and y co-ords of your destinations... all x's go in rand_x and all ys go in rand_y (in the same order)... so my destinations here are (15,28); (17,28); (15,30) and (17,30).
You can add as many sets of co-ordinates as you wish, because the random number generator will always use the length of rand_x and rand_y to determine it's range.

[EDIT @ 14:02] - I've posted a more flexible version of this random destination selection script in the repository - viewtopic.php?f=14&t=3099&p=41194#p41194

With it you can now have any number of plates (1 to 4) around a teleporter and there are variants to set the facing based on either party facing. teleporter facing or a facing specific to the destination. It's also multi-level because you can specifiy destinations as x y and level co-ordinates.