Game Development Community

dev|Pro Game Development Curriculum

Multiple Player Class Selection

by mb · 11/30/2006 (1:21 pm) · 44 comments

<a href="/static/pg/resource/11733.classes.rtf">Download Code File</a>

This version has been updated for T3D and you don't need to use the old Team Implementation resource as I merged the two. The new version is found here: www.garagegames.com/community/resources/view/18383

Description:
This adds player classes and a selection menu to the Teams Implementation resource. Also adds spawn delays after choosing your classes. There 5 classes for each team and each class can have its own models, weapons, ammo, etc... <NOTE: the .rtf file explains the code in more detail if you need it.>

Note: Add the Team Implementation resource first before adding this resource:
www.garagegames.com/community/resources/view/2312


fps/server/scripts/game.cs

at the end of the file add:
function GameConnection::joinPlayerClass(%this, %classid)
{
   //We only have 5 player classes so if class is greater than 5 or less than 0 its invalid.
   if (%classid > 5 || %classid < 0)
       return false;  

   if (%this.respawn == 1)	// If player is spawning then dont spawn again!
     return false;
   
   if (%classid == 1)
       %this.playerClass = $PlayerClass1;

   if (%classid == 2) 
       %this.playerClass = $PlayerClass2; 
   
   if (%classid == 3) 
       %this.playerClass = $PlayerClass3;
   
   if (%classid == 4) 
       %this.playerClass = $PlayerClass4;
   
   if (%classid == 5) 
       %this.playerClass = $PlayerClass5;

  // MessageAll('MsgClientJoinTeam', 'c2%1 joined the %2 side', %this.name, %this.team.name, %this.team.teamId, %this, 

%this.sendGuid, %this.score,  %this.isAiControlled(), %this.isAdmin, %this.isSuperAdmin);
   
   %this.spawnPlayer(%this);        
}

Next at the top of the same file: fps/server/scripts/game.cs
add these: As you can see it uses playerClassId to identify what clas a player is, and a name. You could define more in here

if you wanted like weapons/ammo/armor, various traits etc... but I decided to do this before the player spawns.

$PlayerClass1 = new ScriptObject()
{   
    playerClassId = 1;
    name = Engineer;
};

$PlayerClass2 = new ScriptObject()
{   
    playerClassId = 2;
    name = Assault;
};

$PlayerClass3 = new ScriptObject()
{   
    playerClassId = 3;
    name = Medic;
};

$PlayerClass4 = new ScriptObject()
{   
    playerClassId = 4;
    name = Demolition;
};

$PlayerClass5 = new ScriptObject()
{   
    playerClassId = 5;
    name = Noob;
};

Next is the GUI selection screen, very basic, you can change it how you like.
Name it: ClassSelectDlg.gui and save it in client/ui

