T3D Custom Player Respawns
by Carson Tiller · in Torque 3D Beginner · 03/10/2011 (2:39 pm) · 3 replies
Hello,
I have setup my game so the player spawns as a FlyingVehicle, and this FlyingVehicle can take damage and be destroyed.
Now, as the play spawns directly as the vehicle, when the vehicle does get destroyed, I need it to respawn the player ( And ideally, the solution needs to be safe for multiplayer ).
The code I have so far, looks like this:
I'm not entirely sure why, but it seems 'right' in my mind to reset the control to the camera, but other than this, I'm stuck for how the best way to respawn the player would be.
Adding
Seems like the right way to go, but looking at the code, it will bail and not actually spawn correctly
till I reset something, but I'm not sure what. ( Or maybe not reset, but delete().)
Hopefully, someone out there can point me in the right direction of where to look to resolve this, or give me a pointer or two towards a solution.
I have setup my game so the player spawns as a FlyingVehicle, and this FlyingVehicle can take damage and be destroyed.
Now, as the play spawns directly as the vehicle, when the vehicle does get destroyed, I need it to respawn the player ( And ideally, the solution needs to be safe for multiplayer ).
The code I have so far, looks like this:
...
function WarSparrow::onDestroyed( %data, %obj, %prevState )
{
echo("WarSparrow::onDestroyed().");
// Ok, we need to see if this is a player warsparrow, and if so,
// setup a respawn system of some kind o.o
echo( "Obj.client = " @ %obj.client );
if ( %obj.client )
{
%cam = %obj.client.getCameraObject();
%obj.client.setControlObject( %cam );
}
}
...I'm not entirely sure why, but it seems 'right' in my mind to reset the control to the camera, but other than this, I'm stuck for how the best way to respawn the player would be.
Adding
%obj.client.spawnPlayer();
Seems like the right way to go, but looking at the code, it will bail and not actually spawn correctly
till I reset something, but I'm not sure what. ( Or maybe not reset, but delete().)
Hopefully, someone out there can point me in the right direction of where to look to resolve this, or give me a pointer or two towards a solution.
About the author
A guy, a computer he found, and a strage habbit to tinker.
Recent Threads
#2
It would only apply to the server's client, assuming the server is running a client on it as well, what you want needs to be done through a clientCMD.
03/10/2011 (7:36 pm)
Looks correct to me, the only issue I see is with what you wanted in the first place for the KeyboardTurnSpeed.It would only apply to the server's client, assuming the server is running a client on it as well, what you want needs to be done through a clientCMD.
#3
in regards to doing it as a client command, or even why I chose to use the KeyboardTurnSpeed variable in the first place, after a night of sleep I came up with a thought of just modifiying the ActionMap, I could just unbind the keyboard controls while the player is 'dead'.
I believe that would also work, but I'm not sure if it would still need a clientCmd or not.
03/11/2011 (3:50 am)
Thanks for the response Robert, in regards to doing it as a client command, or even why I chose to use the KeyboardTurnSpeed variable in the first place, after a night of sleep I came up with a thought of just modifiying the ActionMap, I could just unbind the keyboard controls while the player is 'dead'.
I believe that would also work, but I'm not sure if it would still need a clientCmd or not.
Carson Tiller
Doing this with the code doesnt look right, but currently, does what I want it too:
... // Custom 'respawn' o.O function FlyingVehicle::DoRespawn( %this ) { // This will 'respawn' a human player, hopefully %groupName = "MissionGroup/PlayerDropPoints"; %group = nameToID(%groupName); echo( "Respawning..." ); if(%group != -1) { %count = %group.getcount(); if(%count != 0) { %index = getRandom(%count-1); %spawn = %group.getObject(%index); echo( "Client: " @ %this.client ); %this.setTransform( %spawn.getTransform() ); %this.setVelocity("0 0 0"); // Ok, we should now have a spawn location... %this.setDamageLevel(0); %this.setDamageState(Enabled); %this.startFade(1,0,false); %this.spawned = 1; %this.client.setControlObject( %this ); $pref::Input::KeyboardTurnSpeed = 3; } } error("WarSparrow::DoRespawn() - Unable to find a PlayerDropPoints"); } function WarSparrow::onDestroyed( %data, %obj, %prevState ) { echo("WarSparrow::onDestroyed()."); // Ok, we need to see if this is a player warsparrow, and if so, // setup a respawn system of some kind o.o if ( %obj.client > 0 ) { $pref::Input::KeyboardTurnSpeed = 0; %obj.client.deaths += 1; %obj.client.score -= 1; messageAll('MsgClientScoreChanged', "", %obj.client.score, %obj.client.kills, %obj.client.deaths, %obj.client); %obj.client.setControlObject( %obj.client.camera ); centerPrint( %obj.client, "You have failed - Respawn in 7 seconds", 3, 1 ); %obj.spawned = 0; %obj.startFade(1,0,true); %obj.schedule( 7000, "DoRespawn" ); } } ...The changing of KeyboardTurnSpeed stops, or at least seems to, the players ability to rotate the camera when 'dead'.
I'm pretty sure this is a hacky way to accomplish what I wanted, so if someone knows a better way, please let me know.