PDA

View Full Version : [scriptdump] Script-based teleporters



IzNoGoD
13th March 2013, 19:42
Just wrote a script that allows script-based teleporters.
Just call the init_teleporters() on map start and add some teleporters to it




init_teleporters()
{
level.teleporters = [];

level.teleporters[level.teleporters.size] = spawnstruct();
level.teleporters[level.teleporters.size - 1].origin = (0, 0, 0);
level.teleporters[level.teleporters.size - 1].radius = 50;
level.teleporters[level.teleporters.size - 1].height = 30;
level.teleporters[level.teleporters.size - 1].target = (10, 10, 10);

level.teleporters[level.teleporters.size] = spawnstruct();
level.teleporters[level.teleporters.size - 1].origin = (100, 100, 100);
level.teleporters[level.teleporters.size - 1].radius = 50;
level.teleporters[level.teleporters.size - 1].height = 30;
level.teleporters[level.teleporters.size - 1].target = (10, 10, 10);

thread waitforconnect();
}

waitforconnect()
{
while(true)
{
level waittill("connecting", p);
p thread onconnect();
}
}

onconnect()
{
while(isdefined(self))
{
while(isdefined(self.sessionstate) && self.sessionstate == "playing")
{
for(i = 0; i < level.teleporters.size; i++)
{
if(self.origin[2] > level.teleporters[i].origin[2] && self.origin[2] < level.teleporters[i].origin[2] + level.teleporters[i].height)
{
if(distancesquared((self.origin[0], self.origin[1], 0), (level.teleporters[i].origin[0], level.teleporters[i].origin[1], 0)) < level.teleporters[i].radius * level.teleporters[i].radius)
{
self setorigin(level.teleporters[i].target);
}
}
}
wait 0.05;
}
wait 0.05;
}
}

Edit changed the setorigin to the correct .target instead of the .origin