//--- OBJECT WRITE BEGIN ---
new GameTSCtrl(ClassSelectDlg) {
   Profile = "GuiDefaultProfile";
   HorizSizing = "right";
   VertSizing = "bottom";
   position = "0 0";
   Extent = "640 480";
   MinExtent = "8 8";
   Visible = "1";
   applyFilterToChildren = "1";
   cameraZRot = "0";
   forceFOV = "0";
      helpTag = "0";

   new GuiWindowCtrl() {
      Profile = "GuiWindowProfile";
      HorizSizing = "center";
      VertSizing = "center";
      position = "159 155";
      Extent = "321 170";
      MinExtent = "8 8";
      Visible = "1";
      maxLength = "255";
      resizeWidth = "1";
      resizeHeight = "1";
      canMove = "1";
      canClose = "1";
      canMinimize = "1";
      canMaximize = "1";
      MinSize = "50 50";
      closeCommand = "Canvas.popDialog(ClassSelectDlg);";
         helpTag = "0";

      new GuiTextCtrl() {
         Profile = "GuiBigTextProfile";
         HorizSizing = "center";
         VertSizing = "relative";
         position = "31 22";
         Extent = "259 40";
         MinExtent = "8 8";
         Visible = "1";
         text = "Choose your class";
         maxLength = "255";
            helpTag = "0";
      };
      new GuiButtonCtrl(Class1) {
         Profile = "GuiButtonProfile";
         HorizSizing = "right";
         VertSizing = "bottom";
         position = "11 63";
         Extent = "140 30";
         MinExtent = "8 8";
         Visible = "1";
         Command = "joinclass(1);";
         tooltipprofile = "GuiDefaultProfile";
         text = "Class 1";
         groupNum = "-1";
         buttonType = "PushButton";
            helpTag = "0";
      };
      new GuiButtonCtrl(Class2) {
         Profile = "GuiButtonProfile";
         HorizSizing = "right";
         VertSizing = "bottom";
         position = "11 97";
         Extent = "140 30";
         MinExtent = "8 8";
         Visible = "1";
         Command = "joinclass(2);";
         text = "Class 2";
         groupNum = "-1";
         buttonType = "PushButton";
            helpTag = "0";
      };
      new GuiButtonCtrl(Class3) {
         Profile = "GuiButtonProfile";
         HorizSizing = "right";
         VertSizing = "bottom";
         position = "11 132";
         Extent = "140 30";
         MinExtent = "8 8";
         Visible = "1";
         Command = "joinclass(3);";
         text = "Class 3";
         groupNum = "-1";
         buttonType = "PushButton";
            helpTag = "0";
      };
      new GuiButtonCtrl(Class4) {
         Profile = "GuiButtonProfile";
         HorizSizing = "right";
         VertSizing = "bottom";
         position = "157 64";
         Extent = "140 30";
         MinExtent = "8 8";
         Visible = "1";
         Command = "joinclass(4);";
         text = "Class 4";
         groupNum = "-1";
         buttonType = "PushButton";
            helpTag = "0";
      };
      new GuiButtonCtrl(Class5) {
         Profile = "GuiButtonProfile";
         HorizSizing = "right";
         VertSizing = "bottom";
         position = "157 97";
         Extent = "140 30";
         MinExtent = "8 8";
         Visible = "1";
         Command = "joinclass(5);";
         text = "Class 5";
         groupNum = "-1";
         buttonType = "PushButton";
            helpTag = "0";
      };
   };
};
//--- OBJECT WRITE END ---

then in fps/server/scripts/commands.cs I put the server commands which in the team implementation was done on the client, I

just moved it all into the server. I dont know if thats right or not, but I did it. If it doesnt work for you then move the joinclass function into a script on the client, like they do in the team code. Im gonna list the whole code cause Im sure I changed some stuff in here.

// Teamplay
function serverCmdJoinTeam(%client, %teamid)
{  
   %client.joinTeam(%teamid);	

}

// Teamplay - pick a class
function serverCmdJoinPlayerClass(%client, %classid)
{  
    %client.joinPlayerClass(%classid);
}

function joinclass(%classid)
{
   commandtoserver('JoinPlayerClass', %classid);
   Canvas.popDialog(ClassSelectDlg); //Hide the dialog once selection was made
}

function jointeam(%this, %teamid)
{
	commandtoserver('JoinTeam', %this, %teamid);
	Canvas.popDialog(TeamSelectDlg); 	//Hide team select menu
   Canvas.pushDialog(ClassSelectDlg); 	// Show class select menu    
}

function suicideJoinTeam(%this, %teamid)
{
	commandtoserver('Suicide');
	commandtoserver('JoinTeam', %this, %teamid);
	Canvas.popDialog(TeamSelectDlg2); 	//Hide team select menu
   Canvas.pushDialog(ClassSelectDlg); 	// Show class select menu	
}

