Team Specific Player Spawning
by Anthony Rosenbaum · in Torque Game Engine · 06/03/2002 (1:54 pm) · 11 replies
Hello again all, it has been quite a while since my last question, so here it is. I want to make the player character spawn a specific type model depending on the team that the user chooses. I use Exodus' tut(red/blue team but differnt names)for the base code for team selection and Ed Gardner's GUI(press f5 click a team and walla you spawn).
If you are not familiar with the code I will cut and paste the important stuff (found in the game.cs) here
spawning player
However in my code I am testing to find the right variable with the echo() function and it works but I can't pull the names out, all I get is "Spawing team is " with nothing else. Whenever I use the %this variable I get nothing . . . .can anyone help me . . . .if you need more code I will be happy to supply you with it. Thank you
If you are not familiar with the code I will cut and paste the important stuff (found in the game.cs) here
//TEAM TYPES
$Team1 = new ScriptObject()
{
teamId = 1;
name = "G.I. Joe";
score = 0;
numPlayers = 0;
};
$Team2 = new ScriptObject()
{
teamId = 2;
name = "Cobra";
score = 0;
numPlayers = 0;
};andspawning player
function GameConnection::createPlayer(%this, %spawnPoint)
{
if (%this.player > 0) {
// The client should not have a player currently
// assigned. Assigning a new one could result in
// a player ghost.
error( "Attempting to create an angus ghost!" );
}
%teamname = %this.team.name
echo("Spawing team is " %teamname);
// Create the player object
%player = new Player() {
dataBlock = LightMaleHumanArmor;
//dataBlock = CobraCommanderHumanArmor;
//dataBlock = %this.team.name @ HumanArmor
client = %this;
};
MissionCleanup.add(%player);
// Player setup...
%player.setTransform(%spawnPoint);
%player.setEnergyLevel(60);
%player.setShapeName(%this.name);
// Update the camera to start with the player
%this.camera.setTransform(%player.getEyeTransform());
// Give the client control of the player
%this.player = %player;
%this.setControlObject(%player);
}please notice this part%teamname = %this.team.name
echo("Spawing team is " %teamname);
// Create the player object
%player = new Player() {
dataBlock = LightMaleHumanArmor;
//dataBlock = CobraCommanderHumanArmor;
//dataBlock = %this.team.name @ HumanArmor
client = %this;
}; Now I am not good with the scripts yet and this is my problem cause I want to use the %teamname variable to determine in a IF statement, which player model to use something like if(%teamname == Cobra)
{
%player = new Player() {
dataBlock = CobraGruntHumanArmor;
client = %this;
};}
else{
%player = new Player() {
dataBlock = JoeGruntHumanArmor;
client = %this;
};}However in my code I am testing to find the right variable with the echo() function and it works but I can't pull the names out, all I get is "Spawing team is " with nothing else. Whenever I use the %this variable I get nothing . . . .can anyone help me . . . .if you need more code I will be happy to supply you with it. Thank you
About the author
#2
06/03/2002 (2:56 pm)
I second Harold.
#3
needs a colon at the end
%teamname = %this.team.name;
also, %this.team.name won't work anyway because the %team part is non-existant. but i could be wrong about the second part, i'm only still learning the code.
06/03/2002 (3:27 pm)
%teamname = %this.team.nameneeds a colon at the end
%teamname = %this.team.name;
also, %this.team.name won't work anyway because the %team part is non-existant. but i could be wrong about the second part, i'm only still learning the code.
#4
06/03/2002 (3:37 pm)
Harold, why % instead of $ ?
#5
06/03/2002 (5:37 pm)
This is what I do:$Game::Team1 = new ScriptObject()
{
teamId = 1;
name = Red;
score = 0;
numPlayers = 0;
};%this.team = $Game::Team1;
echo("Team name = " @ %this.team.name);
#6
EDIT
ok so I did a test If/else statment
here it is
and I ALWAYS get a TRUE responce. What is wrong with this code?
06/03/2002 (6:11 pm)
ok I got the team name to echo() . . . I was forgetting the "@" symbol. . . .so does everyone think my if/else statement will work?EDIT
ok so I did a test If/else statment
here it is
%teamname = %this.team.name;
echo("Spawing team is " @ %teamname );
if( %teamname == "Cobra"){
echo("COBRAAAAAAAAAAAA");}
else{
echo("Yo Joe!");} and I ALWAYS get a TRUE responce. What is wrong with this code?
#8
THANK YOU THANK YOU THANK YOU It works perfectly . . . . . . I am indebted
06/03/2002 (6:32 pm)
sweet thanks!!!!! it works !!!!THANK YOU THANK YOU THANK YOU It works perfectly . . . . . . I am indebted
#9
06/03/2002 (6:33 pm)
No probs; glad it works for ya!
#10
06/03/2002 (8:14 pm)
No need to waste a global variable to hold the reference to an object if you name it like I did.
#11
06/04/2002 (5:41 am)
keeping that in mind (not to waste variables that is) here is the final version I am using if( %this.team.name $= "Cobra")
{
%player = new Player() {
dataBlock = CobraGruntHumanArmor;
client = %this;
};
}
else{
%player = new Player() {
dataBlock = JoeGruntHumanArmor;
client = %this;
};
}Thanks again everyone
Torque Owner Harold "LabRat" Brown
Personally I'd probably use the following:
//TEAM TYPES
%Team1 = new ScriptObject(Team1)
{
teamId = 1;
name = "G.I. Joe";
score = 0;
numPlayers = 0;
};
%Team2 = new ScriptObject(Team2)
{
teamId = 2;
name = "Cobra";
score = 0;
numPlayers = 0;
};
And for the team assignment:
%client.team = Team1;
echo(%client.team.name);