Game Development Community

Do something with the player?

by CodingChris · in Torque Game Engine · 12/10/2006 (7:48 am) · 14 replies

Hi,
I really need help. I try to do something with player. I tryed something like:
%player.position = "0 0 0";
but it didn't work for me. How to do something like this with the player?
Help needed.

#1
12/10/2006 (8:53 am)
I bet you try to do that from within the console ?

I suggest the following changes in scripts to help you in the future :

In client/scripts/game.cs (or any client script you know is loaded) add the following code :

function setLoc(%newpos)
{
	commandToServer('RelocatePlayer', %newpos) ;
}

function getLoc()
{
	echo(ServerConnection.getControlObject().getTransform());
}

In server/scripts/command.cs adde the following (if not already there) :

function serverCmdRelocatePlayer(%client, %newpos)
{
	%client.player.setTransform(%newpos);
}



This way you can reset the player position from the console in game. Use getLoc() to get the current player position shown in the console.log.
#2
12/10/2006 (9:21 am)
Thanks.
#3
12/11/2006 (9:27 am)
Is it possible to do a direct player.setTransform from within the console?
#4
12/11/2006 (9:31 am)
Yes it is, those are persistent fields on the player object so they will get picked up right away.
#5
12/11/2006 (9:42 am)
You should know that if you are in dedicated mode you can't do direct transform. If you use the example code I provided here you can type Setloc("x y z rot") ; in the console and you reset your player position globally (all clients will get the change).
#6
12/12/2006 (9:26 am)
Now I have got a new problem. I want ever when the player moves to display his position. But I don't really know how to do this.
Could anyone help me?
#7
12/13/2006 (7:33 am)
Look at the gettingstarted.pdf it tells you how to add a score display to the hud. Do the same but instead of the %player.score send the %player.getTransform(); or use getWords( %player.getTransform(),0,2); if you dont want all the rotation info, etc..
#8
12/13/2006 (8:09 am)
But how to display all this information, ever when the player moves?
#9
12/13/2006 (8:25 am)
Now I made this:
function moveleft(%val)
{
   if ($party = 12) {
   $pos = getloc();
   extra.setText($pos);
   }
   
   $mvLeftAction = %val * $movementSpeed;
}

function moveright(%val)
{
if ($party = 12) {
   $pos = getloc();
   extra.setText($pos);
   }
   $mvRightAction = %val * $movementSpeed;
}

function moveforward(%val)
{
if ($party = 12) {
   $pos = getloc();
   extra.setText($pos);
   }
   $mvForwardAction = %val * $movementSpeed;
}

function movebackward(%val)
{
if ($party = 12) {
   $pos = getloc();
   extra.setText($pos);
   }
   $mvBackwardAction = %val * $movementSpeed;
}

function moveup(%val)
{
if ($party = 12) {
   $pos = getloc();
   extra.setText($pos);
   }
   $mvUpAction = %val * $movementSpeed;
}

function movedown(%val)
{
if ($party = 12) {
   $pos = getloc();
   extra.setText($pos);
   }
   $mvDownAction = %val * $movementSpeed;
}

function turnLeft( %val )
{
if ($party = 12) {
   $pos = getloc();
   extra.setText($pos);
   }
   $mvYawRightSpeed = %val ? $Pref::Input::KeyboardTurnSpeed : 0;
}

function turnRight( %val )
{
if ($party = 12) {
   $pos = getloc();
   extra.setText($pos);
   }
   $mvYawLeftSpeed = %val ? $Pref::Input::KeyboardTurnSpeed : 0;
}
But it doesn't work.
#10
12/13/2006 (9:14 am)
Try:

function moveforward(%val)
{
if ($party = 12) {
$pos = getWords( %this.getTransform(),0,2);
extra.setText($pos);
}
$mvForwardAction = %val * $movementSpeed;
}
#11
12/14/2006 (6:07 am)
I will try, when I have time. Hope I can try on saturday.
#12
12/15/2006 (6:25 am)
Now I have this log:
Game/client/scripts/default.bind.cs (69): Unable to find object: '' attempting to call function 'getTransform'
Anyone an idea?
#13
12/21/2006 (12:03 am)
Now I fixed the error:
I made this:
function moveforward(%val)
{
if ($party = 12) {
$pos = getWords( ServerConnection.getControlObject().getTransform(),0,2);
extra.setText($pos);
}
$mvForwardAction = %val * $movementSpeed;
}
#14
12/27/2006 (9:16 pm)
And how to do something with a bot?
I've got this bot:
%botConnection = aiConnect("MasterBlaster" @ %i, -1, 0.5, false, "SDF", 1.0);
and I want him to follow a path:
Here's an example:
ServerConnection.MasterBlaster.followPath("CarPath", -1);
I tried this but his doesn't work.
Anyone an idee?