Next in fps/client/init.cs add this exec: (note: if you did what I mentioned above and put a file clientside, you would need

to exec it here also. If you look at the team code you'll know what I mean.)

exec("./ui/ClassSelectDlg.gui");
 exec("./ui/TeamSelectDlg2.gui");

Next in game.cs again serverside... I added some code: This just resets some variables if needed (probably not needed but doesnt hurt to have them)

function GameConnection::onClientEnterGame(%this)
{
   commandToClient(%this, 'SyncClock', $Sim::Time - $Game::StartTime);

   // Create a new camera object. 
   %this.camera = new Camera()
   {      
      dataBlock = Observer;   
   };   

   MissionCleanup.add( %this.camera );
   %this.camera.scopeToClient(%this); 

   // Setup game parameters, the onConnect method currently starts 
   // everyone with a 0 score.
   %this.score = 0;
   %this.respawn = 0; // tracks whether a player is spawning or not
   %this.team = 0; //default team is 0 (observer)
   %this.playerClass = 0; // default class is 0
    
   //Spawn a camera by default on a observer point 
   %this.camera.setTransform(pickObserverPoint(%this));
   %this.camera.setVelocity("0 0 0"); 
   %this.setControlObject(%this.camera);
}

Then down a bit in game.cs the spawnplayer function: makes the player spawn after about ten seconds.

function GameConnection::spawnPlayer(%this)
{
	
   if (%this.respawn == 1)	// If player is spawning then dont spawn again!
     return;
   	
    %this.respawn = 1;
	
   // Combination create player and drop him somewhere
   %spawnPoint = pickSpawnPoint(%this);
   
   %this.schedule(10000,createPlayer,%spawnPoint); // delay spawn	
}

Next bit of code is where you set the classes & the player datablocks, weapons, ammo, etc... you could again do this at the

top of game.cs and then reference it here, but I just did it all in here... btw: change the player datablocks to your own. IE: PlayerBody1Class1, etc. and mount weapons/ammo.. how you like.


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!" );
   }

   // get the correct datablock for the player. This is the players class.
   
    // TEAM 1 DATABLOCKS
    if (%this.team.teamId == 1)
    {
        switch ( %this.playerClass.playerClassId )
        {
            // Class 1
            case 1:
                %classDatablock = PlayerBody1Class1;  // change to another datablock when we make new models for each class           
				

            // Class 2
            case 2:
                %classDatablock = PlayerBody1Class2;
                

            // Class 3
            case 3:
                %classDatablock = PlayerBody1Class3;
                

            // Class 4
            case 4:
                %classDatablock = PlayerBody1Class4;
                

            // Class 5
            case 5:
                %classDatablock = PlayerBody1Class5;
                
        }
    }
   
    // TEAM 2 DATABLOCKS
   if (%this.team.teamId == 2)
   {
      switch ( %this.playerClass.playerClassId )
      {
         // Class 1
         case 1:
            %classDatablock = PlayerBody2Class1;  // change to another datablock when we make new models for each class
            

         // Class 2
         case 2:
            %classDatablock = PlayerBody2Class2;
            

         // Class 3
         case 3:
            %classDatablock = PlayerBody2Class3;
            

         // Class 4
         case 4:
            %classDatablock = PlayerBody2Class4;
            

         // Class 5
         case 5:
            %classDatablock = PlayerBody2Class5;
            
        }
   }
   // Create the player object
   %player = new Player() {
      dataBlock = %classDatablock;
      client = %this;
   };
	
	
   MissionCleanup.add(%player);

   // Player setup...
   %player.setTransform(%spawnPoint);
   %player.setShapeName(%this.name);
   
   // Starting equipment
   // need to change this to a switch$ statement for each class...
	

    // TEAM 1 WEAPONS
    if (%this.team.teamId == 1)
    {
        switch ( %this.playerClass.playerClassId )
        {
            // Class 1
            case 1:
                %player.setInventory(Crossbow,1);
  	%player.setInventory(CrossbowAmmo,10);
   	%player.mountImage(CrossbowImage,0);
	

            // Class 2
            case 2:
	%player.setInventory(Pistol,1);
                %player.setInventory(PistolImage,1);
	%player.setInventory(PistolAmmoClip,4);
	%player.setInventory(Rifle,1);
  	%player.setInventory(RifleAmmoClip,3);
   	%player.mountImage(RifleImage,0);
                

            // Class 3
            case 3:
	%player.setInventory(Pistol,1);
  	%player.setInventory(PistolAmmoClip,4);
   	%player.mountImage(PistolImage,0);
                

            // Class 4
            case 4:
                %player.setInventory(Shotgun,1);
  	%player.setInventory(ShotgunAmmoClip,5);
   	%player.mountImage(ShotgunImage,0);
                

            // Class 5
            case 5:
                %player.setInventory(Shotgun,1);
  	%player.setInventory(ShotgunAmmoClip,5);
   	%player.mountImage(ShotgunImage,0);
                
        }
    }
   
    // TEAM 2 WEAPONS
   if (%this.team.teamId == 2)
    {
        switch ( %this.playerClass.playerClassId )
        {
            // Class 1
            case 1:
                %player.setInventory(Pistol,1);
  	%player.setInventory(PistolAmmo,10);
   	%player.mountImage(PistolImage,0);
                

            // Class 2
            case 2:
                %player.setInventory(Pistol,1);
  	%player.setInventory(PistolAmmo,10);
   	%player.mountImage(PistolImage,0);
                

            // Class 3
            case 3:
                %player.setInventory(Pistol,1);
  	%player.setInventory(PistolAmmo,10);
   	%player.mountImage(PistolImage,0);
                

            // Class 4
            case 4:
                %player.setInventory(Pistol,1);
  	%player.setInventory(PistolAmmo,10);
   	%player.mountImage(PistolImage,0);
                

            // Class 5
            case 5:
                %player.setInventory(Pistol,1);
  	%player.setInventory(PistolAmmo,10);
   	%player.mountImage(PistolImage,0);
                
        }
    }
  

   // 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); 
	%this.respawn = 0; // allow player to respawn after dying.	

   echo ("CLASS NAME: " @ %this.playerClass.name );

}

