Game Development Community

Gun script ( i bought it this time )

by Mark Junior · in Torque Game Engine · 01/15/2007 (7:58 am) · 26 replies

Hey, i bought the modern weapons pack this time and now ive copied the crossbow script to make a script for an AWP. ( well i used the m16.cs file as a resource which is made out of the crossbow script file that came with the soldier pack ) the code wont work please help me and tell me what errors there are ( nothing in console.log ) i need a pro to do this:


/-----------------------------------------------------------------------------
// Torque Game Engine
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// Crossbow weapon. This file contains all the items related to this weapon
// including explosions, ammo, the item and the weapon item image.
// These objects rely on the item & inventory support system defined
// in item.cs and inventory.cs
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// Sounds profiles

datablock AudioProfile(AwpReloadSound)
{
filename = "~/data/sound/crossbow_reload.ogg";
description = AudioClose3d;
preload = true;
};

datablock AudioProfile(AwpFireSound)
{
filename = "~/data/sound/crossbow_firing.ogg";
description = AudioClose3d;
preload = true;
};

datablock AudioProfile(AwpFireEmptySound)
{
filename = "~/data/sound/crossbow_firing_empty.ogg";
description = AudioClose3d;
preload = true;
};

datablock AudioProfile(AwpExplosionSound)
{
filename = "~/data/sound/crossbow_explosion.ogg";
description = AudioDefault3d;
preload = true;
};

//-----------------------------------------------------------------------------
// M16 ammo projectile splash

datablock ParticleData(AwpSplashMist)
{
dragCoefficient = 2.0;
gravityCoefficient = -0.05;
inheritedVelFactor = 0.0;
constantAcceleration = 0.0;
lifetimeMS = 400;
lifetimeVarianceMS = 100;
useInvAlpha = false;
spinRandomMin = -90.0;
spinRandomMax = 500.0;
textureName = "~/data/shapes/soldier/splash";

colors[0] = "0.7 0.8 1.0 1.0";
colors[1] = "0.7 0.8 1.0 0.5";
colors[2] = "0.7 0.8 1.0 0.0";

sizes[0] = 0.5;
sizes[1] = 0.5;
sizes[2] = 0.8;
times[0] = 0.0;
times[1] = 0.5;
times[2] = 1.0;
};

datablock ParticleEmitterData(AwpSplashMistEmitter)
{
ejectionPeriodMS = 5;
periodVarianceMS = 0;
ejectionVelocity = 3.0;
velocityVariance = 2.0;
ejectionOffset = 0.0;
thetaMin = 85;
thetaMax = 85;
phiReferenceVel = 0;
phiVariance = 360;
overrideAdvance = false;
lifetimeMS = 250;
particles = "AwpSplashMist";
};

datablock ParticleData( AwpSplashParticle )
{
dragCoefficient = 1;
gravityCoefficient = 0.2;
inheritedVelFactor = 0.2;
constantAcceleration = -0.0;
lifetimeMS = 600;
lifetimeVarianceMS = 0;
colors[0] = "0.7 0.8 1.0 1.0";
colors[1] = "0.7 0.8 1.0 0.5";
colors[2] = "0.7 0.8 1.0 0.0";
sizes[0] = 0.5;
sizes[1] = 0.5;
sizes[2] = 0.5;
times[0] = 0.0;
times[1] = 0.5;
times[2] = 1.0;
};
Page «Previous 1 2
#1
01/15/2007 (7:59 am)
Datablock ParticleEmitterData( AwpSplashEmitter )
{
ejectionPeriodMS = 1;
periodVarianceMS = 0;
ejectionVelocity = 3;
velocityVariance = 1.0;
ejectionOffset = 0.0;
thetaMin = 60;
thetaMax = 80;
phiReferenceVel = 0;
phiVariance = 360;
overrideAdvance = false;
orientParticles = true;
lifetimeMS = 100;
particles = "AwpSplashParticle";
};

datablock SplashData(AwpSplash)
{
numSegments = 15;
ejectionFreq = 15;
ejectionAngle = 40;
ringLifetime = 0.5;
lifetimeMS = 300;
velocity = 4.0;
startRadius = 0.0;
acceleration = -3.0;
texWrap = 5.0;

texture = "~/data/shapes/soldier/splash";

emitter[0] = M16SplashEmitter;
emitter[1] = M16SplashMistEmitter;

colors[0] = "0.7 0.8 1.0 0.0";
colors[1] = "0.7 0.8 1.0 0.3";
colors[2] = "0.7 0.8 1.0 0.7";
colors[3] = "0.7 0.8 1.0 0.0";
times[0] = 0.0;
times[1] = 0.4;
times[2] = 0.8;
times[3] = 1.0;
};

