etqw-sdk/base/script/vehicles/weapons/stroybomb.script
2008-05-29 00:00:00 +00:00

63 lines
1.5 KiB
Text

object vehicle_weapon_stroybomb : vehicle_weapon_base {
void preinit();
void Fire();
string muzzleFlashFX;
float fireRate;
float spread;
float projectileIndex;
float jointHandle;
vector velocity;
entity vehicle;
}
void vehicle_weapon_stroybomb::preinit() {
projectileIndex = GetEntityDef( getKey( "def_projectile" ) );
vehicle = getVehicle();
jointHandle = vehicle.getJointHandle( getKey( "muzzle" ) );
muzzleFlashFX = getKey( "muzzle_flash" );
fireRate = getFloatKey( "fire_rate" );
spread = getFloatKey( "spread" );
velocity = getVectorKey( "velocity" );
}
void vehicle_weapon_stroybomb::Fire() {
vector origin = vehicle.getJointPos( jointHandle );
vector vehicleVelocity = vehicle.getLinearVelocity();
vehicleVelocity_z = 0.f;
float velocityLength = sys.vecLength( velocity );
vector forward;
if ( user != $null_entity ) {
forward = sys.angToForward( user.getRenderViewAngles() );
} else {
forward = vehicle.jointToWorldSpace( jointHandle, velocity ) * ( 1 / velocityLength );
}
vector projectileVelocity = forward * velocityLength;
float forwardVelocity = vehicleVelocity * forward;
if ( forwardVelocity > 0.0f ) {
projectileVelocity += forward * forwardVelocity;
}
vehicle.launchMissileSimple( user, vehicle, $null_entity, projectileIndex, -1, spread, origin, projectileVelocity );
vehicle.playJointEffect( muzzleFlashFX, jointHandle, 0 );
AddReFireDelay( fireRate );
RemoveCharge();
GoToIdle();
}