Game Development Community

Help regarding new player

by Ironbelly Studios · in Technical Issues · 08/23/2006 (3:25 am) · 5 replies

Hello everybody
i ust had a small problem while using TGE
i wished to put in a new player into the game who can move and run
but does not have any idea how can i do it ?
thus i need help regarding this
thanking to everyone in advance
thanks

#1
08/23/2006 (11:51 am)
When you say new player you talking one you create or a pack you purchase? Create a folder in data/shapes. Like Orc or Adam. In this folder you will put the dts, dsq, texture and player.cs for the animations. Go to server/scripts and exec that player.cs at the top of player.cs in server/scripts. Then scroll down to datablock PlayerData(PlayerBody) and change the path of dts to point to the new model or create 5 line script below datablock PlayerData(PlayerBody) to copy the datablock and change the path in there.


PS. If you want an enemy do a search on AiGuard.
#2
08/23/2006 (2:10 pm)
You could also do this using an AI Player
You will need to create your paths using the editor.

However, if you just call the Spawn function you dont need to use the paths.

Could someone please show how to call the Spawn function giving the
%players.getTransform() location as a paramater ? So they all start from the same location ?

The function call should be located in function AIManager::spawnAll(%this)
which is called from game.cs

This will put multipul bots is a SimSet and call there think function
every 10000 ticks so they can roam around at random.

Youl'll need to create two files Bot_1 & Bot_2.cs like this...

This also has obstacal collision detection, but the bots just stop, Ha.. Ha..
They would do that anyway, just add a function to make them
do a %this.setMoveDestination(...) around it.


*************************AND NOW FOR THE THE AI PLAYER FILE.

//-----------------------------------------------------------------------------
// AIPlayer static functions
//-----------------------------------------------------------------------------
//------------------------------------------------------------------
function AIPlayer::spawn( %name, %spawnPoint )
{
// Create the A.I. driven bot object...
%player = new AIPlayer()
{
dataBlock = %name;
path = "";
};

MissionCleanup.add( %player );
%player.setShapeName( %name );
%player.setTransform( %spawnPoint );

return %player;
}
//------------------------------------------------------------------
function AIPlayer::spawnOnPath( %name, %path )
{
// Spawn a bot and place him on the first node of the path
if( !isObject( %path ) )
{
echo( "AIPlayer::spawnOnPath failed - Bad Path!" );
%this.path = "";
return;
}

%node = %path.getObject(0);
%player = AIPlayer::spawn( %name, %node.getTransform() );

return %player;
}
//------------------------------------------------------------------
function AIPlayer::followPath( %this, %path, %node )
{
// Start the bot following a path
%this.stopThread(0);

if( !isObject( %path ) )
{
echo( "AIPlayer::followPath failed - Bad Path!" );
%this.path = "";
return;
}

if( %node > %path.getCount() - 1 )
%this.targetNode = %path.getCount() - 1;
else
%this.targetNode = %node;

if( %this.path $= %path )
%this.moveToNode(%this.currentNode);
else
{
%this.path = %path;
%this.moveToNode(0);
}
}
//------------------------------------------------------------------
function AIPlayer::moveToNextNode( %this )
{
if( %this.targetNode < 0 || %this.currentNode < %this.targetNode )
{
if( %this.currentNode < %this.path.getCount() - 1 )
%this.moveToNode( %this.currentNode + 1 );
else
%this.moveToNode( 0 );
}
else
{
if( %this.currentNode == 0 )
%this.moveToNode( %this.path.getCount() - 1 );
else
%this.moveToNode( %this.currentNode - 1 );
}
}
//------------------------------------------------------------------
function AIPlayer::moveToNode( %this, %index )
{
// Move to the given path node index
%this.currentNode = %index;
%node = %this.path.getObject(%index);
%this.setMoveDestination( %node.getTransform(), %index == %this.targetNode );
}
//-----------------------------------------------------------------------------
function AIManager::think(%this)
{

if (isObject(%this.bots))
{
%num = %this.bots.getCount();
for (%n = 0; %n < %num; %n++)
%this.bots.getObject(%n).think();
}

%this.schedule(10000, think);
}
//-------------------------------------------------------------------------------
function AIManager::spawnAll(%this)
{

if (!isObject(%this.bots))
%this.bots = new SimSet();


%bot = AIPlayer::spawnOnPath("Bot_1", "MissionGroup/Path1");
//%bot.followPath("MissionGroup/Path1", -1);
%this.bots.add(%bot);

%bot = AIPlayer::spawnOnPath("Bot_2", "MissionGroup/Path2");

//%bot.followPath("MissionGroup/Path2", -1);
%this.bots.add(%bot);
}
//-------------------------------------------------------------------------------
function AIPlayer::think(%this)
{
// echo("I am a bot. I am thinking. My ID is" SPC %this SPC "my name is" SPC %this.getShapeName());
%this.setMoveDestination(getRandom(-600,60) SPC getRandom(-600,60) SPC 0);
botCollisionAvoid(%this);
}
//-------------------------------------------------------------------
function botCollisionAvoid(%this)
{


%start = %this.getEyePoint();
%rayLength = 10;
%rayDirection = VectorScale(%this.getEyeVector(), %rayLength);
%end = VectorAdd(%start, %rayDirection);

%mask = $TypeMasks::InteriorObjectType | $TypeMasks::StaticObjectType | $TypeMasks::ShapeBaseObjectType;
%rayInfo = ContainerRayCast(%start, %end, %mask, %this);


if(%rayinfo > 0)
{
echo (%rayinfo);
%this.stop();
return %object;
}

}

