Problems Creating a New Weapon From the NewWeaponTemplate.cs Script
by JAGTutorials · in Technical Issues · 11/23/2011 (3:29 pm) · 1 replies
I have been trying to get a new weapon created.
I am following the tutorial at www.garagegames.com/community/blogs/view/9230 and tork.beffy.de/tutorials/simpleobjects/simpleweapon.html with a couple of changes.
It tells you to update /server/scripts/player.cs but instead it needs to be "game/art/datablocks/Player.cs"
I tried using the script in the tutorial, but when launching the game it would just hang. I also tried using the crossbow.cs script from previous versions without luck. Instead of using the script provided i wanted to start with /game/art/datablocks/weapons/NewWeaponTemplate.cs
I have it so i can drop the weaponitem and weaponammo in the editor. I can pick them up and switch to them. The weapon shows the fire animation and makes the firing sound
Problems
1. I don't see the projectile smoke, muzzle flash, or impact in the empty terrain map.
2. The weapon i imported is shown mounted at the elbow of the character when it is equipped instead of the hand. I have tried moving the mountpoint in max before export but it still shows on his elbow.
3. I see for some of the other weapons that they have DAE files that, when viewed in the shape editor, i can see a bone structure attached to the weapon. Is this something that i need to create and if so how?
After I get this figured out I am going to make a beginning to end tutorial. Thanks for any help or direction anyone can provide.
Below is my weapon pistol.cs script. anything i changed from the NewWeaponTemplate.cs script has a comment with JAG in it.
I am following the tutorial at www.garagegames.com/community/blogs/view/9230 and tork.beffy.de/tutorials/simpleobjects/simpleweapon.html with a couple of changes.
It tells you to update /server/scripts/player.cs but instead it needs to be "game/art/datablocks/Player.cs"
I tried using the script in the tutorial, but when launching the game it would just hang. I also tried using the crossbow.cs script from previous versions without luck. Instead of using the script provided i wanted to start with /game/art/datablocks/weapons/NewWeaponTemplate.cs
I have it so i can drop the weaponitem and weaponammo in the editor. I can pick them up and switch to them. The weapon shows the fire animation and makes the firing sound
Problems
1. I don't see the projectile smoke, muzzle flash, or impact in the empty terrain map.
2. The weapon i imported is shown mounted at the elbow of the character when it is equipped instead of the hand. I have tried moving the mountpoint in max before export but it still shows on his elbow.
3. I see for some of the other weapons that they have DAE files that, when viewed in the shape editor, i can see a bone structure attached to the weapon. Is this something that i need to create and if so how?
After I get this figured out I am going to make a beginning to end tutorial. Thanks for any help or direction anyone can provide.
Below is my weapon pistol.cs script. anything i changed from the NewWeaponTemplate.cs script has a comment with JAG in it.
//--------------------------------------------------------------------------
// Sounds
//--------------------------------------------------------------------------
// Added for Lesson 5 - Adding Weapons - 23 Sep 11
datablock SFXProfile(WeaponTemplateFireSound)
{
filename = "art/sound/weapons/wpn_fire";
description = AudioClose3D;
preload = true;
};
datablock SFXProfile(WeaponTemplateReloadSound)
{
filename = "art/sound/weapons/wpn_reload";
description = AudioClose3D;
preload = true;
};
datablock SFXProfile(WeaponTemplateSwitchinSound)
{
filename = "art/sound/weapons/wpn_switchin";
description = AudioClose3D;
preload = true;
};
datablock SFXProfile(WeaponTemplateIdleSound)
{
filename = "art/sound/weapons/wpn_idle";
description = AudioClose3D;
preload = true;
};
datablock SFXProfile(WeaponTemplateGrenadeSound)
{
filename = "art/sound/weapons/wpn_grenadelaunch";
description = AudioClose3D;
preload = true;
};
datablock SFXProfile(WeaponTemplateMineSwitchinSound)
{
filename = "art/sound/weapons/wpn_mine_switchin";
description = AudioClose3D;
preload = true;
};
//-----------------------------------------------------------------------------
// Added 28 Sep 11
datablock LightDescription( BulletProjectileLightDesc )
{
color = "0.0 0.5 0.7";
range = 3.0;
};
datablock ProjectileData( PistolProjectile ) //jag
{
projectileShapeName = "art/shapes/weapons/test/pistolprojectile.dts"; //jag
directDamage = 5;
radiusDamage = 0;
damageRadius = 0.5;
areaImpulse = 0.5;
impactForce = 1;
explosion = BulletDirtExplosion;
decal = BulletHoleDecal;
muzzleVelocity = 120;
velInheritFactor = 1;
armingDelay = 0;
lifetime = 992;
fadeDelay = 1472;
bounceElasticity = 0;
bounceFriction = 0;
isBallistic = false;
gravityMod = 1;
};
function PistolProjectile::onCollision(%this,%obj,%col,%fade,%pos,%normal) //jag
{
// Apply impact force from the projectile.
// Apply damage to the object all shape base objects
if ( %col.getType() & $TypeMasks::GameBaseObjectType )
%col.damage(%obj,%pos,%this.directDamage,"PistolProjectile"); //jag
}
//-----------------------------------------------------------------------------
datablock ProjectileData( PistolTemplateProjectile ) //jag
{
projectileShapeName = "art/shapes/weapons/test/pistolprojectile.dts"; //jag
directDamage = 5;
radiusDamage = 0;
damageRadius = 0.5;
areaImpulse = 0.5;
impactForce = 1;
muzzleVelocity = 120;
velInheritFactor = 1;
armingDelay = 0;
lifetime = 992;
fadeDelay = 1472;
bounceElasticity = 0;
bounceFriction = 0;
isBallistic = false;
gravityMod = 1;
};
function PistolTemplateProjectile::onCollision(%this,%obj,%col,%fade,%pos,%normal) //jag
{
// Apply impact force from the projectile.
// Apply damage to the object all shape base objects
if ( %col.getType() & $TypeMasks::GameBaseObjectType )
%col.damage(%obj,%pos,%this.directDamage,"PistolTemplateProjectile"); //jag
}
//-----------------------------------------------------------------------------
// Ammo Item
//-----------------------------------------------------------------------------
datablock ItemData(PistolAmmo) //jag
{
// Mission editor category
category = "Ammo";
// Add the Ammo namespace as a parent. The ammo namespace provides
// common ammo related functions and hooks into the inventory system.
className = "Ammo";
// Basic Item properties
shapeFile = "art/shapes/weapons/test/pistolprojectile.dts"; //jag
mass = 1;
elasticity = 0.2;
friction = 0.6;
// Dynamic properties defined by the scripts
pickUpName = "PistolAmmo"; //jag
maxInventory = 1000;
};
//--------------------------------------------------------------------------
// 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 NewWeaponTemplate is used.
//-----------------------------------------------------------------------------
datablock ItemData(PistolItem) //jag
{
// 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/test/pistol.dts"; //jag
mass = 1;
elasticity = 0.2;
friction = 0.6;
emap = true;
// Dynamic properties defined by the scripts
pickUpName = "Pistol"; //jag
description = "Pistol"; //jag
image = WeaponTemplateImage;
reticle = "crossHair";
};
datablock ShapeBaseImageData(WeaponTemplateImage)
{
// FP refers to first person specific features
// Defines what art file to use.
shapeFile = "art/shapes/weapons/test/pistol.dts"; //jag
shapeFileFP = "art/shapes/weapons/test/pistol.dts"; //jag
// Whether or not to enable environment mapping
//emap = true;
//imageAnimPrefixFP = "";
// Specify mount point & offset for 3rd person, and eye offset
// for first person rendering.
mountPoint = 0;
//firstPerson = true;
//eyeOffset = "0.001 -0.05 -0.065"; //jag
offset = "0 0 0";
firstPerson = true; //jag
useEyeNode = true; //jag
animateOnServer = true; //jag
// 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 = true;
// Add the WeaponImage namespace as a parent, WeaponImage namespace
// provides some hooks into the inventory system.
class = "WeaponImage";
className = "WeaponImage";
// Projectiles and Ammo.
item = PistolItem; //jag
ammo = PistolAmmo; //jag
//projectile = BulletProjectile;
//projectileType = Projectile;
//projectileSpread = "0.005";
// Properties associated with the shell casing that gets ejected during firing
//casing = BulletShell;
//shellExitDir = "1.0 0.3 1.0";
//shellExitOffset = "0.15 -0.56 -0.1";
//shellExitVariance = 15.0;
//shellVelocity = 3.0;
// Properties associated with a light that occurs when the weapon fires
lightType = "WeaponFireLight"; //added WeaponFireLight and removed comment out
lightColor = "0.992126 0.968504 0.708661 1";
lightRadius = "4";
lightDuration = "100";
lightBrightness = 2;
// Properties associated with shaking the camera during firing
//shakeCamera = false;
//camShakeFreq = "0 0 0";
//camShakeAmp = "0 0 0";
// Images have a state system which controls how the animations
// are run, which sounds are played, script callbacks, etc. This
// state system is downloaded to the client so that clients can
// predict state changes and animate accordingly. The following
// system supports basic ready->fire->reload transitions as
// well as a no-ammo->dryfire idle state.
// If true, allow multiple timeout transitions to occur within a single tick
// useful if states have a very small timeout
//useRemainderDT = true;
// Initial start up state
stateName[0] = "Preactivate";
stateTransitionOnLoaded[0] = "Activate";
stateTransitionOnNoAmmo[0] = "NoAmmo";
// Activating the gun. Called when the weapon is first
// mounted and there is ammo.
stateName[1] = "Activate";
stateTransitionGeneric0In[1] = "SprintEnter";
stateTransitionOnTimeout[1] = "Ready";
stateTimeoutValue[1] = 0.5;
stateSequence[1] = "switch_in";
// Ready to fire, just waiting for the trigger
stateName[2] = "Ready";
stateTransitionGeneric0In[2] = "SprintEnter";
stateTransitionOnMotion[2] = "ReadyMotion";
stateTransitionOnTimeout[2] = "ReadyFidget";
stateTimeoutValue[2] = 10;
stateWaitForTimeout[2] = false;
stateScaleAnimation[2] = false;
stateScaleAnimationFP[2] = false;
stateTransitionOnNoAmmo[2] = "NoAmmo";
stateTransitionOnTriggerDown[2] = "Fire";
stateSequence[2] = "idle";
// Same as Ready state but plays a fidget sequence
stateName[3] = "ReadyFidget";
stateTransitionGeneric0In[3] = "SprintEnter";
stateTransitionOnMotion[3] = "ReadyMotion";
stateTransitionOnTimeout[3] = "Ready";
stateTimeoutValue[3] = 6;
stateWaitForTimeout[3] = false;
stateTransitionOnNoAmmo[3] = "NoAmmo";
stateTransitionOnTriggerDown[3] = "Fire";
stateSequence[3] = "idle_fidget1";
// Ready to fire with player moving
stateName[4] = "ReadyMotion";
stateTransitionGeneric0In[4] = "SprintEnter";
stateTransitionOnNoMotion[4] = "Ready";
stateWaitForTimeout[4] = false;
stateScaleAnimation[4] = false;
stateScaleAnimationFP[4] = false;
stateSequenceTransitionIn[4] = true;
stateSequenceTransitionOut[4] = true;
stateTransitionOnNoAmmo[4] = "NoAmmo";
stateTransitionOnTriggerDown[4] = "Fire";
stateSequence[4] = "run";
// Fire the weapon. Calls the fire script which does
// the actual work.
stateName[5] = "Fire";
stateTransitionGeneric0In[5] = "SprintEnter";
stateTransitionOnTimeout[5] = "Reload";
stateTimeoutValue[5] = 0.15;
stateFire[5] = true;
stateRecoil[5] = "";
stateAllowImageChange[5] = false;
stateSequence[5] = "fire";
stateScaleAnimation[5] = false;
stateSequenceNeverTransition[5] = true;
stateSequenceRandomFlash[5] = true; // use muzzle flash sequence
stateScript[5] = "onFire";
stateSound[5] = WeaponTemplateFireSound;
stateEmitter[5] = GunFireSmokeEmitter;
stateEmitterTime[5] = 0.025;
// Play the reload animation, and transition into
stateName[6] = "Reload";
stateTransitionGeneric0In[6] = "SprintEnter";
stateTransitionOnNoAmmo[6] = "NoAmmo";
stateTransitionOnTimeout[6] = "Ready";
stateWaitForTimeout[6] = "0";
stateTimeoutValue[6] = 0.05;
stateAllowImageChange[6] = false;
//stateSequence[6] = "reload";
stateEjectShell[6] = true;
// No ammo in the weapon, just idle until something
// shows up. Play the dry fire sound if the trigger is
// pulled.
stateName[7] = "NoAmmo";
stateTransitionGeneric0In[7] = "SprintEnter";
stateTransitionOnAmmo[7] = "ReloadClip";
stateScript[7] = "onClipEmpty";
// No ammo dry fire
stateName[8] = "DryFire";
stateTransitionGeneric0In[8] = "SprintEnter";
stateTimeoutValue[8] = 1.0;
stateTransitionOnTimeout[8] = "NoAmmo";
stateScript[8] = "onDryFire";
// Play the reload clip animation
stateName[9] = "ReloadClip";
stateTransitionGeneric0In[9] = "SprintEnter";
stateTransitionOnTimeout[9] = "Ready";
stateWaitForTimeout[9] = true;
stateTimeoutValue[9] = 3.0;
stateReload[9] = true;
stateSequence[9] = "reload";
stateShapeSequence[9] = "Reload";
stateScaleShapeSequence[9] = true;
// Start Sprinting
stateName[10] = "SprintEnter";
stateTransitionGeneric0Out[10] = "SprintExit";
stateTransitionOnTimeout[10] = "Sprinting";
stateWaitForTimeout[10] = false;
stateTimeoutValue[10] = 0.5;
stateWaitForTimeout[10] = false;
stateScaleAnimation[10] = false;
stateScaleAnimationFP[10] = false;
stateSequenceTransitionIn[10] = true;
stateSequenceTransitionOut[10] = true;
stateAllowImageChange[10] = false;
stateSequence[10] = "sprint";
// Sprinting
stateName[11] = "Sprinting";
stateTransitionGeneric0Out[11] = "SprintExit";
stateWaitForTimeout[11] = false;
stateScaleAnimation[11] = false;
stateScaleAnimationFP[11] = false;
stateSequenceTransitionIn[11] = true;
stateSequenceTransitionOut[11] = true;
stateAllowImageChange[11] = false;
stateSequence[11] = "sprint";
// Stop Sprinting
stateName[12] = "SprintExit";
stateTransitionGeneric0In[12] = "SprintEnter";
stateTransitionOnTimeout[12] = "Ready";
stateWaitForTimeout[12] = false;
stateTimeoutValue[12] = 0.5;
stateSequenceTransitionIn[12] = true;
stateSequenceTransitionOut[12] = true;
stateAllowImageChange[12] = false;
stateSequence[12] = "sprint";
};
Torque Owner Jeff Yaskus
jy games
Here is my 2 cents, but can't guarantee it fixes anything.
first, I'd rename "WeaponTemplateImage" to "PistolImage" and "PistolTemplateProjectile" to "PistolProjectile " ...
And keep in mind, anything not specifically created for this pistol, will just use the defaults ... including the onCollision for all projectiles.
So no need to redefine PistolTemplateProjectile::onCollision() , but I guess it doesn't hurt anything as is.
The pistol needs (2) mount points to work ... one in the pistol model called "mountPoint" and another in the character model called "mount0".
without mount0 in the model, it will default to the objects base (if I recall correctly) -- which sounds like is what you are seeing.
Actually, you could let all of this use the default for WeaponTemplates ... and just define the itemData(PistolItem) and ShapeBaseImageData(PistolImage) ... it can use the bullet, sound effects, etc ... that are defaults.
finally, the bone structure you noticed ... is new with release v1.2 and is only needed (i think) for mounting weapons in first person, with the new "first person hands" method.
otherwise, the its just as I mentioned above.
Hope this helps and good luck!