datablock ParticleData(AwpExplosionSparks)
{
textureName = "~/data/shapes/soldier/spark";
dragCoefficient = 1;
gravityCoefficient = 0.0;
inheritedVelFactor = 0.2;
constantAcceleration = 0.0;
lifetimeMS = 250;
lifetimeVarianceMS = 50;

sizes[0] = 0.6;
sizes[1] = 0.5;
sizes[2] = 0.3;

times[0] = 0.0;
times[1] = 0.5;
times[2] = 1.0;
};

datablock ParticleEmitterData(AwpExplosionSparkEmitter)
{
ejectionPeriodMS = 3;
periodVarianceMS = 0;
ejectionVelocity = 5;
velocityVariance = 1;
ejectionOffset = 0.0;
thetaMin = 0;
thetaMax = 0;
phiReferenceVel = 0;
phiVariance = 0;
overrideAdvances = false;
orientParticles = true;
lifetimeMS = 100;
particles = "AwpExplosionSparks";

useEmitterSizes = false;
};

datablock ParticleData(AwpExplosionWaterSparks)
{
textureName = "~/data/shapes/particles/bubble";
dragCoefficient = 0;
gravityCoefficient = 0.0;
inheritedVelFactor = 0.2;
constantAcceleration = 0.0;
lifetimeMS = 500;
lifetimeVarianceMS = 350;

colors[0] = "0.4 0.4 1.0 1.0";
colors[1] = "0.4 0.4 1.0 1.0";
colors[2] = "0.4 0.4 1.0 0.0";

sizes[0] = 0.5;
sizes[1] = 0.5;
sizes[2] = 0.5;

times[0] = 0.0;
times[1] = 0.5;
times[2] = 1.0;
};

datablock ParticleEmitterData(AwpExplosionWaterSparkEmitter)
{
ejectionPeriodMS = 3;
periodVarianceMS = 0;
ejectionVelocity = 4;
velocityVariance = 4;
ejectionOffset = 0.0;
thetaMin = 0;
thetaMax = 60;
phiReferenceVel = 0;
phiVariance = 360;
overrideAdvances = false;
orientParticles = true;
lifetimeMS = 200;
particles = "AwpExplosionWaterSparks";
};

datablock ExplosionData(AwpExplosion)
{
soundProfile = M16ExplosionSound;
lifeTimeMS = 1200;

// Volume particles
particleEmitter = AwpExplosionSparkEmitter;
particleDensity = 15;
particleRadius = 1;

// Camera Shaking
shakeCamera = false;
#2
01/15/2007 (8:02 am)
// Impulse
impulseRadius = 0.5;
impulseForce = 15;

// Dynamic light
lightStartRadius = 2;
lightEndRadius = 3;
lightStartColor = "0.9 1 0.5";
lightEndColor = "0 0 0";
};

datablock ExplosionData(AwpWaterExplosion)
{
soundProfile = AwpExplosionSound;

// Volume particles
particleEmitter = AwpExplosionBubbleEmitter;
particleDensity = 375;
particleRadius = 2;


// Point emission
emitter[0] = AwpExplosionBubbleEmitter;
emitter[1] = AwpExplosionWaterSparkEmitter;



// Camera Shaking
shakeCamera = false;

// Impulse
impulseRadius = 0.5;
impulseForce = 15;

// Dynamic light
lightStartRadius = 2;
lightEndRadius = 3;
lightStartColor = "0 0.5 0.5";
lightEndColor = "0 0 0";
};

//-----------------------------------------------------------------------------
// Projectile Object

datablock ProjectileData(AwpProjectile)
{
projectileShapeName = "~/data/shapes/soldier/tracer.dts";
directDamage = 20;
// PUT HERE: explosion = M16Explosion semicolon
// PUT HERE: waterexplosion = M16WaterExplosion semicolon

particleWaterEmitter= AwpAmmoBubbleEmitter;

splash = AwpSplash;

muzzleVelocity = 3000; // default 150
velInheritFactor = 0.3;

armingDelay = 0;
lifetime = 5000;
fadeDelay = 5000;
bounceElasticity = 0;
bounceFriction = 0;
isBallistic = true;
gravityMod = 0;

hasLight = false; // default true
lightRadius = 4;
lightColor = "0.5 0.5 0.25";

hasWaterLight = true;
waterLightColor = "0 0.5 0.5";
};