Still in game.cs comment out the spawnPlayer in function GameConnection::joinTeam because we dont do that here (we do it in GameConnection::joinPlayerClass).

//%this.spawnPlayer();  // in GameConnection::joinTeam

Then in player.cs

I inherited the same player datablock and just changed the dts model. Do this for all your players. PlayerBody1Class1 - PlayerBody2Class5. You dont have to change the models if you dont want to of course, you could just use just one. Put this after: datablock PlayerData(PlayerBody)

datablock PlayerData(PlayerBody1Class1 : PlayerBody)
{
    shapeFile = "~/data/shapes/player/player.dts";
};

datablock PlayerData(PlayerBody1Class2 : PlayerBody)
{
    shapeFile = "~/data/shapes/player/player.dts";
};
datablock PlayerData(PlayerBody1Class3 : PlayerBody)
{
    shapeFile = "~/data/shapes/player/player.dts";
};
datablock PlayerData(PlayerBody1Class4 : PlayerBody)
{
    shapeFile = "~/data/shapes/player/player.dts";
};
datablock PlayerData(PlayerBody1Class5 : PlayerBody)
{
    shapeFile = "~/data/shapes/player/player.dts";
};

datablock PlayerData(PlayerBody2Class1 : PlayerBody)
{
    shapeFile = "~/data/shapes/player/player.dts";
};
datablock PlayerData(PlayerBody2Class2 : PlayerBody)
{
    shapeFile = "~/data/shapes/player/player.dts";
};
datablock PlayerData(PlayerBody2Class3 : PlayerBody)
{
    shapeFile = "~/data/shapes/player/player.dts";
};
datablock PlayerData(PlayerBody2Class4 : PlayerBody)
{
    shapeFile = "~/data/shapes/player/player.dts";
};
datablock PlayerData(PlayerBody2Class4 : PlayerBody)
{
    shapeFile = "~/data/shapes/player/player.dts";
};


<EDIT>
When your already in game and want to switch$ team/classes.

make a new gui: TeamSelectDlg2.gui

