Multiple game characters
by Amarnauth Sukhu · in General Discussion · 11/12/2006 (8:18 am) · 13 replies
I was hoping if, anyone could instruct me on what i have to do to load multiple characters. Which are correctly animated with their own unique run, walk .... sequences. I couldn't find any reference online.
About the author
#2
I had working with 2 different models: 1 human player and 1 orc.
STef
11/12/2006 (9:55 am)
I made it, the solution is in script files, but you must be careful when loading the exec sequences in the game.cs script.I had working with 2 different models: 1 human player and 1 orc.
STef
#3
11/12/2006 (12:09 pm)
I made a simple class system to do all that. I started with the teamplay resource then added another gui to select a class. I added five classes, and each team can have seperate player models & weapons/ammo for each class. I'll make it into a resource if anyone wants it.
#4
It will be great if you could show an example on how to have multiple player objects.
i was able to see the ai and my player, but they are 'gliding' across the screen.
11/12/2006 (1:18 pm)
Mb,It will be great if you could show an example on how to have multiple player objects.
i was able to see the ai and my player, but they are 'gliding' across the screen.
#5
1: Put the character DTS files, along with all their animation (DSQ) files in individual folders for each character. This will keep everything a lot neater.
2: Keep player.cs in game/data/shapes/player and open it up. You should have
Then, replace 'PlayerDts' with something meaningful for your first character, eg OrcDts, then make the file path to the shape point to the appropriate shape (DTS), and the animation file paths point to the equivalent animation file (DSQ). EG:
3: Copy the entire datablock and past it underneath, then repeat the same changes on this datablock for the second character. IE: Rename it to something appropriate and point all the files to those which apply to that character.
Repeat this for all your characters and this should embed the animations into the DTS file so that they display correctly when triggered.
4: To have all these models running around together you then need to create a PlayerData datablock which applys to each character type, otherwise when you change the datablock it will affect ALL the characters which use it. Open up game/server/scripts/player.cs and find the PlayerData datablock. Rename it to something for your first character, Eg: PlayerData(OrcBody) and point the ShapeFile entry at the appropriate model, eg: shapeFile = "~/data/shapes/player/orc/player.dts";
5: THEN copy the entire datablock and paste it underneath, rename it for the second character, select the appropriate model and repeat for each character.
6: Finally you want to use these different datablocks to create different characters when players or AIs are spawned. This is done differently for Players and AIs.
For players their datablock is set in game/server/scripts/game.cs in the GameConnection::createPlayer function. where it says dataBlock = PlayerBody simply replace PlayerBody with the datablock for the character you want to use. This can also be replaced by a variable to allow players to pick their character, to load characters from a database, or any other number of things.
For AIs it's set in game/server/scripts/aiplayer.cs right at the top. Simply replace the PlayerBody in PlayerData(DemoPlayer : PlayerBody) with the one you want.
The PlayerData datablock is also realy great for changing all aspects of each character. You can make some character types faster, slower, tougher, weaker, limit weapon types and pickups, change pretty much everything about each group.
I hope that helped some, and sorry if I made any mistakes.
Cheers,
Davidovich
Edit: What's with this message board? It keeps cutting my posts off where ever I've copied and pasted something.
11/12/2006 (2:38 pm)
How I did it: (This was a while back so I might forget something. Also this was done with 1.4.2, I haven't tried it with 1.5, but the code looks the same so it guess it will work)1: Put the character DTS files, along with all their animation (DSQ) files in individual folders for each character. This will keep everything a lot neater.
2: Keep player.cs in game/data/shapes/player and open it up. You should have
datablock TSShapeConstructor(PlayerDts)
{
baseShape = "./player.dts";
sequence0 = "./player_root.dsq root";
...Then, replace 'PlayerDts' with something meaningful for your first character, eg OrcDts, then make the file path to the shape point to the appropriate shape (DTS), and the animation file paths point to the equivalent animation file (DSQ). EG:
datablock TSShapeConstructor(OrcDts)
{
baseShape = "./orc/player.dts";
sequence0 = "./orc/player_root.dsq root";
...3: Copy the entire datablock and past it underneath, then repeat the same changes on this datablock for the second character. IE: Rename it to something appropriate and point all the files to those which apply to that character.
Repeat this for all your characters and this should embed the animations into the DTS file so that they display correctly when triggered.
4: To have all these models running around together you then need to create a PlayerData datablock which applys to each character type, otherwise when you change the datablock it will affect ALL the characters which use it. Open up game/server/scripts/player.cs and find the PlayerData datablock. Rename it to something for your first character, Eg: PlayerData(OrcBody) and point the ShapeFile entry at the appropriate model, eg: shapeFile = "~/data/shapes/player/orc/player.dts";
5: THEN copy the entire datablock and paste it underneath, rename it for the second character, select the appropriate model and repeat for each character.
6: Finally you want to use these different datablocks to create different characters when players or AIs are spawned. This is done differently for Players and AIs.
For players their datablock is set in game/server/scripts/game.cs in the GameConnection::createPlayer function. where it says dataBlock = PlayerBody simply replace PlayerBody with the datablock for the character you want to use. This can also be replaced by a variable to allow players to pick their character, to load characters from a database, or any other number of things.
For AIs it's set in game/server/scripts/aiplayer.cs right at the top. Simply replace the PlayerBody in PlayerData(DemoPlayer : PlayerBody) with the one you want.
The PlayerData datablock is also realy great for changing all aspects of each character. You can make some character types faster, slower, tougher, weaker, limit weapon types and pickups, change pretty much everything about each group.
I hope that helped some, and sorry if I made any mistakes.
Cheers,
Davidovich
Edit: What's with this message board? It keeps cutting my posts off where ever I've copied and pasted something.
#6
11/12/2006 (3:24 pm)
Thanks alot guys, i got it.
#7
datablock PlayerData(PlayerBody2 : PlayerBody)
{
shapeFile = "~/data/shapes/player/player2.dts";
};
datablock PlayerData(PlayerBody3 : PlayerBody)
{
shapeFile = "~/data/shapes/player/player3.dts";
};
this would inherit all the properties of PlayerBody except the shapeFile which was changed.
11/12/2006 (10:35 pm)
Also I dont know if you said this or not, but if you dont need to change everything in the datablock you can inherit from another datablock, and change what you need:datablock PlayerData(PlayerBody2 : PlayerBody)
{
shapeFile = "~/data/shapes/player/player2.dts";
};
datablock PlayerData(PlayerBody3 : PlayerBody)
{
shapeFile = "~/data/shapes/player/player3.dts";
};
this would inherit all the properties of PlayerBody except the shapeFile which was changed.
#8
11/13/2006 (3:37 am)
Good point mb. That's an easier way of doing it if you're not changing heaps of the paramaters.
#9
Well as suggested you should have this in the forums its much quicker for response and for others looking for the same question.
you can include other player animation scripts in the player.cs file or any if you want.
e.g.
exec("~/data/shapes/playerred/player.cs");
exec("~/data/shapes/playerblue/player.cs");
But you have to make sure that the file it referrers to doesn't describe the same model and that it has a different name given other wise it'll over write it and you only have one.
data/shapes/playerblue/player.cs:
datablock TSShapeConstructor(PlayerBlueDts)
data/shapes/playerred/player.cs
datablock TSShapeConstructor(PlayerRedDts)
Then you can referrer to that model and get its animations script.
I hope that helps?
11/13/2006 (6:21 am)
Edward Smith (Nov 12, 2006 at 18:37) Well as suggested you should have this in the forums its much quicker for response and for others looking for the same question.
you can include other player animation scripts in the player.cs file or any if you want.
e.g.
exec("~/data/shapes/playerred/player.cs");
exec("~/data/shapes/playerblue/player.cs");
But you have to make sure that the file it referrers to doesn't describe the same model and that it has a different name given other wise it'll over write it and you only have one.
data/shapes/playerblue/player.cs:
datablock TSShapeConstructor(PlayerBlueDts)
data/shapes/playerred/player.cs
datablock TSShapeConstructor(PlayerRedDts)
Then you can referrer to that model and get its animations script.
I hope that helps?
#10
www.garagegames.com/mg/forums/result.thread.php?qt=35506
and
www.garagegames.com/mg/forums/result.thread.php?qt=41082
I learned something new here and will try again.
11/21/2006 (8:29 pm)
MB: That willl be awesome if you could make it into a resource. I have been trying this for a while and no luck. I am trying make bot to run different paths or loading different bots or players into a game. www.garagegames.com/mg/forums/result.thread.php?qt=35506
and
www.garagegames.com/mg/forums/result.thread.php?qt=41082
I learned something new here and will try again.
#11
I basically loaded all the models the same way in my \server\scripts\player.cs file which contains my info about the player.
Because each model basically share the same sounds, playerDebris, etc. the only thing i added/updated was the PlayerData datablock.
Example:
NOTE: That i have the 'exec' statement before the 'PlayerData' datablock for each PlayerData
now inside of
("~/data/shapes/game_characters/skeleton/skeleton_def.cs");
I renamed the "PlayerDts" to SkeletonFirePowDts
("~/data/shapes/game_characters/orc/player.cs");
Its TSShapeConstructor should look like
It could look like something like this:
11/21/2006 (11:28 pm)
In my game i have an orc, a skeleton, a guy, and some robotsI basically loaded all the models the same way in my \server\scripts\player.cs file which contains my info about the player.
Because each model basically share the same sounds, playerDebris, etc. the only thing i added/updated was the PlayerData datablock.
Example:
NOTE: That i have the 'exec' statement before the 'PlayerData' datablock for each PlayerData
exec("~/data/shapes/game_characters/skeleton/skeleton_def.cs");
datablock PlayerData(SkeletonFirePow)
{
... Player's info....
}
exec("~/data/shapes/game_characters/orc/player.cs");
datablock PlayerData(Orc)
{
... Player's info....
}etc....now inside of
("~/data/shapes/game_characters/skeleton/skeleton_def.cs");
I renamed the "PlayerDts" to SkeletonFirePowDts
datablock TSShapeConstructor(SkeletonFirePowDts)
{
.... Your animation sequence....
}and for the other character:("~/data/shapes/game_characters/orc/player.cs");
Its TSShapeConstructor should look like
datablock TSShapeConstructor(OrcDts)
{
.... Your animation sequence....
}And of course if you want to load that character to something like an AI, just point the AI datablock to one of these two. The same goes for the user's character.It could look like something like this:
datablock PlayerData(DemoPlayer : SkeletonFirePow)
{
...
}or something like this:// Create the player object
%player = new Player() {
dataBlock = Orc;
client = %this;
};I hoped that this brief info helps.
#12
If you have:
It only share the Greeny if you have this. Question do you have to put an Spawnsphere or a marker in game to work?
I have this also in aiPlayer.cs
I added this also below.
don't you need to have something like this(spawn different bot) and this is not working. sniff:)
I have also this below this in aiPLayer.cs below function AIPlayer::spawn(%name,%spawnPoint)
In player.cs I put this at top exec("~/data/shapes/greeny/player.cs");
because if put this below. Game Crashed.
Sorry, for the novice question. Still learning scripting...and hopefully I get it soon. hehe
12/04/2006 (12:53 pm)
I have a few Question:) I am still tinkering with this resource and others like it. Don't you have to call it on different path. In order to have different (different coloured Korks, (greeny bluey)) bots to run on it's own separate path. If you have:
function AIManager::spawn(%this)
{
%player = AIPlayer::spawnOnPath("Bluey","MissionGroup/Paths/Path1");
%player.followPath("MissionGroup/Paths/Path1",-1);
%player = AIPlayer::spawnOnPath("Greeny","MissionGroup/Paths2/Path2");
%player.followPath("MissionGroup/Paths2/Path2",-1);
%player.mountImage(CrossbowImage,0);
%player.setInventory(CrossbowAmmo,1000);
return %player;
} It only share the Greeny if you have this. Question do you have to put an Spawnsphere or a marker in game to work?
I have this also in aiPlayer.cs
datablock PlayerData(DemoPlayer : GreenyBody)
{
shootingDelay = 2000;
};I added this also below.
datablock PlayerData(DemoPlayer : BlueyBody)
{
shootingDelay = 2000;
};don't you need to have something like this(spawn different bot) and this is not working. sniff:)
function AIManager::spawnBluey(%this)
{
%player = AIBluey::spawnOnPath("Bluey","MissionGroup/Paths4/Path4");
%player.followPath("MissionGroup/Paths4/Path4",-1);
%player.mountImage(CrossbowImage,0);
%player.setInventory(CrossbowAmmo,1000);
return %player;
}I have also this below this in aiPLayer.cs below function AIPlayer::spawn(%name,%spawnPoint)
function AIPlayer::spawn(%name,%spawnPoint)
{
// Create the demo player object
%player = new AiPlayer() {
dataBlock = DemoPlayer;
path = "";
};
MissionCleanup.add(%player);
%player.setShapeName(%name);
%player.setTransform(%spawnPoint);
return %player;
} function AIPlayer::spawnBluey(%name,%spawnPoint)
{
// Create the demo player object
%player = new AiPlayer() {
dataBlock = bluey;
path = "";
};
MissionCleanup.add(%player);
// Player setup
%player.setMoveSpeed(1);
%player.setTransform(pickSpawnPoint());
%player.setEnergyLevel(60);
%player.setShapeName(%name);
return %player;
}In player.cs I put this at top exec("~/data/shapes/greeny/player.cs");
because if put this below. Game Crashed.
datablock PlayerData(GreenyBody ...
Sorry, for the novice question. Still learning scripting...and hopefully I get it soon. hehe
#13
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=11733
12/04/2006 (12:58 pm)
My resource is here: www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=11733
Torque Owner Amarnauth Sukhu
I am unfamiliar on how to post question, but yea, i just figured out how to make a post on the forums and i just created a copy of this blog there.
I had looked at player.cs.
I saw the datablock PlayerData(PlayerBodyOrc)
{
shapeFile = "~/data/shapes/game_characters/orc/player.dts";
....
}
where we can change the shape file to point at another dts file.
but see on top:
->exec("~/data/shapes/game_characters/orc/player.cs");
the exec will load the triggers for that game character. Triggers for running, jumping, etc.
The problem that i am having is that, i have several characters, typically an AI who is not an 'orc' but another character that have a different set of sequence for running, jumping, looking...,
->exec("~/data/shapes/game_characters/X/XX.cs");
I know that you can not have both exec(..), loaded on the player.cs.
Any suggestions on how to go about this??