Teleport script
by Stefan Beffy Moises · 07/09/2002 (10:11 am) · 44 comments
Download Code File
The basic idea was to combine 2 (or more) triggers, animated dts shapes
for the basic effect, particle effects, a little script
swapping the player location/transform and finally some "buzz" sound.
Okay, so lets start with the function doing the actual teleport...
I've put it into "server/scripts/commands.cs" and it looks like this:
target object indicated by %targetObj, adjusts the z value to prevent the player from
falling through the terrain and sends him to the %finalPos position.
Now lets look at the trigger, I've made a new file "fps/server/teleportTrigger.cs" which I execute in
"fps/server/game.cs" (as always), and it looks like this:
I've got two trigger objects in my mission file named "TeleportTrigger1" and "TeleportTrigger2",
furthermore there are the two shape files, which have their own datablock (btw., I took these shapefiles
and their datablock file "fxShapes.cs" from the latest RWTA build - thanks Phil :-).
Here is the datablock:
recent teleport, and if he was, he has to step out of it (onLeaveTrigger), before he can use it again...
otherwise he would be trapped, I guess... ;-)
To make it more realistic and to not just move the player, I put a little timeout of two seconds in,
and, what adds quite a lot to it, I set
So here is how all that looks in my mission file:
The ParticleEmitter looks like this, I keep all of my particle stuff in a file named "customParticles.cs",
which is also executed in ... well, you guess it!
Okay, so here are the "step-by-step" instructions...
1) download the zip :-P
2) put flame.dts and flame.png in "fps\data\shapes\markers"
3) put electricity.wav in "\fps\data\sound\fx"
4) put fxShapes.cs, teleportTrigger.cs and customParticles.cs in "fps\server\scripts"
5) put
6) put the function serverCmdTeleportPlayer(%client, %targetObj) in "fps\server\scripts\commands.cs"
7) add all the objects needed to your mission file (use the world editor by pressing F11 -> F4)
Note: it may be hard to add and place the particle emitters in the editor, so if you have problems, simply add
the shapes and the triggers with the editor, then save your mission and add the emitters manually - you can copy
the positions of the triggers and then adjust them later in the editor).
Well, as always, hope you enjoyed it - happy teleporting! :-))
PLEASE NOTE: The download file available here comes without the sound file for the effect (too large for the resource), but you can find this tutorial and ALL the files here!
EDIT: Fixed the multiplayer issues, everything is working now in multiplayer, too! The zip files here and on our website have been updated! Thanks to Ed Gardner who helped me out on IRC! :-)
The basic idea was to combine 2 (or more) triggers, animated dts shapes
for the basic effect, particle effects, a little script
swapping the player location/transform and finally some "buzz" sound.
Okay, so lets start with the function doing the actual teleport...
I've put it into "server/scripts/commands.cs" and it looks like this:
function serverCmdTeleportPlayer(%client, %clientId, %targetObj)
{
%player = %clientId.player;
%currPlayerPos = %player.getPosition();
%targetPos = %targetObj.getPosition();
%x = getWord(%targetPos, 0);
%y = getWord(%targetPos, 1);
%z = getWord(%targetPos, 2);
// adjust z value to prevent player from falling through the terrain... :-P
%z += 3.0;
%finalPos = %x SPC %y SPC %z;
echo("Transforing from" SPC %currPlayerPos SPC "to" SPC %finalPos);
%player.setTransform(%finalPos);
}Well, pretty basic, all it does is get the player's position and the position of thetarget object indicated by %targetObj, adjusts the z value to prevent the player from
falling through the terrain and sends him to the %finalPos position.
Now lets look at the trigger, I've made a new file "fps/server/teleportTrigger.cs" which I execute in
"fps/server/game.cs" (as always), and it looks like this:
datablock TriggerData(TeleportTrigger)
{
tickPeriodMS = 500;
};
datablock AudioProfile(TeleportBuzz)
{
fileName = "~/data/sound/fx/electricity.wav";
description = AudioClose3d;
preload = true;
};
function TeleportTrigger::onEnterTrigger(%data, %obj, %colObj)
{
%checkname = %obj.getName();
%client = %colObj.client;
if(!%client)
{
echo("not a client!");
return;
}
echo("Teleport client:" SPC %client);
if(%checkname $= "TeleportTrigger1")
{
// if the player didn't recently beam over here... otherwise
// he would be looping around between the two, I guess...
if(!$from2to1)
{
%target = "TeleportTrigger2";
CommandToClient(%client,'bottomprint',"Teleporter initializing... good luck!!",2,10);
$teleSched = schedule(2000,0,"goScotty",%client,%target);
$teleSound = serverPlay3D(TeleportBuzz,%client.player.getTransform());
%client.player.setCloaked(true);
$from1to2 = true;
$from2to1 = false;
}
}
else
{
if(!$from1to2)
{
%target = "TeleportTrigger1";
CommandToClient(%client,'bottomprint',"Teleporter initializing... good luck!!",2,10);
$teleSched = schedule(2000,0,"goScotty",%client, %target);
$teleSound = serverPlay3D(TeleportBuzz,%client.player.getTransform());
%client.player.setCloaked(true);
$from2to1 = true;
$from1to2 = false;
}
}
}
function TeleportTrigger::onLeaveTrigger(%data, %obj, %colObj)
{
%checkname = %obj.getName();
%client = %colObj.client;
echo("TeleportTrigger::onLeaveTrigger called!");
cancel($teleSched);
alxStop($teleSound);
%client.player.setCloaked(false);
// if the player leaves the target trigger,
// he can use it, too...
if(%checkname $= "TeleportTrigger1")
{
$from2to1 = false;
}
else if(%checkname $= "TeleportTrigger2")
{
$from1to2 = false;
}
}
function goScotty(%client, %target)
{
echo("goScotty called!");
// beam me up!
commandToServer('TeleportPlayer', %client, %target);
}
function TeleportTrigger::onTickTrigger(%data, %obj)
{
}I've got two trigger objects in my mission file named "TeleportTrigger1" and "TeleportTrigger2",
furthermore there are the two shape files, which have their own datablock (btw., I took these shapefiles
and their datablock file "fxShapes.cs" from the latest RWTA build - thanks Phil :-).
Here is the datablock:
datablock StaticShapeData(MeshEffect)
{
category = "Effects";
shapeFile = "~/data/shapes/markers/flame.dts";
};I use two vars "$from1to2" and "$from2to1" to keep track if the player already was teleported to therecent teleport, and if he was, he has to step out of it (onLeaveTrigger), before he can use it again...
otherwise he would be trapped, I guess... ;-)
To make it more realistic and to not just move the player, I put a little timeout of two seconds in,
and, what adds quite a lot to it, I set
%client.player.setCloaked(true);which kinda fades the player out and makes him semi-transparent, and after he's teleported, he "fades back in"... make sure to try it in 3rd person perspective...!! :-)
So here is how all that looks in my mission file:
new StaticShape(TeleportEffect1) {
position = "-27.6876 21.0268 100.362";
rotation = "1 0 0 90.5273";
scale = "1 1 1";
dataBlock = "MeshEffect";
};
new ParticleEmitterNode(TeleportParticle1) {
position = "-27.1392 22.8644 101.253";
rotation = "1 0 0 0";
scale = "1 1 1";
dataBlock = "defaultParticleEmitterNode";
emitter = "TeleportEmitter";
velocity = "1";
};
new StaticShape(TeleportEffect2) {
position = "-28.3129 125.469 100.391";
rotation = "1 0 0 90.5273";
scale = "1 1 1";
dataBlock = "MeshEffect";
};
new ParticleEmitterNode(TeleportParticle2) {
position = "-28.3129 127.069 101.391";
rotation = "1 0 0 0";
scale = "1 1 1";
dataBlock = "defaultParticleEmitterNode";
emitter = "TeleportEmitter";
velocity = "1";
};
new Trigger(TeleportTrigger2) {
position = "-29.4077 128.417 99.849";
rotation = "1 0 0 0";
scale = "3 2 2";
dataBlock = "TeleportTrigger";
polyhedron = "0.0000000 0.0000000 0.0000000 1.0000000 0.0000000 0.0000000 0.0000000
-1.0000000 0.0000000 0.0000000 0.0000000 1.0000000";
};
new Trigger(TeleportTrigger1) {
position = "-29.2559 23.685 99.5474";
rotation = "1 0 0 0";
scale = "3 2 2";
dataBlock = "TeleportTrigger";
polyhedron = "0.0000000 0.0000000 0.0000000 1.0000000 0.0000000 0.0000000 0.0000000
-1.0000000 0.0000000 0.0000000 0.0000000 1.0000000";
};The ParticleEmitter looks like this, I keep all of my particle stuff in a file named "customParticles.cs",
which is also executed in ... well, you guess it!
datablock ParticleData(TeleportParticle)
{
dragCoefficient = 1.11437;
gravityCoefficient = -0.735043;
windCoefficient = 0;
inheritedVelFactor = 0.483366;
constantAcceleration = 0;
lifetimeMS = 1056;
lifetimeVarianceMS = 256;
useInvAlpha = 0;
spinRandomMin = -159;
spinRandomMax = 172;
textureName = "fps/data/shapes/rifle/smokeParticle";
times[0] = 0;
times[1] = 1;
colors[0] = "0.102362 0.070866 0.000000 0.370079";
colors[1] = "0.000000 0.102362 0.000000 0.740157";
sizes[0] = 6.08863;
sizes[1] = 0;
};
datablock ParticleEmitterData(TeleportEmitter)
{
ejectionPeriodMS = 10;
periodVarianceMS = 2;
ejectionVelocity = 2.75;
velocityVariance = 1.62;
ejectionOffset = 0;
thetaMin = 47;
thetaMax = 90;
phiReferenceVel = 144;
phiVariance = 360;
overrideAdvances = 0;
orientParticles= 0;
orientOnVelocity = 1;
particles = "TeleportParticle";
};Okay, so here are the "step-by-step" instructions...
1) download the zip :-P
2) put flame.dts and flame.png in "fps\data\shapes\markers"
3) put electricity.wav in "\fps\data\sound\fx"
4) put fxShapes.cs, teleportTrigger.cs and customParticles.cs in "fps\server\scripts"
5) put
exec("./teleportTrigger.cs");
exec("./customParticles.cs");
exec("./fxShapes.cs");in "fps\server\scripts\game.cs"6) put the function serverCmdTeleportPlayer(%client, %targetObj) in "fps\server\scripts\commands.cs"
7) add all the objects needed to your mission file (use the world editor by pressing F11 -> F4)
Note: it may be hard to add and place the particle emitters in the editor, so if you have problems, simply add
the shapes and the triggers with the editor, then save your mission and add the emitters manually - you can copy
the positions of the triggers and then adjust them later in the editor).
Well, as always, hope you enjoyed it - happy teleporting! :-))
PLEASE NOTE: The download file available here comes without the sound file for the effect (too large for the resource), but you can find this tutorial and ALL the files here!
EDIT: Fixed the multiplayer issues, everything is working now in multiplayer, too! The zip files here and on our website have been updated! Thanks to Ed Gardner who helped me out on IRC! :-)
#42
Ill get it and play around with it and see if i can come up with a way to link teleport 2 to the next mission map,maybe use some arcane fx to make a portal and link it to that effect.might take a awhile ,but if i get it working ill re post back here, seeing how the OP was like years and years ago. Thanks for the resources.
11/05/2011 (7:16 pm)
I can see where that would work well porting from one town to another, just wondering if it can be modified to port to the next mission map.Ill get it and play around with it and see if i can come up with a way to link teleport 2 to the next mission map,maybe use some arcane fx to make a portal and link it to that effect.might take a awhile ,but if i get it working ill re post back here, seeing how the OP was like years and years ago. Thanks for the resources.
#43
11/05/2011 (7:18 pm)
don't guess i will. post to old the resource page not found.
#44
11/05/2011 (7:21 pm)
hmm odd. link on top works, one on bottom broke. 
Scott Gonte