//-------------------------------------------------------------------

*********************** OK HERE'S HOW YOU CREATE THE BOT_?.CS FILES ....

//-----------------------------------------------------------------------------
// To create a Bot or A.I. driven player, we'll simply create a new PlayerData
// datablock called "bot_1" which derives all of its functionality from the
// "PlayerShape" datablock. This way our Bot can do anything that a human
// player can do. The only difference is, our Bot is being controlled by the
// computer so we need to add a few extra functions so it can think for it
// self.
//-----------------------------------------------------------------------------
datablock PlayerData( bot_1 : orc )
{
renderFirstPerson = false;
shapeFile = "~/data/shapes/orc/orc.dts";
// TO DO: Add extra stuff here to manage new A.I. functionality...
patrol = true;
attack = false;
};

function bot_1::onReachDestination( %this, %obj )
{
// Moves to the next node on the path.
if( %obj.path !$= "" )
{
if( %obj.currentNode == %obj.targetNode )
%this.onEndOfPath( %obj, %obj.path );
else
%obj.moveToNextNode();
}
else
echo( "bot_1::onReachDestination warning - Path is blank!" );
}

function bot_1::onEndOfPath( %this, %obj, %path )
{
%obj.nextTask();
}

// Load dts shapes and merge animations
datablock TSShapeConstructor(PlayerDts)
{
baseShape = "~/data/shapes/orc/orc.dts";
sequence0 = "~/data/shapes/orc/orc_root.dsq root";
sequence1 = "~/data/shapes/orc/orc_forward.dsq run";
ETC... ETC...
};
#3
08/31/2006 (6:23 am)
Hi
thanks Michael Prewer and Areal Person

hey Michael i had to add a new player meant i needed to see two players in the game one is the normal player and i wished to add a second player who moves around in a fixed path in the game and at whom the first person can chase and shoot at
i tried the aiguard but got some errors after recompiling the thing adding the aiguard and aipatrol it could not start the game and insted gave errors

fps/server/scripts/aiGuard.cs (0): Unable to find parent object PlayerBody for P
layerData.
can u help me in this regard?

hi Areal Person i tried ur method also but got stuck in between as i could not understand it properly i.e., how to do it
where do i get the spawn function to call from?
how to add the lines of code u gave me for Aiplayer file?
how and where to create the bot_1.cs file and also what should i put into it?(since the codes u send were not complete)

please don't mind if i sound a bit stupid in these questions
since i am new to TGE i could not know all the things which were assumed to be known

help much appreciated
thanking you
#4
08/31/2006 (9:08 am)
Yes it is looking for your datablock PlayerData(GuardPlayer : PlayerBody).

Open aiGuard.cs and scroll down to line 77, change it to this
datablock PlayerData(GuardPlayer : PlayerBody) // was PlayerBody

Open player.cs in server\scripts and scroll down to the end of // Allowable Inventory Items (line 672 on clean Torque install).

Add this after // Allowable Inventory Items
// Orc test for aiguard
datablock PlayerData(GuardPlayer : PlayerBody)
{
// Change path to yours
shapeFile = "~/data/shapes/players/Orc/player.dts";
};
// Orc test for aiguard

The reason to add this datablock in player.cs so you can have different dts for the enemy then the player, just remember to setup your folder in data\shapes. This datablock will copy all it needs from the datablock PlayerData(PlayerBody). You add the shapefile path for new enemy.

For this to work datablock PlayerData(GuardPlayer : PlayerBody) must be same in aiGuard.cs and player.cs. The dts paths must be same too in both files.

If you get error still then when you install aiGuard you left something out. I have test this TGE 1.4 and TLK 1.4 and it works very well.
#5
08/31/2006 (9:25 am)
AiPatrol is very much the same.
Open aiPatrol.cs and scroll down to line 34, change it to this
datablock PlayerData(PatrolPlayer : PlayerBody)

Open player.cs in server\scripts and scroll down to the end of // Allowable Inventory Items (line 672 on clean Torque install).
Add this after // Allowable Inventory Items

// Patrol
datablock PlayerData(PatrolPlayer : PlayerBody)
{
shapeFile = "~/data/shapes/players/PlayerWeapon/CubixStudioFemale.dts";
};
// Patrol

The same rules apply here as for the aiGuard.

I forgot same above dont forget add this line at top of the player.cs in server\scripts if not you will have no animation on your dts.
exec("~/data/shapes/players/Orc/player.cs");

After you get everything up and running you put your path in the world editor.
Then place AIpatrol maker in the world editor throw shapes. Go to the properties and add New Dynamic Field. Change the field name to pathname. Change Default Valves to path2 (Your Path Name). Save and relaunch Torque and you should have bot runinng the path.