-- LUA Script - precede every function and global member with lowercase name of script + '_main' g_teleporter_name_list = {} function teleporter_name_init_name(e, name) -- initialise transporter within level g_teleporter_name_list[e] = {name = name, state = 'off', tTime = 0} end local function distBetween (e1, e2) local Dx, Dy, Dz = e1.x - e2.x, e1.y - e2.y, e1.z - e2.z return (Dx * Dx + Dy * Dy + Dz * Dz) end function teleporter_name_main(e) local TP = g_teleporter_name_list[e] PlayerDist = GetPlayerDistance(e) if TP.state == 'off' and PlayerDist > 50 and PlayerDist < 120 then -- transporter aware of players proximity and powers up if g_Time > TP.tTime then TP.state = 'pup' end end if TP.state == 'pup' and PlayerDist < 50 then -- transport system active TP.state = 'trn' -- find matching or closest transporter local closest = math.huge local otherEnd = nil local Ent = g_Entity[e] local useName = (TP.name ~= 'Transporter Green' and TP.name ~= 'Transporter Blue') for k,v in pairs(g_teleporter_name_list) do if k ~= e then if useName and v.name == TP.name then otherEnd = k break else local dist = distBetween(g_Entity[k], Ent) if dist < closest then otherEnd = k closest = dist end end end end if otherEnd ~= nil then oeEnt = g_Entity[otherEnd] -- transport player here PlaySound(e, 0) SetFreezePosition(oeEnt.x, oeEnt.y, oeEnt.z) TransportToFreezePositionOnly() TP.tTime = g_Time + 500 end end if TP.state ~= 'off' and PlayerDist >= 120 then -- transporter powers down and cools down TP.state = 'off' TP.tTime = g_Time + 500 end end