Well when I experiment the cog with activated and deactivated messages, I found that if you hold your fire the weapon will continue to be activated, and when you stop the fire the deactivated message runs.
Then I made the cog to have a counter that increases by 1 when a shot is fired, and resets to 0 when you stop shooting. Accuracy is based on this brust number.
This cog weapon cog for a rifle/SMG that provides a 30 round clip capacity and accuracy decreases in long brusts. Feel free to use/copy/modifly it whatever to fulfill your needs. The less accuracy when moving and accuracy bonus when moving has not be implemented yet in this cog.
symbols
model povModel=strv.3do local
model weaponMesh=strg.3do local
keyframe mountAnim=StrVmnt.key local
keyframe dismountAnim=StrVdis.key local
keyframe povfireAnim=StrVpst1.key local
keyframe holsterAnim=kyhlstr.key local
sound mountSound=df_rif_ready.wav local
sound dismountSound=PutWeaponAway01.wav local
sound fireSound=30cal.wav local
sound outSound=trprout.wav local
template projectile=+chainbullet local
thing player local
vector randVec local
flex fireWait=0.05 local
flex holsterWait local
flex powerBoost local
flex autoAimFOV=25 local
flex autoAimMaxDist=5 local
int dummy local
int trackID=-1 local
int fireChannel=-1 local
int holsterTrack local
int mode local
int clipp=30 local
int brustnumber=0 local
message activated
message deactivated
message selected
message deselected
message autoselect
message fire
message timer
message trigger
end
# ========================================================================================
code
fire:
player = GetSourceRef();
mode = GetSenderRef();
// Check that the player is still alive.
if(GetThingHealth(player) <= 0)
{
Return;
}
// Check Ammo - If we are out, autoselect best weapon.
// It should always use two energy cells, but -- as in DF --
// allow the last fire if there is only one left...
if(GetInv(player, 11) < 1.0)
{
PlaySoundThing(outSound, player, 1.0, -1, -1, 0x80);
if((GetAutoSwitch() & 1))
SelectWeapon(player, AutoSelectWeapon(player, 1));
Return;
}
if(mode == 0)
{
if(clipp <= 0)
{
nofire = 1;
reloadmode = 1;
settimer(firewait * 50);
//print("reload");
powerBoost = GetInv(player, 63);
//jkPlayPOVKey(player, dismountAnim, 0, 0x18);
// setmountwait(player, getkeylen(dsmountanim));
// holsterTrack = PlayKey(player, holsterAnim, 1, 0x18);
// holsterWait = GetKeyLen(holsterAnim);
// SetMountWait(player, holsterWait);
PlayMode(player, 41);
PlaySoundThing(mountSound, player, 1.0, -1.0, -1.0, 0x80);
trackID = jkPlayPOVKey(player, mountAnim, 0, 0x14);
SetMountWait(player, GetKeyLen(mountAnim));
ChangeFireRate(player, fireWait /powerBoost);
clipp = 30;
return;
}
else if(nofire == 0)
{
//print("fire");
clipp = clipp - 1;
// Get random aiming error
if(brustnumber <= 1) randvec = vectorset(0, 0, 0);
else if(brustnumber <= 3) randvec = VectorSet((Rand()-0.5)*1, (Rand()-0.5)*2, 0.0);
if(brustnumber > 3) randVec = VectorSet((Rand()-0.5)*4, (Rand()-0.5)*5, 0.0);
printint(brustnumber);
SetPOVShake('0.0 -.003 0.0', '1.5 0.0 0.0', .05, 80.0);
dummy = FireProjectile(player, projectile, fireSound, 8, '0.0168 0.1896 0.00', randVec, 1.0, 0x30, autoAimFOV, autoAimFOV*2);
if(IsMulti())
{
ID = GetCurWeapon(player) * 10 + mode; //A unique ID to be retrieved in the trigger message with GetSourceRef().
SendTrigger(-1, ID, player, 0, 0, 0); //Send the trigger, so every player's computer will recieve the action
}
// SetThingVel(dummy, vectorScale(GetThingVel(dummy), 0.01));
ChangeInv( player, 11, -1.0 );
// jkPlayPOVKey( player, povfireAnim, 1, 0x38 );
brustnumber = brustnumber + 1;
powerBoost = GetInv(player, 63);
ChangeFireRate(player, fireWait/powerBoost);
Return;
}
}
else if(clipp < 30)
{
nofire = 1;
reloadmode = 1;
settimer(firewait * 50);
//print("reload");
powerBoost = GetInv(player, 63);
//jkPlayPOVKey(player, dismountAnim, 0, 0x18);
// setmountwait(player, getkeylen(dsmountanim));
// holsterTrack = PlayKey(player, holsterAnim, 1, 0x18);
// holsterWait = GetKeyLen(holsterAnim);
// SetMountWait(player, holsterWait);
PlayMode(player, 41);
PlaySoundThing(mountSound, player, 1.0, -1.0, -1.0, 0x80);
trackID = jkPlayPOVKey(player, mountAnim, 0, 0x14);
SetMountWait(player, GetKeyLen(mountAnim));
ChangeFireRate(player, fireWait /powerBoost);
clipp = 30;
return;
}
Return;
# ........................................................................................
activated:
player = GetSourceRef();
mode = GetSenderRef();
jkSetWaggle(player, '0.0 0.0 0.0', 0);
powerBoost = GetInv(player, 63);
ActivateWeapon(player, fireWait/powerBoost, mode);
Return;
# ........................................................................................
deactivated:
player = GetSourceRef();
jkSetWaggle(player, '10.0 7.0 0.0', 350);
DeactivateWeapon(player, mode);
nofire = 1;
reloadmode = 1;
settimer(firewait * 5);
brustnumber = 0;
Return;
# ........................................................................................
selected:
player = GetSourceRef();
PlayMode(player, 41);
PlaySoundThing(mountSound, player, 1.0, -1, -1, 0x80);
jkSetPOVModel(player, povModel);
SetArmedMode(player, 1);
jkSetWeaponMesh(player, weaponMesh);
jkSetWaggle(player, '10.0 7.0 0.0', 350);
trackID = jkPlayPOVKey(player, mountAnim, 0, 20);
SetMountWait(player, GetKeyLen(mountAnim));
jkClearFlags(player, 0x5);
SetCurWeapon(player, 3);
Return;
# ........................................................................................
deselected:
player = GetSourceRef();
PlaySoundThing(dismountSound, player, 1.0, -1, -1, 0x80);
jkPlayPOVKey(player, dismountAnim, 0, 0x18);
holsterWait = GetKeyLen(holsterAnim);
SetMountWait(player, holsterWait);
holsterTrack = PlayKey(player, holsterAnim, 1, 0x4);
SetTimerEx(holsterWait, 2, 0.0, 0.0);
if (trackID != -1)
{
jkStopPOVKey(player, trackID, 0);
trackID = -1;
}
jkSetWaggle(player, '0.0 0.0 0.0', 0);
Return;
# ........................................................................................
autoselect:
player = GetSourceRef();
// If the player has the weapon
if(GetInv(player, 3) != 0.0)
{
// If the player has ammo
if(GetInv(player, 11) != 0.0)
{
ReturnEx(600.0);
}
else
{
ReturnEx(-1.0);
}
}
else
{
ReturnEx(-1.0);
}
Return;
# ........................................................................................
timer:
if(reloadmode == 1)
{
print("timer contacted");
nofire = 0;
reloadmode = 0;
}
StopKey(player, holsterTrack, 0.0);
Return;
# ........................................................................................
trigger:
//Only fire on other player's comp...
if(GetLocalPlayerThing() == GetParam(0)) return; //If the shooter is yourself, then don't fire again.
if( (GetSourceRef() == 30) || (GetSourceRef() == 31) ) //In this case, bryar is weapon 2
{ //and fire mode could be 1 or 0. I just added to make a unique ID.
FireProjectile(GetParam(0), projectile, -1, 8, '0.0168 0.1896 0.00', randVec, 1.0, 0x30, autoAimFOV, autoAimFOV*2);
}
return;
# ........................................................................................
end
------------------
"...and may the Force be with you."
-Luke Skywalker
Dark Luke, known for dressed like Vader (But no helmets and computer stuffs on), ignites his green lightsaber, ready to fight against evil and defend the light side.
Zone name: Deedlit6
Jedi vs. Sith - Dark Luke's Jedi Knight web site: Informations, addons, etc.
[This message has been edited by Darth Maul (edited January 13, 2002).]