Re: Useful scripts repository
Posted: Thu Nov 01, 2012 4:01 pm
Configure any number of teleporters to send you to a random destination from a list of co-ordinates.
* Each teleporter should be named in the format plate_01_tele (where plate_01 will be the name of pressure plates around the teleporter
* each teleporter should have hidden pressure plates on each of it's open sides that are named in the format plate_01_A, plate_01_B etc. (the A, B etc are irrelevant so could be anything as long as each plate is different)
create a script entity and paste in the following code:
* In the script entity populate the tables rand_x; rand_y and rand_l with your sets of co-ordinates... so in this example as is, the destinations as (x,y,level) are (15,28,1); (17,28,1) (15,30,1) and (17,30,1)
* Connect every single pressure plate to this script entity with the action teleActivate
Notes -
* The script has a failsafe for If you end up putting too many or too few in any of the co-ordinate tables and only use as many destinations as it has complete data for.
* final facing in this example is determined by the direction the party are facing, but the script can be modified to use either a facing specified by the destination (we'd add another table rand_f) or by the facing of the teleporter itself. (we'd use teleporter_id.facing)
Script entity if wish to use teleport facing
script entity to use facing based on destination co-ordinates.
* Each teleporter should be named in the format plate_01_tele (where plate_01 will be the name of pressure plates around the teleporter
* each teleporter should have hidden pressure plates on each of it's open sides that are named in the format plate_01_A, plate_01_B etc. (the A, B etc are irrelevant so could be anything as long as each plate is different)
create a script entity and paste in the following code:
Code: Select all
function randomTele(teleporter_id)
local rand_x = {15,17,15,17}
local rand_y = {28,28,30,30}
local rand_l = {1,1,1,1}
local rand = math.random(1,math.min(#rand_x,#rand_y,#rand_l))
teleporter_id:setTeleportTarget(rand_x[rand],rand_y[rand],party.facing,rand_l[rand])
end
function teleActivate(plate)
tele_id = plate.id:sub(1,8) .. "_tele"
local tele_port = findEntity(tele_id)
randomTele(tele_port)
end
* Connect every single pressure plate to this script entity with the action teleActivate
Notes -
* The script has a failsafe for If you end up putting too many or too few in any of the co-ordinate tables and only use as many destinations as it has complete data for.
* final facing in this example is determined by the direction the party are facing, but the script can be modified to use either a facing specified by the destination (we'd add another table rand_f) or by the facing of the teleporter itself. (we'd use teleporter_id.facing)
Script entity if wish to use teleport facing
SpoilerShow
Code: Select all
function randomTele(teleporter_id)
local rand_x = {15,17,15,17}
local rand_y = {28,28,30,30}
local rand_l = {1,1,1,1}
local rand = math.random(1,math.min(#rand_x,#rand_y,#rand_l))
teleporter_id:setTeleportTarget(rand_x[rand],rand_y[rand],teleporter_id.facing,rand_l[rand])
end
function teleActivate(plate)
tele_id = plate.id:sub(1,8) .. "_tele"
local tele_port = findEntity(tele_id)
randomTele(tele_port)
end
SpoilerShow
Code: Select all
function randomTele(teleporter_id)
local rand_x = {15,17,15,17}
local rand_y = {28,28,30,30}
local rand_l = {1,1,1,1}
local rand_f = {0,1,3,2}
local rand = math.random(1,math.min(#rand_x,#rand_y,#rand_l,#rand_f))
teleporter_id:setTeleportTarget(rand_x[rand],rand_y[rand],rand_f[rand],rand_l[rand])
end
function teleActivate(plate)
tele_id = plate.id:sub(1,8) .. "_tele"
local tele_port = findEntity(tele_id)
randomTele(tele_port)
end