Game Development Community

Use a different weapon but with select with ONE key

by CIMO · in General Discussion · 09/08/2006 (10:40 am) · 17 replies

HI...
I use this code fore select a different weapon with ONE key...

In "default.bind.cs" i put this:
function Specializzazione(%val)
{
   if (%val)
      commandToServer('Specializzazione');
}
moveMap.bind( keyboard, "9", Specializzazione );

In "commands.cs" i put this:
function serverCmdSpecializzazione(%client)
{
    if(%this.kit.kitid == 3)
	%currentWeapon = %client.player.getMountedImage($WeaponSlot[9]);
    if(%this.kit.kitid == 4)
	return;
}

In "inventory.cs" i put this:
$weaponInSlot[9] = "attrezzaturaMedica";

$maxWeaponSlot = 9;

else if(%curWeapon $= "attrezzaturaMedica")
            %slot = 9;

But if press a "9 key" NOT function.....Why?
Thanks for help

#1
09/08/2006 (11:12 am)
Try like this in default.bind.cs

moveMap.bindCmd(keyboard, "2", "commandToServer('use',\"AssaultRifle\");", "");
#2
09/08/2006 (11:41 am)
? no not this.....
I have two type of player and i use a ONE key for select a weapon with this player....
But with this ONE key i select a different weapon in base a different player.......
See the my up code....
ONE key EGUALS KEY for select a different weapon in base a different player....
#3
09/08/2006 (11:42 am)
I think he's trying to use one button to cycle between two different weapons Michael.

Looks like his player has two classes of medical kits which he would like to be able to cycle through using keyboard 9.
#4
09/08/2006 (11:45 am)
If(%this.kit.kitid == 4)
return;

This use for another soldier.... equals a metod for medic medic =P
But a this metod not function....Why?
#5
09/08/2006 (11:53 am)
Well what is %this.kit.kitid?

Where is it being defined?

Is it within the your weapons ShapeBaseImageData datablock?
#6
09/08/2006 (12:00 pm)
Ok....mmm
I use this "%this.kit.kitid == 4" for select a type o f player....A my modify....
When start the game whit a GUI select a "%this.kit.kitid == 4" (my type of player) =) and all ok...
But i have a medic and engineer and i use a "9 kEY" for use a different weapon but equals key for medic and engineer...
This -> "%this.kit.kitid == 4" stay on game.cs
and when in command.cs see a "if(%this.kit.kitid == 3)" a medic have a this weapon whit press a "9 key" and when "if(%this.kit.kitid == 4)" a enginner have a weapon with press a "9 key" but have a different weapon of medic
#7
09/08/2006 (12:02 pm)
Ok, so you want one type of player to press keyboard 9 and use weapon A. Then another type of player would press keyboard 9 and weapon B would be selected. Is this correct?
#8
09/08/2006 (12:03 pm)
Yes =D see a up post i edited =P
#9
09/08/2006 (12:15 pm)
So why don't you do it this way.

In default.bind.cs create two functions which define each player type's key bindings.

Example:
function medicalPlayer1Keybindings()
{
   echo("---->medicalPlayer1");

   moveMap.bindCmd(keyboard, "9", "commandToServer('use',\"attrezzaturaMedica\");", "");
}

function medicalPlayer2Keybindings()
{
   echo("---->medicalPlayer2");

   moveMap.bindCmd(keyboard, "9", "commandToServer('use',\"someOtherMedica\");", "");
}

Then all you have to do is execute the appropriate function, most likely in game.cs, when that type of player is selected.

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

   // Create the player object
   %player = new Player() {
      dataBlock = %this.armor;
      client = %this;
   };

   MissionCleanup.add(%player);

   //Player setup...
   %player.setTransform(%spawnPoint);
   %player.setShapeName(%this.name);

   // Starting equipment for Defence players
   if (%this.kit.kitid $= "MedicalPlayer1")
      GameConnection::equipMedicalPlayer1(%player);

   if (%this.kit.kitid $= "MedicalPlayer2")
      GameConnection::equipMedicalPlayer2(%player);

   // 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);
}

function GameConnection::equipMedicalPlayer1(%player)
{
   medicalPlayer1Keybindings();

   echo("-->Medical player 1 weapon layout loaded");
   // Starting equipment

   %player.setInventory(stuff,1);
   %player.setInventory(stuffAmmo,30);

   %player.setInventory(moreStuff,1);
   %player.setInventory(moreStuffAmmo,30);

   %player.use(Cocaine);
}

function GameConnection::equipMedicalPlayer2(%player)
{
   medicalPlayer2Keybindings();

   echo("-->Medical player 2 weapon layout loaded");
   // Starting equipment

   %player.setInventory(stuff,1);
   %player.setInventory(stuffAmmo,30);

   %player.setInventory(moreStuff,1);
   %player.setInventory(moreStuffAmmo,30);

   %player.use(Cocaine);
}

See what you can do with that. I'm tired now and must go to bed, good luck =)
#10
09/09/2006 (5:38 am)
YES =) i use half our code and half my code and now function =) thanks for support =)
#11
09/09/2006 (6:01 am)
That's the way to do it, mix and match.

Glad you got it working, make sure my name is spelt correctly within your credits screen ;)
#12
09/09/2006 (6:04 am)
YES OF COURSE I A MEN OF VALOR =)
Tim jus a question....You know a ArmThread?
I would create a different Pose for different Weapon....Help me to lear a create a armThread?
#13
09/09/2006 (6:10 am)
All you have to do is put something like this in weapon.cs
function WeaponImage::onMount(%this,%obj,%slot)
{
   // Arm position
   if (%this.armthread $= "")
      %obj.setArmThread(look);
   else
      %obj.setArmThread(%this.armThread);
...
...

Then add a value to your ShapeBaseImageData section for each weapon specifying which armThread you would like to use.
armThread = "lookms";

That's it, aside from actually creating the armThread for your model etc.
#14
09/09/2006 (6:13 am)
And how generate a armThread in model?
#15
09/09/2006 (6:18 am)
Depends what modeling application you're using.

If I remember correctly you're using MilkShape.

If I am correct than this article on TDN will explain it all for you:

TGE/How to setup Blend Sequences in Milkshape3D
#16
09/09/2006 (6:26 am)
Oh yes i test with this but i have a problem....The armTrhead start ok for different weapon but see strange...
See not normal...on the contrary...But i send you a my player.ms3d (in milkShape) for you see and to correct it in correct way...
Please if i learn a armThread my game is suit and it's very pretty instead that a one pose for all weapon =(
thanks help
#17
09/09/2006 (7:12 am)
Never? please----- =(