function AwpProjectile::onCollision(%this,%obj,%col,%fade,%pos,%normal)
{
// Apply damage to the object all shape base objects
if (%col.getType() & $TypeMasks::ShapeBaseObjectType)
%col.damage(%obj,%pos,%this.directDamage,"AwpAmmo");

// Radius damage is a support scripts defined in radiusDamage.cs
// Push the contact point away from the contact surface slightly
// along the contact normal to derive the explosion center. -dbs
radiusDamage
(%obj, VectorAdd(%pos, VectorScale(%normal, 0.01)),
%this.damageRadius,%this.radiusDamage,"Radius",40);
}


//-----------------------------------------------------------------------------
// Ammo Item

datablock ItemData(AwpAmmo)
{
// 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 = "~/data/shapes/crossbow/ammo.dts";
mass = 1;
elasticity = 0.2;
friction = 0.6;

// Dynamic properties defined by the scripts
pickUpName = "Awp bullets";
maxInventory = 20;
};


//--------------------------------------------------------------------------
// 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 AwpImage is used.

datablock ItemData(Awp)
{
// 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";
#3
01/15/2007 (8:02 am)
// Basic Item properties
shapeFile = "~/data/shapes/awp/w_awp.dts";
mass = 1;
elasticity = 0.2;
friction = 0.6;
emap = true;

// Dynamic properties defined by the scripts
pickUpName = "a Awp";
image = AwpImage;

};


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


datablock ShapeBaseImageData(AwpImage)
{
// Basic Item properties
shapeFile = "~/data/shapes/awp/w_awp.dts";
emap = true;

// Specify mount point & offset for 3rd person, and eye offset
// for first person rendering.
mountPoint = 0;
eyeOffset = "0.5 0.4 -0.4"; // default is 0.1 0.4 -0.6

// 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";

// Projectile && Ammo.
item = Awp;
ammo = AwpAmmo;
projectile = AwpProjectile;
projectileType = Projectile;

// 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.

// 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";
stateTransitionOnTimeout[1] = "Ready";
stateTimeoutValue[1] = 0.6;
stateSequence[1] = "Activate";

// Ready to fire, just waiting for the trigger
stateName[2] = "Ready";
stateTransitionOnNoAmmo[2] = "NoAmmo";
stateTransitionOnTriggerDown[2] = "Fire";

// Fire the weapon. Calls the fire script which does
// the actual work.
stateName[3] = "Fire";
stateTransitionOnTimeout[3] = "Reload";
stateTimeoutValue[3] = 0.1;
stateFire[3] = true;
stateRecoil[3] = LightRecoil;
stateAllowImageChange[3] = false;
stateSequence[3] = "Fire";
stateScript[3] = "onFire";
stateSound[3] = AwpFireSound;

// Play the relead animation, and transition into
stateName[4] = "Reload";
stateTransitionOnNoAmmo[4] = "NoAmmo";
stateTransitionOnTimeout[4] = "Ready";
stateTimeoutValue[4] = 0.05;
stateAllowImageChange[4] = false;
stateSequence[4] = "Reload";
stateEjectShell[4] = true;
stateSound[4] = AwpReloadSound;

// No ammo in the weapon, just idle until something
// shows up. Play the dry fire sound if the trigger is
// pulled.
stateName[5] = "NoAmmo";
stateTransitionOnAmmo[5] = "Reload";
stateSequence[5] = "NoAmmo";
stateTransitionOnTriggerDown[5] = "DryFire";

// No ammo dry fire
stateName[6] = "DryFire";
stateTimeoutValue[6] = 1.0;
stateTransitionOnTimeout[6] = "NoAmmo";
stateSound[6] = AwpFireEmptySound;
};




//-----------------------------------------------------------------------------

