Game Development Community

Adding a player shield

by Jonathan Blair · in General Discussion · 03/04/2006 (8:35 am) · 1 replies

I am hoping someone can help me out with this. I have looked at the health patch item in starter.fps and the flag and shield code from realm wars and I cannot get my player to interact with my shields.

I originally started by using an onCollision function (similar to health patch) to have the player pickup the shield and mount the image when they ran over the shield. That didn't work so I went in and built my shield.cs file based on the flag and shield code from RW. Now I can get the shield in the game but I cannot get the player to pick it up or to use it if I add it to the player's inventory before hand. I even went so far as to just copy the entire server/scripts/weapon folder over from realm wars to see if I could get it to work and the same thing happened.

I am. as far as I can tell adding the correct code to game.cs and player.cs to run my script and set up the player's inventory but to no avail.

I have added my shield.cs code below, if anyone code take a look at it or point me towards a post/tut on adding non-weapon items that mount it would be much appreciated.

Thanks



//Begin Code



//Set Shield mount slot currently located on back of character
$Shieldslot = 2;


//=========================================================================
//Shield Item
//=========================================================================

datablock ItemData(Shield)
{
// Mission editor category
category = "Shields";
className = "Shield";
image = ShieldImage;
shapefile = "~/data/shapes/shield/shield.dts";
mass = 1.2;
elasticity = 0.2;
friction = 0.6;
pickupRadius = 3;
pickUpName = "a shield";
itemType="item";
maxInventory = 1;
};


//=======================================================================
//Shield Image
//=======================================================================
datablock ShapeBaseImageData(ShieldImage)
{
shapeFile = "~/data/shapes/shield/shield.dts";

emap = true;
mountPoint = $Shieldslot;
offset = "0 0 0";
className = "ShieldImage";
item = Shield;

};

//==========================================================================
//Shield Functions
//==========================================================================
function Shield::onThrow(%this,%user,%amount)
{
echo("Shield Throw\n");
// Remove the object from the inventory
if (%amount $= "")
%amount = 1;
if (%this.maxInventory !$= "")
if (%amount > %this.maxInventory)
%amount = %this.maxInventory;
if (!%amount)
return 0;
%user.decInventory(%this,%amount);

%user.unmountImage($Shieldslot);
return %obj;

// dont create a shield in the world when we get rid of ours.
// Construct the actual object in the world, and add it to
// the mission group so it's cleaned up when the mission is
// done. The object is given a random z rotation.
%obj = new Item()
{
datablock = %this;
rotation = "0 0 1 " @ (getRandom() * 360);
count = %amount;
};
MissionGroup.add(%obj);
return %obj;
}


function Shield::create(%data)
{
echo("Shield create\n");
// The mission editor invokes this method when it wants to create
// an object of the given datablock type. For the mission editor
// we always create "static" re-spawnable rotating objects.
%obj = new Item()
{
dataBlock = %data;
static = true;
rotate = true;
};
return %obj;
}


function Shield::onPickup(%this, %Shield, %player, %amount)
{
echo("Shield Pickup\n");
if (%player.getClassName() $= "Player")
{
ServerPlay3D(WeaponPickupSound,%Shield.getTransform());
%player.incInventory(%this,1);
%player.mountImage(%this.image, $Shieldslot);
%Shield.delete();
}
}

#1
03/04/2006 (9:43 am)
Might want to use a TGE forum for this. Normally don't tackle code in this general forum.