Game Development Community

Adding weapon into inventory

by William Goh (Joondalup IT TAFE) · in Torque 3D Professional · 10/15/2009 (11:20 pm) · 2 replies

Trying to place weapon into inventory. My weapon cs file contains the following code:

// ----------------------------------------------------------------------------
// Weapon Item. This is the item that exists in the world,
// i.e. when it's been dropped, thrown or is acting as re-spawnable item.
// When the weapon is mounted onto a shape, the Image is used.
// ----------------------------------------------------------------------------

datablock ItemData(M4A1Carbine)
{
// Mission editor category
category = "Weapon";

// Hook into Item Weapon class hierarchy. The weapon namespace
// provides common weapon handling functions in addition to hooks
// into the inventory system.
className = "Weapon";

// Basic Item properties
shapefile = "art/shapes/weapons/M4A1 Carbine/M4A1 Carbine.DAE";
mass = 3;
elasticity = 0.2;
friction = 0.6;
emap = true;

// Dynamic properties defined by the scripts
pickUpName = "M4A1 Carbine";
description = "Rifle";
image = M4A1CarbineImage;

// weaponHUD
previewImage = 'swarmer.png';
reticle = 'reticle_rocketlauncher';
};

// ----------------------------------------------------------------------------
// Image which does all the work. Images do not normally exist in
// the world, they can only be mounted on ShapeBase objects.
// ----------------------------------------------------------------------------

datablock ShapeBaseImageData(M4A1CarbineImage)
{
// Basic Item properties
shapefile = "art/shapes/weapons/M4A1 Carbine/M4A1 Carbine.DAE";
emap = true;

// Specify mount point & offset for 3rd person, and eye offset
// for first person rendering.
mountPoint = 0;
offset = "0.0 0.15 0.025";
eyeOffset = "0.25 0.6 -0.4"; // 0.25=right/left 0.5=forward/backward, -0.5=up/down

// When firing from a point offset from the eye, muzzle correction
// will adjust the muzzle vector to point to the eye LOS point.
// Since this weapon doesn't actually fire from the muzzle point,
// we need to turn this off.
correctMuzzleVector = false;

// Add the WeaponImage namespace as a parent, WeaponImage namespace
// provides some hooks into the inventory system.
className = "WeaponImage";

};

How to add this weapon into my inventory?

#1
10/15/2009 (11:48 pm)
Make sure you do this:

With your .cs placed in game\art\datablocks\weapons

open file game\art\datablocks\datablockExec.cs

Under the rocketlauncher line add:

exec("./weapons/M4A1Carbine.cs");



Inventory:
open file game\art\datablocks\player.cs

Under datablock PlayerData(DefaultPlayerData) look for:

// Allowable Inventory Items

Add:

maxInv[M4A1Carbine] = 1;
maxInv[M4A1CarbineAmmo] = 20;
#2
10/15/2009 (11:58 pm)
Oh yeah thanks. My weapon assigning works now. Number 1 is the rocket launcher and the second is the M4A1Carbine weapon. However doesnt work with the keypress of 2 but only the mouse wheel.

Cheers for your help :)