Assigning objects to players
by Jules · in Torque Game Engine · 12/19/2007 (2:46 pm) · 6 replies
Hi,
I have 3 players that are selectable on joining the game. How do I go about assigning them their own weapons/inventory in game.cs based on their PlayerBody datablock, or is there another way of doing this?
Currently the default %player.setInventory(Crossbow,1); means they all get the crossbow.
I have 3 players that are selectable on joining the game. How do I go about assigning them their own weapons/inventory in game.cs based on their PlayerBody datablock, or is there another way of doing this?
Currently the default %player.setInventory(Crossbow,1); means they all get the crossbow.
#2
I have seperate player.cs files for each of the players. Each one has its own player datablock, defined by PlayerBody1, PlayerBody2, PlayerBody3.
The client side GUI allows you to select which player you want to use and puts them in game. However I'm not sure you can use the datablock to define who gets what objects assigned to them.
Maybe I need to define a class for each of the players and define it that way.
12/20/2007 (2:46 am)
I'm not sure that would work.I have seperate player.cs files for each of the players. Each one has its own player datablock, defined by PlayerBody1, PlayerBody2, PlayerBody3.
The client side GUI allows you to select which player you want to use and puts them in game. However I'm not sure you can use the datablock to define who gets what objects assigned to them.
Maybe I need to define a class for each of the players and define it that way.
#3
For my game I use a seperate file called setup_ships.cs, which i guess can be aded to your game.cs.
So in the function GameConnection::createPlayer(%this, %spawnPoint, %shipType) I create my Ship... Yours will just be a Player:
Then further down after you've set the Transform, you just do a case statement. Here's an extract from mine:
Hope that helps
12/20/2007 (5:18 am)
Should be fairly similar to what I do mounting guns on the selected ship.For my game I use a seperate file called setup_ships.cs, which i guess can be aded to your game.cs.
So in the function GameConnection::createPlayer(%this, %spawnPoint, %shipType) I create my Ship... Yours will just be a Player:
// human player!
%player = new FlyingVehicle()
{
dataBlock = %shipType;
//dataBlock = ScoutShip;
//dataBlock = InterceptorShip;
//dataBlock = DroneCarrierShip;
client = %this;
};
MissionCleanup.add(%player);Then further down after you've set the Transform, you just do a case statement. Here's an extract from mine:
%ShipType = %player.getDataBlock().getName();
switch$(%ShipType)
{
case "FighterShip":
//Primary
%player.incInventory(Pulsar, 1);
%player.incInventory(PulsarAmmo, PulsarAmmo.maxInventory);
%player.use(Pulsar);
//Secondary
%player.incInventory(ThunderLauncher,1);
%player.incInventory(ThunderLauncherAmmo, ThunderLauncherAmmo.maxInventory);
%player.use(ThunderLauncher);
case "AssaultShip":
//Primary
%player.incInventory(AssaultCannon,1);
%player.incInventory(AssaultCannonAmmo, AssaultCannonAmmo.maxInventory);
%player.use(AssaultCannon);
//Secondary
..
.Hope that helps
#4
This is big help - thanks. I had something like that with the switching, but without the key components ,getDataBlock() and getName so I was not far off - well, maybe by a mile :)
12/20/2007 (7:57 am)
Hi James Laker.This is big help - thanks. I had something like that with the switching, but without the key components ,getDataBlock() and getName so I was not far off - well, maybe by a mile :)
#5
12/20/2007 (8:05 am)
I do this in a resource I made if wanna look at it. www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=11733
#6
12/20/2007 (8:22 am)
Thanks MB. I used your resource in a previous version of our game and forgot about it, it will come in handy as a reference, when I implement teams. Can this resource be easily tied into a gui selection at startup instead of in the game as an observer then joining?
Torque Owner James W.
could you use if statement
if (%player1)
this inventory
else (%player2)
this inventory
just an Idea, I still learning