//--- OBJECT WRITE BEGIN ---
new GameTSCtrl(TeamSelectDlg2) {
   Profile = "GuiDefaultProfile";
   HorizSizing = "right";
   VertSizing = "bottom";
   position = "0 0";
   Extent = "640 480";
   MinExtent = "8 8";
   Visible = "1";
   applyFilterToChildren = "1";
   cameraZRot = "0";
   forceFOV = "0";
      helpTag = "0";

   new GuiWindowCtrl() {
      Profile = "GuiWindowProfile";
      HorizSizing = "center";
      VertSizing = "center";
      position = "159 155";
      Extent = "321 170";
      MinExtent = "8 8";
      Visible = "1";
      maxLength = "255";
      resizeWidth = "1";
      resizeHeight = "1";
      canMove = "1";
      canClose = "1";
      canMinimize = "1";
      canMaximize = "1";
      MinSize = "50 50";
      closeCommand = "Canvas.popDialog(TeamSelectDlg2);";
         helpTag = "0";

      new GuiTextCtrl() {
         Profile = "GuiBigTextProfile";
         HorizSizing = "center";
         VertSizing = "relative";
         position = "32 30";
         Extent = "257 40";
         MinExtent = "8 8";
         Visible = "1";
         text = "Choose your team";
         maxLength = "255";
            helpTag = "0";
      };
      new GuiButtonCtrl(RedTeam) {
         Profile = "GuiButtonProfile";
         HorizSizing = "right";
         VertSizing = "bottom";
         position = "10 130";
         Extent = "140 30";
         MinExtent = "8 8";
         Visible = "1";
         Command = "suicideJoinTeam(1);";
         tooltipprofile = "GuiDefaultProfile";
         text = "Red Team";
         groupNum = "-1";
         buttonType = "PushButton";
            helpTag = "0";
      };
      new GuiButtonCtrl(BlueTeam) {
         Profile = "GuiButtonProfile";
         HorizSizing = "right";
         VertSizing = "bottom";
         position = "170 130";
         Extent = "140 30";
         MinExtent = "8 8";
         Visible = "1";
         Command = "suicideJoinTeam(2);";
         text = "Blue Team";
         groupNum = "-1";
         buttonType = "PushButton";
            helpTag = "0";
      };
   };
};
//--- OBJECT WRITE END ---

config.cs: you could just delete this file, the engine will make a new one for you
moveMap.bindCmd(keyboard, "m", "Canvas.pushDialog(TeamSelectDlg2);", "");

change defaultbind.cs:
moveMap.bindCmd(keyboard, "m", "Canvas.pushDialog(TeamSelectDlg2);", "");

and client/scripts/client/config.cs
moveMap.bindCmd(keyboard, "m", "Canvas.pushDialog(TeamSelectDlg2);", "");

When you press 'm' you get the TeamSelectDlg2 menu and it kills your player in "suicideJoinTeam".

And one last thing if it's not in there already add this line in bold to clientscriptsserverConnection.cs :

function GameConnection::initialControlSet(%this)
{
   echo ("*** Initial Control Object");

   // The first control object has been set by the server
   // and we are now ready to go.
   
   // first check if the editor is active
   if (!Editor::checkActiveLoadDone())
   {
      if (Canvas.getContent() != PlayGui.getId())
         Canvas.setContent(PlayGui);
        
         [b]
         // Teamplay - popup team select gui
         Canvas.pushDialog(TeamSelectDlg);[/b]
   }
}


Sorry if I left anything out, I coded this a few months back when I first got TGE.
Page «Previous 1 2 3 Last »
#1
11/30/2006 (6:48 pm)
Thanks alot for sharing, looking real good, doing a singel player, but thinking of maybe just modifing it to a profesions systems, so thanks alot, again =)
#2
12/01/2006 (3:06 pm)
No prob Paul Thanks!

Quick update: I found a small bug. A player could open the change team menu during a respawn and change to the other team, but spawn on the enemies spawn point. I changed the code in the resource already. Here's all that was needed:

