Unable to get teleport script working properly... anyone?
by John Schmuff · in Game Design and Creative Issues · 06/14/2009 (7:10 pm) · 2 replies
I have browsed all the teleporting threads on this website and I am unable to get any to work properly all I want to do it teleport my player from point A to point B using a keybind "t".
Here is my server.cs teleport function
Here is the code in my presetkeys.cs
What works:
The keybinding is working correctly and it is calling the servercmdteleportplayer function properly it is within that function it isn't working right at all in the console it reads errors for setTransform. This is exactly what the console reads.
Teleporting now!
control/server/server.cs (0): Unable to find object: '' attempting to call function 'setTransform'
Teleporting now!
control/server/server.cs (0): Unable to find object: '' attempting to call function 'setTransform'
Anyone have any suggestions here at all besides buy a book as suggested on someones post for teleporting?
Here is my server.cs teleport function
function serverCmdTeleportPlayer()
{
%x = 400;
%y = 1;
%z = 0;
// adjust z value to prevent player from falling through the terrain... :-P
%z += 3.0;
%finalPos = %x SPC %y SPC %z;
%player.setTransform(%finalPos);
}Here is the code in my presetkeys.cs
PlayerKeymap.Bind(keyboard, t, Teleport);
function Teleport()
{
commandToServer('TeleportPlayer');
echo("Teleporting now!");
}What works:
The keybinding is working correctly and it is calling the servercmdteleportplayer function properly it is within that function it isn't working right at all in the console it reads errors for setTransform. This is exactly what the console reads.
Teleporting now!
control/server/server.cs (0): Unable to find object: '' attempting to call function 'setTransform'
Teleporting now!
control/server/server.cs (0): Unable to find object: '' attempting to call function 'setTransform'
Anyone have any suggestions here at all besides buy a book as suggested on someones post for teleporting?
#2
Oh, and there's the getHeight(x, y) function which returns the height at x,y, which you can use to get the actual height at the point being teleported to, and then add some to that and always be above the terrain.
06/14/2009 (8:03 pm)
You forgot to pass %client and then use that to get your %player variable, which is what caused that console error. This function works (teleported me off my MegaTerrain and into the Great Digital Void). Enjoy...function serverCmdTeleportPlayer(%client)
{
%player = %client.player;
%xfrm = %player.getTransform();
%x = getWord(%xfrm, 0) + 400;
%y = getWord(%xfrm, 1) + 1;
%finalPos = %x SPC %y SPC %z;
%player.setTransform(%finalPos);
}Oh, and there's the getHeight(x, y) function which returns the height at x,y, which you can use to get the actual height at the point being teleported to, and then add some to that and always be above the terrain.
Associate Michael Hall
Distracted...
A little helpful hint: since you're sending a serverCMD with your keybind, the server already knows who the client is, and if you know who the client is then you can determine who the player is.
Try this:
function serverCmdTeleportPlayer(%this) { %x = 400; %y = 1; %z = 0; // adjust z value to prevent player from falling through the terrain... :-P %z += 3.0; %finalPos = %x SPC %y SPC %z; %this.player.setTransform(%finalPos); }In this case %THIS is the implicit variable attached to the function, and in this example %this = the client. A dynamic variable of player is given to the client when a new player body is spawned. You can reference this player variable directly if you know who the client is.