function AwpImage::onFire(%this, %obj, %slot)
{
%projectile = %this.projectile;

// Decrement inventory ammo. The image's ammo state is update
// automatically by the ammo inventory hooks.
%obj.decInventory(%this.ammo,1);

// Determin initial projectile velocity based on the
// gun's muzzle point and the object's current velocity
%muzzleVector = %obj.getMuzzleVector(%slot);
%objectVelocity = %obj.getVelocity();
%muzzleVelocity = VectorAdd(
VectorScale(%muzzleVector, %projectile.muzzleVelocity),
VectorScale(%objectVelocity, %projectile.velInheritFactor));

// Create the projectile object
%p = new (%this.projectileType)() {
dataBlock = %projectile;
initialVelocity = %muzzleVelocity;
initialPosition = %obj.getMuzzlePoint(%slot);
sourceObject = %obj;
sourceSlot = %slot;
client = %obj.client;
};
MissionCleanup.add(%p);
return %p;
}
#4
01/15/2007 (8:02 am)
A long piece of code there aint it :D?
#5
01/15/2007 (8:07 am)
Hi there Saska
What is not working ?
#6
01/15/2007 (8:32 am)
The whole gun script is not doing anything. Yes i execed it in game.cs. I mean the gun script isnt working so that it doesnt do anything i was hoping for someone to checkout some errors.
#7
01/15/2007 (8:52 am)
If there is just one error, the whole thing might not work, so I'll look closely........................... The first few lines for the sound files, I believe should be, "new AudioProfile" not "datablock AudioProfile", I had that problem with my weather.

I'll keep looking.

EDIT-

Hmmmm.... Does the weapon mount? If so, put this at the top of the "onFire" code to make sure its being called,
echo("onFire has been called); If nothing happens when you pull the trigger, then the Image is probably not in mountPoint 0;

PS. Please post more info.
#8
01/15/2007 (9:03 am)
Dont think this is compiling
Change the D to d in datablock at this line
Datablock ParticleEmitterData( AwpSplashEmitter )

And voila then its working.

Edit : And i hope the first line look like this

//----------------------------------------------------------------------------
// Torque Game Engine
#9
01/15/2007 (9:43 am)
Its as if the script wasnt there it cant mount nothing when trying to implement it in mission editor its in static shapes folder too.
#10
01/15/2007 (9:44 am)
Or could someone owning the Modern Weapons Pack help me? Like create there own script for me ? i need help just got the weapons pack i knew it was only a art pack though.
#11
01/15/2007 (9:44 am)
Its as if the script wasnt there it cant mount nothing when trying to implement it in mission editor its in static shapes folder too.
#12
01/15/2007 (9:53 am)
Are you sure your program is loading the weapons script? Try adding an echo at the top of your script file, something like echo("########AWP SCRIPT LOADED############"); and when you play the game, check the console and see if you can see the echo.

--Amr
#13
01/15/2007 (9:55 am)
If you dont see the weapons and ammo in shapes
then you either have an error or dont exec the file.
check the console.log if the script is compiling !

I tested the script and it's working with the changes i showed above.
#14
01/16/2007 (2:50 am)
The script doesnt seem to be even compiling. It doesnt have a dso
#15
01/16/2007 (2:51 am)
Do you guys own the modern weps pack?
#16
01/16/2007 (5:08 am)
If there is no dso it means there is either A) an error that you can see in the console after the game loads or in the log file or B) you are not exec the right file.
#17
01/16/2007 (5:45 am)
I execed it in game.cs... no console.log nor ingame console errors. Could someone please owning the modern weps pack try help me? if theyve done a script :(.
#18
01/16/2007 (5:48 am)
Take look at line 1. You have
/-----------------------------------------------------------------------------

It should be
//-----------------------------------------------------------------------------

Take look at line 107. You have
Datablock ParticleEmitterData( AwpSplashEmitter )

It should be
Datablock ParticleEmitterData( AwpSplashEmitter )

This will get the script working then from there you tweak to get what you want.
#19
01/16/2007 (6:48 am)
WOOOHOOO THANKS THANKS OH THANKS!!! thanks alot guys you really helped! fucifier gave the little peacefull touch to make it work thanks!

if anyone knows how to make a good awp script tell me. How do i do shoot delays?
#20
01/16/2007 (6:55 am)
OH no! When i put the awp in mission editor and spawn it there in the shapes folder i cant pick it up. But i can mount it at the beginning of the game. :S And when i mount it to me with game.cs the only way i can i try mount ammo but it doesnt work. I only mount the wep and no ammo. Anyone know what i did wrong i cant pickup awp ammo nor the gun.
Page «Previous 1 2