function GameConnection::joinPlayerClass(%this, %classid)
{
   //We only have 5 player classes so if class is greater than 5 or less than 0 its invalid.
   if (%classid > 5 || %classid < 0)
       return false;  

   if (%this.respawn == 1)	// If player is spawning then dont spawn again!
     return false;


Just this line:

if (%this.respawn == 1) // If player is spawning then dont spawn again!
return false;
#3
12/15/2006 (9:49 am)
Great resource, thank you! (TGE 1.5)
#4
12/27/2006 (12:26 pm)
Awesome Resource!!
#5
12/28/2006 (12:06 pm)
I'm getting an error about there not being a servercmdSuicide
#6
01/11/2007 (6:38 am)
Look in starter.fps in fps/server/scripts/commands.cs. There should be a function defined already by default.
#7
03/14/2007 (12:10 pm)
Thank you so much... I'm going to learn this like the bible.
#8
03/21/2007 (12:22 pm)
I added the classes.rtf file to help explain the code in more detail, and basically in the order that it works.
#9
04/16/2007 (8:16 pm)
Okay I do have a question though. I am fairly new to scripting, but what if you wanted a single player game, for instance an rpg for simplicity. And wanted to create a character class screen (i.e. human, elf, dwarf, etc, etc, etc.) Would you use the same sequence of script but remove items that referred to a client?
#10
04/17/2007 (6:40 am)
Since I started with the Teamplay resource you would need to delete the code that checks if you're on team 1 or team 2, your player is still a client.

if (%this.team.teamId == 1)
if (%this.team.teamId == 2)

Also you can delete the %this.team = 0; //default team is 0 (observer) and all the JoinTeam functions.

Since you only need code for one player, I'd delete all of the team 2 stuff. So where it says "// TEAM 2 DATABLOCKS" & " // TEAM 2 WEAPONS" delete the whole "if statement". The CreatePlayer function should look something like:

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!" );
   }

   // get the correct datablock for the player. This is the players class.
   
    
    switch$ ( %this.playerClass.playerClassId )
    {
        // Class 1
        case 1:
            %classDatablock = PlayerBody1Class1;  // change to another datablock when we make new models for each class
               break;

        // Class 2
        case 2:
            %classDatablock = PlayerBody1Class2;
            break;

        // Class 3
        case 3:
            %classDatablock = PlayerBody1Class3;
            break;

        // Class 4
        case 4:
            %classDatablock = PlayerBody1Class4;
            break;

        // Class 5
        case 5:
            %classDatablock = PlayerBody1Class5;
            break;
    }
    
   
   // Create the player object
   %player = new Player() {
      dataBlock = %classDatablock;
      client = %this;
   };
	
	
   MissionCleanup.add(%player);

   // Player setup...
   %player.setTransform(%spawnPoint);
   %player.setShapeName(%this.name);
   
   // Starting equipment
   // need to change this to a switch$ statement for each class...
	

    // WEAPONS
    switch$ ( %this.playerClass.playerClassId )
    {
        // Class 1
    	case 1:
        	%player.setInventory(Crossbow,1);
		%player.setInventory(CrossbowAmmo,10);
   		%player.mountImage(CrossbowImage,0);
		break;

        // Class 2
        case 2:
		%player.setInventory(Pistol,1);
                %player.setInventory(PistolImage,1);
		%player.setInventory(PistolAmmoClip,4);
		%player.setInventory(Rifle,1);
  		%player.setInventory(RifleAmmoClip,3);
   		%player.mountImage(RifleImage,0);
                break;

        // Class 3
        case 3:
		%player.setInventory(Pistol,1);
  		%player.setInventory(PistolAmmoClip,4);
   		%player.mountImage(PistolImage,0);
                break;

        // Class 4
        case 4:
                %player.setInventory(Shotgun,1);
  		%player.setInventory(ShotgunAmmoClip,5);
   		%player.mountImage(ShotgunImage,0);
                break;

        // Class 5
        case 5:
                %player.setInventory(Shotgun,1);
  		%player.setInventory(ShotgunAmmoClip,5);
   		%player.mountImage(ShotgunImage,0);
                break;
    } 
    
  
   // 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); 
	%this.respawn = 0; // allow player to respawn after dying.	

   echo ("CLASS NAME: " @ %this.playerClass.name );

}
#11
04/17/2007 (6:03 pm)
Alright I will give this a shot. Thanks a bunch MB, I really need to get my feet wet and learn how to script . I have tried to break it down and learn, but it is so foreign to me.
#12
06/01/2007 (7:30 am)
update: I took out the breaks in the switch statements, didn't realize they don't do anything in torque script (even though someone told me before.. lol)

