Game Development Community

SetSkinName of Mounted Weapon

by Chris "C2" Byars · in Torque Game Engine · 01/07/2006 (2:47 pm) · 9 replies

Curious as to how I would use setSkinName to affect a player's mounted weapon depending on the player's armor datablock choice.

In game.cs, in the player creation section, the datablock is set as
// Create the player object
   %player = new Player() {
      dataBlock = %this.armor;
      client = %this;
   };

How would I "if a certain armor, then setSkinName of all mounted weapons as this"?

#1
01/07/2006 (2:52 pm)
A quick search of the source and you have your answer:

ConsoleMethod( ShapeBase, mountImage, bool, 4, 6, "(ShapeBaseImageData image, int slot, bool loaded=true, string skinTag=NULL)")
#2
01/07/2006 (2:55 pm)
Ahah...I've been looking for that myself =)
#3
01/07/2006 (3:17 pm)
I know how setSkinName works, I'm just thinking out how to set it up so that a client's weapon uses a different texture depending on their armor choice.
#4
01/07/2006 (3:22 pm)
Umm.... I posted the MountImage console method, not setSkinName. Notice the fourth variabe: "SkinTag". I'm assuming that it uses the same setup as setSkinName, ie. you pass it something like "base", "red", or "desertCamo".
#5
01/07/2006 (9:17 pm)
Mine it working this way C2, this is post-game-connect though:

function GameConnection::createPlayer(%this, %spawnPoint, %armor)
{
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!" );
%this.player.kill("suicide");
}

%client.armor = %armor; // store this for reuse if player simply respawns.

switch$(%armor)
{
case "model_A":
// Create the player object
%player = new Player()
{
dataBlock = %armor;
client = %this;
};

%player.setInventory(Sword,1);
%player.setInventory(pistol,1);
%player.setInventory(CrossbowAmmo,10);
%player.mountImage(pistolImage,0);

break;

case "model_b":
// Create the player object
%player = new Player()
{
dataBlock = %armor;
client = %this;
};

%player.setInventory(Sword,1);
%player.setInventory(Crossbow,1);
%player.setInventory(CrossbowAmmo,10);
%player.mountImage(CrossbowImage,0);

break;
}

MissionCleanup.add(%player);

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

// 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);
}
#6
01/08/2006 (7:53 am)
In order to make my texture name correct, it is the same name as the client's armor choice. So in function GameConnection::createPlayer, I have:
// Create the player object
   %player = new Player() {
      dataBlock = %this.armor;
      client = %this;
   };
   MissionCleanup.add(%player);

   %skinTag = addTaggedString(%this.armor);

Then lower down where the Image of a weapon is mounted, I have:
%player.mountImage(XM8Image, 0, false, %skinTag);

Which correctly sets the correct texture to the client's choice of armor. Then in weapon.cs,
function Weapon::onUse(%data,%obj)
{

%skinTag = addTaggedString(%obj.client.armor);

   // Default behavoir for all weapons is to mount it into the
   // this object's weapon slot, which is currently assumed
   // to be slot 0
   if (%obj.getMountedImage($WeaponSlot) != %data.image.getId()) {
      %obj.mountImage(%data.image, $WeaponSlot, false, %skinTag);
   }
}

Solved. :)
#7
01/08/2006 (4:47 pm)
Hurrah!
#8
01/09/2006 (1:43 pm)
Nice, thank you C2!
This opens so many doors.

Ari
#9
01/09/2006 (2:19 pm)
Especially if you use that "add the arms/hands to the first person view" LOD code and want your arms and hands to have the same texture that your player actually does. Works like a dream for me.