Armageddon
Teapot
I'm making this thread as a modders resource, I'll add little bits of code for weapons/cores/items whenever i can. Others are welcome to do the same. All code posted in this thread can be used in any manner by any coder for whatever purpose.
A few requested snippets to start it off.
Shotgun Fire function, at least 10 requests for this.
Directional Boosts, too many requests.
Boosts the player in his/her current moving direction. Slightly modified jumppad code.
This could also be used with function Boost:nUse( %this, %obj). For testing i just threw it in my grenade onThrow function.
A few requested snippets to start it off.
Shotgun Fire function, at least 10 requests for this.
Code:
//-----------------------------------------------------------------------------
// Shotgun - Arma 11/28/11
//-----------------------------------------------------------------------------
// Projectile for the Shotgun.
datablock LinearProjectileData(ShotgunProjectile)
{
projectileShapeName = "legions/data/shapes/weapons/chaingun/tracer.dts";
scale = "0.43 1 0.43";
hasTracer = true;
tracerWidth = 0.45; // 0.3;
tracerLength = 40.0;
tracerMaterialName = ChaingunTracerMaterial;
tracerOffset = 0.3; //6
tracerGrowthScale = 0.05;
// damage
directDamage = 3.5; //5
radiusDamage = 0;
damageRadius = 1.25; //2.25
areaImpulse = 20; //30
damageType = $DamageType::ChaingunProjectile;
deleteOnExplode = false;
// effects
explosionPlayer = "ChaingunBulletExplosionPlayer";
explosionTerrain = "ChaingunBulletExplosionTerrain";
explosionObject = "ChaingunBulletExplosionObject";
// velocity
muzzleVelocity = 800; //1000
forwardVelInheritFactor = 1.0;
sideVelInheritFactor = 0.0;
// timing
armingDelay = 25;
lifetime = 4000;
fadeDelay = 3500;
// physics
isBallistic = false;
gravityMod = 0.0;
// chaingun ghosts don't (currently, 3/13/08) need this stuff
sendLifetimeToGhosts = false;
sendSourceObjectToGhosts = false;
sendCurrTickToGhosts = false;
doDistanceFade = true;
startFadeDistance = 300;
endFadeDistance = 450;
};
new ScriptObject(ShotgunIcon)
{
class = IconInfo;
name = Shotgun;
containerIcon = "client/gui/images/hud/weaponIcons/rocketLauncher";
ammoIcon = "client/gui/images/hud/weaponIcons/BoltLauncherAmmo";
};
new ScriptObject(ShotgunReticle)
{
class = ReticleInfo;
name = Shotgun;
image = "client/gui/images/hud/reticles/BoltReticle01";
frames = "2 1";
normalFrame = 0;
armedFrame = 1;
};
datablock ItemData(Shotgun)
{
class = Weapon;
image = ShotgunImage;
iconInfo = RocketLauncherIcon;
reticleInfo = RocketLauncherReticle;
longName = "Shotgun";
shortName = "SG";
};
datablock ItemData(ShotgunAmmo)
{
class = Ammo;
item = Shotgun;
};
// Shotgun image
datablock ShapeBaseImageData(ShotgunImage)
{
//canLockOn = false;
//lockAcquisitionTime = 3;
class = WeaponImage;
item = Shotgun;
ammo = ShotgunAmmo;
projectile = ShotgunProjectile;
projectileType = LinearProjectile;
shapeFile = "legions/data/shapes/Weapons/skybolt/bolttemp.dts";
emap = true;
cursorTexture = "client/gui/images/hud/targetingCursor";
burstCount = 1;
burstDelay = 120;
mountPoint = $WeaponSlot;
firstPerson = false;
eyeOffset = "0.7 0.25 -0.5";
correctMuzzleVector = true;
ProjectileSpread = 0.8;
// Check ammo, do appropriate activate animation
stateName[0] = "PreActivate";
stateTransitionOnAmmo[0] = "Activate";
stateTransitionOnNoAmmo[0] = "ActivateNoAmmo";
stateName[1] = "Activate";
stateSequence[1] = "activate";
stateTransitionOnTimeout[1] = "Ready";
stateTimeoutValue[1] = 0.5;
stateName[2] = "ActivateNoAmmo";
stateSequence[2] = "activatenoammo";
stateTransitionOnTimeout[2] = "NoAmmo";
stateTimeoutValue[2] = 0.5;
stateName[3] = "Ready";
stateScript[3] = "onReady";
stateWaitForTimeout[3] = false;
stateSequence[3] = "ready";
stateTransitionOnTriggerDown[3] = "Fire";
stateTransitionOnNoAmmo[3] = "NoAmmo";
stateName[4] = "Fire";
stateTimeoutValue[4] = 0.17; //was 0.4;
stateTransitionOnTimeout[4] = "CheckAmmo";
stateSequence[4] = "fire";
stateFire[4] = true;
stateAllowImageChange[4] = false;
stateFullSound[4] = SkyboltImpactSound;// RocketLauncherFireSound;
stateScript[4] = "onFire";
stateName[5] = "CheckAmmo";
stateTransitionOnAmmo[5] = "Reload";
stateTransitionOnNoAmmo[5] = "NoAmmoStart";
stateAllowImageChange[5] = false;
stateName[6] = "Reload";
stateScript[6] = "onReload";
stateSequence[6] = "reload";
stateSequenceStartPosition[6] = 0.0;
stateSequenceEndPosition[6] = 0.4;
stateTransitionOnTimeout[6] = "Reloaded";
stateTimeoutValue[6] = 0.17; //was 0.7;
stateAllowImageChange[6] = false;
stateFullSound[6] = SkyboltLoadingSound;
stateName[7] = "Reloaded";
stateSequence[7] = "reload";
stateSequenceStartPosition[7] = 0.4;
stateSequenceEndPosition[7] = 1.0;
stateTransitionOnTimeout[7] = "Ready";
stateTimeoutValue[7] = 0.17;
stateName[8] = "NoAmmoStart";
stateSequence[8] = "noammostart";
stateTransitionOnTimeout[8] = "NoAmmo";
stateTimeoutValue[8] = 2.0;
stateWaitForTimeout[8] = false;
stateTransitionOnTriggerDown[8] = "DryFire";
stateTransitionOnAmmo[8] = "Reload";
stateName[9] = "NoAmmo";
stateSequence[9] = "noammo";
stateTransitionOnTriggerDown[9] = "DryFire";
stateTransitionOnAmmo[9] = "Reload";
stateName[10] = "DryFire";
stateTimeoutValue[10] = 0.3;
stateWaitForTimeout[10] = true;
stateTransitionOnTimeout[10] = "CheckAmmo";
stateSequence[10] = "dryfire";
stateFullSound[10] = RocketLauncherDryFireSound;
};
function ShotgunImage::onFire(%this, %obj, %slot)
{
if (!isObject(%obj))
return;
if (%obj.getClassName() $= "Player")
Game.cancelInvincibility(%obj);
%projectile = %this.projectile;
%obj.decInventory(%this.ammo,1);
%muzzleVector = %obj.getMuzzleVector(%slot);
%objectVelocity = %obj.getVelocity();
%muzzleVelocity = VectorAdd(
VectorScale(%muzzleVector, %projectile.muzzleVelocity),
VectorScale(%objectVelocity, %projectile.velInheritFactor));
for(%i = 0; %i < 20; %i++)
{
%x = (getRandom() - 0.5) * 0.1 * 3.1415926 * %this.projectileSpread;
%y = (getRandom() - 0.5) * 0.1 * 3.1415926 * %this.projectileSpread;
%z = (getRandom() - 0.5) * 0.1 * 3.1415926 * %this.projectileSpread;
%mat = MatrixCreateFromEuler(%x SPC %y SPC %z);
%vector = MatrixMulVector(%mat, %muzzleVelocity);
%p = new (%this.projectileType)()
{
dataBlock = %projectile;
initialVelocity = %vector;
initialPosition = %obj.getMuzzlePoint(%slot);
sourceObject = %obj;
sourceSlot = %slot;
client = %obj.client;
};
MissionCleanup.add(%p);
}
}
Directional Boosts, too many requests.
Boosts the player in his/her current moving direction. Slightly modified jumppad code.
This could also be used with function Boost:nUse( %this, %obj). For testing i just threw it in my grenade onThrow function.
Code:
function Grenade::onThrow( %this, %obj, %source )
{
%BoostImpulse = 5000;
%BoostImpulseZ = 500;
Game.cancelInvincibility(%source);
%moveDir = VectorNormalize(VectorMul(%source.getVelocity(), "1 1 0"));
%impulse = VectorAdd(VectorScale(%moveDir, %BoostImpulse), "0 0" SPC %BoostImpulseZ);
%source.applyImpulse("0 0 0", %impulse);
}