btw:
switch: is for numbers 1,2,3,etc...
switch$ is for strings

in case you're wondering...
#13
06/15/2007 (7:49 am)
How can i make it to where each class has his own set of key binds to pull out his class specific weapons? I would also like to make each class have his own run speed, health ect...
#14
06/15/2007 (8:27 am)
Quote:How can i make it to where each class has his own set of key binds to pull out his class specific weapons?

edit:
Make a new action map for that class. Then in GameConnection::createPlayer() change (push/pop) the 'moveMap' to your new actionMap depending on which class it is in the switch statement.


As for player speed you can use the 'sprint' resource. You could also add a variable to the playerClass script object for that and then in GameConnection::createPlayer change the speed of the player to that variable.
#15
06/15/2007 (1:14 pm)
Im very new to this and dont know what that mean, but here is my guess.. Add the key binds to each datablock like this?

// TEAM 1 DATABLOCKS
if (%this.team.teamId == 1)
{
switch ( %this.playerClass.playerClassId )
{
// Class 1
case 1:
%classDatablock = PlayerBody1Class1; // change to another datablock when we make new models for each class

moveMap.bindCmd(keyboard, "1", "commandToServer('use',\"ak47\");", "");


// Class 2
case 2:
%classDatablock = PlayerBody1Class2;

moveMap.bindCmd(keyboard, "1", "commandToServer('use',\"m16\");", "");


Its almost laughable because i know i am wrong, but i try lol
#16
06/15/2007 (1:39 pm)
I can't do it now I'm at work, but later I can show you how... but here's a couple ways to do it:

You can copy movemap.cs on the client side and rename it to whatever and change the binds in that file to whatever you want. Then make functions on the client side to push your new map and pop the movemap. Then make a server command to call the client side functions (commandToClient). Then in the switch statement call the server command using commandToServer.

Another way that may work. I can't remember which file it is where the functions are for the binds maybe in movemap.cs? You might be able change those functions to check which class you are and then switch weapons from there.
#17
06/15/2007 (1:53 pm)
the keybinds are in data/client/scripts/defaultbind.cs

Having a new defaultbind.cs file for each class seems like a good idea.

Another good idea i had (but dont know how to do) is give weapons a "class" like pistol, rifle, sniperrifle, ect ect then make it to where you can only carry one of each class. When you have lets say a rifle and try to pick up another rifle it will throw out the old rifle and pickup the new one. From there all you realy have to do is make a key bind for the weapons class. This is ultimatly what i plan to do, but i dont expect someone to tell me how i will just have to learn.
#18
06/17/2007 (7:52 am)
Couldnt i use a if statement to do something similar in my defaultbind.cs

---------------------------------------------------

function equippistol(%weapontoequip)
{
if (classid = 1)
%weapontoequip = deserteagle;

else if (classid = 2)
%weapontoequip = socom;
}

moveMap.bindCmd(keyboard, "1", "commandToServer('use',\"%weapontoequip\");", "");
#19
07/10/2007 (11:30 am)
Sorry it took so long to respond.

If your wanting to let the player pickup weapons you can do it in the weapons .cs file for example 'crossbow.cs'. There's a function in there for picking up the weapon when it's on the ground (not sure which function without looking but it should be easy to find). In that function just check which weapon the player already has equiped, and if it's a different weapon throw out the old one and equip the new one. When you equip a weapon use a variable on the player to track what weapon is equiped.
#20
07/11/2007 (3:01 pm)
Hi mb - this is a great resource - a quick question, how would I be able to define a key map in defaultbind.cs so that PlayerBody1Class1 can only press key "j" for jetpack and the others cannot?

Thanks in advance.

Jules.
Page «Previous 1 2 3 Last »