Massassi Forums Logo

This is the static archive of the Massassi Forums. The forums are closed indefinitely. Thanks for all the memories!

You can also download Super Old Archived Message Boards from when Massassi first started.

"View" counts are as of the day the forums were archived, and will no longer increase.

ForumsCog Forum → Need some help with this one...
Need some help with this one...
2003-07-11, 7:13 PM #1
Code:
# Jedi Knight Cog Script
#
# WEAP_STRIFLE.COG
#
# WEAPON 3 script - Stormtrooper Rifle
#
# The standard rifle used by the stormtroopers.  You can hold a rifle in each hand
# and fire them both at the same time, or have them alternate.
#
# - Affected by MagSealed sectors/surfaces.
#
#
# [YB & CYW] + [Stormtrooper]
#
# NOT SUPPORTED by LucasArts Entertainment Co.

symbols

# =Double=================================================================================

model       povModel=2strv.3do                  local                         
model       weaponMesh=strg.3do                local                         
model       weaponMesh2=2strglk.3do             local                         
model       lukusmodel=kyf2.3do                 local                         

# =Single=================================================================================

model       povModels=strv.3do                   local
model       weaponMeshs=strg.3do                 local

# =Double=================================================================================

keyframe     mountAnim=2StrVmnt.key              local                         
keyframe     dismountAnim=2strvdis.key           local                         
keyframe     povfireAnim1=2strvfirer.key         local                         
keyframe     povfireAnim2=2strvfirel.key         local                         
keyframe     povfireAnim3=2strvfireb.key         local                         
keyframe     drawgunAnim=2strgdraw.key           local                         
keyframe     holdgunAnim=2weapstand.key          local                         
keyframe     leftfireAnim=2strgfirel.key         local                         
keyframe     rightfireAnim=2strgfirer.key        local                         
keyframe     bothfireAnim=2strgfireb.key         local                         
keyframe     holsterAnim=kyhlstr.key             local                         

# =Single=================================================================================

keyframe    mountAnims=StrVmnt.key               local
keyframe    dismountAnims=StrVdis.key            local
keyframe    povfireAnims=StrVpst1.key            local
keyframe    holsterAnims=kyhlstr.key             local

# ========================================================================================

sound       mountSound=df_rif_ready.wav          local
sound       dismountSound=PutWeaponAway01.wav    local
sound       fireSound=trprsht2.wav               local
sound       outSound=trprout.wav                 local

template    projectile=+stlaser                  local

thing       player                               local

vector      randVec                              local
vector      randVec1                             local
# =Single=================================================================================
flex        firewaits=0.2
# ========================================================================================
flex        fireWait=0.5                         local                         
flex        holsterWait                          local                         
flex        powerBoost                           local                         
flex        autoAimFOV=25                        local                         
flex        autoAimMaxDist=5                     local                         

int         dummy=0                              local
int         trackID=-1                           local
int         trackID2=-1                          local
int         fireChannel=-1                       local
int         holsterTrack                         local
int         mode                                 local
int         shootframe=0                         local
# =Single==================================================================================
int         trackID1=-1                          local
# =========================================================================================


message     activated
message     deactivated
message     selected
message     deselected
message     autoselect
message     fire
message     timer

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.
   if(GetInv(player, 11) < 1.0)
   {
      PlaySoundThing(outSound, player, 1.0, -1, -1, 0x80);
      if((GetAutoSwitch() & 1))
         SelectWeapon(player, AutoSelectWeapon(player, 1));
      Return;
   }


   // Get random aiming error
   randVec = VectorSet((Rand()-0.25)*5, (Rand()-0.25)*5, 0.0);
   // Get random aiming error for the second gun
   randVec1 = VectorSet((Rand()-0.25)*5, (Rand()-0.25)*5, 0.0);

   SetPOVShake('0.0 -.003 0.0', '1.5 0.0 0.0', .05, 80.0);

   // If we have one rifle
   if((GetInv(player, 3) == 1))                  //Copied this from original weap_strifle
   {
	   // 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);
	   // SetThingVel(dummy, vectorScale(GetThingVel(dummy), 0.01));

	   ChangeInv( player, 11, -2.0 );
	   jkPlayPOVKey( player, povfireAnims, 1, 0x38 );

	   powerBoost = GetInv(player, 63);
	   ChangeFireRate(player, fireWaits/powerBoost);
   }
   // If we have 2 rifles
   if((GetInv(player, 3) == 2))
   {
	if(mode == 0)
	{
			if(shootframe == 0) //right weapon
			{
				JKPlayPOVKey(player, povfireAnim1, 1, 0x38);
				dummy = FireProjectile(player, projectile, firesound, 8, '0.0325 0.1624 0.0', randVec, 1.0, 0x20, autoAimFOV, autoAimFOV*2);
				if(trackID2 != -1)
				{
					Stopkey(player, trackID2, 0.0);
					trackID2 = -1;
				}
				playkey(player, rightfireAnim, 1, 0x38);

				shootframe = 1;
			}
			else
			if(shootframe == 1) //left weapon
			{
				jkPlayPOVKey(player, povfireAnim2, 1, 0x38);
				dummy =  FireProjectile(player, projectile, firesound, 8, '-0.0325 0.1624 0.0', randVec, 1.0, 0x20, autoAimFOV, autoAimFOV*2);
				if(trackID2 != -1)
				{
					Stopkey(player, trackID2, 0.0);
					trackID2 = -1;
				}
				playkey(player, leftfireAnim, 1, 0x38);
				shootframe = 0;
			}
			ChangeInv(player, 11, -1.0);

			powerBoost = GetInv(player, 63);
			ChangeFireRate(player, fireWait/2/powerBoost);
		}

		if(mode == 1)
		{
			if(GetInv(player, 11) > 1)
			{
				jkPlayPOVKey(player, povfireAnim3, 1, 0x38);
				{
				dummy = FireProjectile(player, projectile, fireSound, -1, '0.0325 0.1624 0.0', randVec, 1.0, 0x20, autoAimFOV, autoAimFOV*2);
				dummy = FireProjectile(player, projectile, fireSound, -1, '-0.0325 0.1624 0.0', randVec1, 1.0, 0x20, autoAimFOV, autoAimFOV*2);
				}
				ChangeInv(player, 11, -2.0);
			}
			else
			{
				jkPlayPOVKey(player, povfireAnim1, 1, 0x38);
				dummy = FireProjectile(player, projectile, fireSound, 8, '0.0325 0.1624 0.0', '0 0 0', 1.0, 0x20, autoAimFOV, autoAimFOV*2);
				ChangeInv(player, 11, -1.0);
			}
			if(trackID2 != -1)
			{
				Stopkey(player, trackID2, 0.0);
				trackID2 = -1;
			}
			playkey(player, bothfireAnim, 1, 0x38);
			SetTimerEx(GetKeyLen(bothfireAnim), 2, 0, 0);
			powerBoost = GetInv(player, 63);
			ChangeFireRate(player, fireWait/powerBoost);

	   }
   }
   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 );
   // If we have one
   if((GetInv(player, 3) == 1))        // Another from weap_strifle
   {
   	DeactivateWeapon(player, mode);
   }
   // If we have 2
   if((GetInv(player, 3) == 2))
   {
   	if(trackID2 == -1) trackID2 = playkey(player, holdgunAnim, 1, 0x4);
   }
   Return;

# ........................................................................................

selected:
   player = GetSourceRef();
   // If we have 1
   if((GetInv(player, 3) == 1))       // From weap_strifle
   {
	   PlayMode(player, 41);
	   PlaySoundThing(mountSound, player, 1.0, -1, -1, 0x80);
	   jkSetPOVModel(player, povModels);
	   SetArmedMode(player, 1);
	   jkSetWeaponMesh(player, weaponMeshs);
	   jkSetWaggle(player, '10.0 7.0 0.0', 350);
	   trackID1 = jkPlayPOVKey(player, mountAnims, 0, 20);
	   SetMountWait(player, GetKeyLen(mountAnims));
	   jkClearFlags(player, 0x5);
	   SetCurWeapon(player, 3);
   }
   // If we have 2
   if((GetInv(player, 3) == 2))
   {

	   jkSetPOVModel(player, povModel);    // two Rifles
	   SetThingModel(player, weaponMesh2);
   
	   jkSetWeaponMesh(player, weaponMesh);
	   SetArmedMode(player, 1);
	   PlaySoundThing(mountSound, player, 1.0, -1.0, -1.0, 0x80);
	   trackID = jkPlayPOVKey(player, mountAnim, 0, 20);
	   PlayKey(player, drawgunAnim, 1, 0x38);
	   SetTimerEx(GetKeyLen(drawgunAnim), 2, 0, 0);
	   jkClearFlags(player, 0x5);
	   jkSetWaggle(player, '10.0 7.0 0.0', 350);
	   SetMountWait(player, GetKeyLen(mountAnim));
	   SetCurWeapon(player, 3);
   }
   Return;

# ........................................................................................

deselected:
   player = GetSourceRef();
   // If we have 1
   if((GetInv(player, 3) == 1))
   {
	   PlaySoundThing(dismountSound, player, 1.0, -1, -1, 0x80);
	   jkPlayPOVKey(player, dismountAnims, 0, 0x18);
	   holsterWait = GetKeyLen(holsterAnims);
	   SetMountWait(player, holsterWait);
	   holsterTrack = PlayKey(player, holsterAnims, 1, 0x4);
	   SetTimerEx(holsterWaits, 2, 0.0, 0.0);
	   if (trackID1 != -1)
	   {
	      jkStopPOVKey(player, trackID1, 0);
	      trackID1 = -1;
	   }
	   jkSetWaggle(player, '0.0 0.0 0.0', 0);
   }
   if((GetInv(player, 3) == 2))
   {
	   PlaySoundThing(dismountSound, player, 1.0, -1, -1, 0x80);
	   jkPlayPOVKey(player, dismountAnim, 0, 18);
	   holsterWait = GetKeyLen(holsterAnim);
	   SetMountWait(player, holsterWait);
	   holsterTrack = PlayKey(player, holsterAnim, 1, 0x4);
	   SetTimerEx(holsterWait, 1, 0.0, 0.0);
	   if (trackID != -1)
	   {
	      jkStopPOVKey(player, trackID, 0);
	      trackID = -1;
	   }
	   if (trackID2 != -1)
	   {
	      StopKey(player, trackID2, 0);
	      trackID2 = -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 we have 1
   if((GetInv(player, 3) == 1))
   {
	   StopKey(player, holsterTrack, 0.0);
   }
   // If we have 2
   if((GetInv(player, 3) == 2))
   {
	   if(GetSenderID() == 1)
	   {
		StopKey(player, holsterTrack, 0.0);
		SetThingModel(player, lukusmodel);
	   }
	   else if(GetSenderID() == 2 && trackID2 == -1) trackID2 = playkey(player, holdgunAnim, 1, 0x4);
   }
   Return;

end

It won't change the the model(POV or external) when bin 3 is set at 2, It just keeps the models as they are until you deselect the weapon and select it again, then it's correct. Any ideas on how to make it work?

[EDIT]I spelled code wrong for the tags [http://forums.massassi.net/html/frown.gif][/EDIT]

------------------
Look for my current project, The Force in Your Soul.
Last week I cudn't evn spel grajuat, but now I is one.

*Takes out his blaster and fires shots at the wall, the blastmarks leave the words "S-TROOPER WUZ 'ERE!!!"

[This message has been edited by Stormtrooper (edited July 11, 2003).]
2003-07-11, 10:39 PM #2
Make sure that your bin is set to 2. Put a PrintInt(GetInv(player, 3)); in your selected message.

------------------
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
2003-07-12, 6:49 AM #3
When I first select it, it prints "1," after I pick up another stormtrooper rifle and deselect it, then select it again, it prints "2."
Like I said before, after I pick up the second stormtrooper rifle, It fires the 2 projectiles like it's supposed to, but I have to reselect it to get the models and the keyframes to change.

------------------
Look for my current project, The Force in Your Soul.
Last week I cudn't evn spel grajuat, but now I is one.

*Takes out his blaster and fires shots at the wall, the blastmarks leave the words "S-TROOPER WUZ 'ERE!!!"
2003-07-12, 8:57 AM #4
Perhaps after setting the player up with two guns, try: SendMessage(GetSelfCog(), Activated);

Might work, might not.

------------------
"The Just shall live by faith." - Galatians 3:11
To edit is human... To COG is divine!!

pegasus_1984: Stop bushing that dang suck button.
guitarofgold: NOOOOOOOOO!!!!
-------[end post]-------
Catloaf, meet mouseloaf.
My music
2003-07-12, 5:10 PM #5
No, that didn't work.
What if I had it, when the second rifle is picked up, call something like:
Code:
reactivate:
if(something == 0)
{
   if((GetInv(player, 3) == 2))
   {
      DeactivateWeapon(player, mode);
      Sleep(.05);
      ActivateWeapon( player, fireWait/powerBoost, mode );
      something = 1;
   }
}
else if(something == 1)
{
   return;
}
   Return;

The INT "something" would be there so that the message would only be called once so it doesn't deselect and reselect the weapon all the time.
Do you think that might work?

But does anyone have any ideas?

------------------
Look for my current project, The Force in Your Soul.
Last week I cudn't evn spel grajuat, but now I is one.

*Takes out his blaster and fires shots at the wall, the blastmarks leave the words "S-TROOPER WUZ 'ERE!!!"
2003-07-14, 5:52 AM #6
Does nobody know if this is possible?

------------------
Look for my current project, The Force in Your Soul.
Last week I cudn't evn spel grajuat, but now I is one.

*Takes out his blaster and fires shots at the wall, the blastmarks leave the words "S-TROOPER WUZ 'ERE!!!"
2003-07-14, 9:21 AM #7
you could try adding this if you want.
Code:
changed:
  player = GetSourceRef();
  if(GetInv(player, 3) != 2)
    return;
  if(GetCurWeapon(player) != 3)
    return;
  jkSetPOVModel(player, povModel);    // two Rifles
  SetThingModel(player, weaponMesh2);
  jkSetWeaponMesh(player, weaponMesh);
  SetArmedMode(player, 1);
  PlaySoundThing(mountSound, player, 1.0, -1.0, -1.0, 0x80);
  trackID = jkPlayPOVKey(player, mountAnim, 0, 20);
  PlayKey(player, drawgunAnim, 1, 0x38);
  SetTimerEx(GetKeyLen(drawgunAnim), 2, 0, 0);
  jkClearFlags(player, 0x5);
  jkSetWaggle(player, '10.0 7.0 0.0', 350);
  SetMountWait(player, GetKeyLen(mountAnim));
  SetCurWeapon(player, 3);
return;

make sure to add message changed to the symbols section too.
that makes it so that when the weapon inventory for the st-rifle is changed to 2 the cog runs the same stuff the selected message would.

------------------
Famous last words - "It seemed like a good idea at the time."

[This message has been edited by DSLS_DeathSythe (edited July 14, 2003).]
Famous last words - "It seemed like a good idea at the time."
2003-07-14, 10:42 AM #8
Well, it works when you pick up the second rifle it changes the model and everything, but after you press fire once, it keeps on firing the weapon until you run out of ammo.

------------------
Look for my current project, The Force in Your Soul.
Last week I cudn't evn spel grajuat, but now I is one.

*Takes out his blaster and fires shots at the wall, the blastmarks leave the words "S-TROOPER WUZ 'ERE!!!"
2003-07-14, 12:23 PM #9
w00t!!
I got it working, I forgot a deactivateweapon() in the fire section.

Thanks everyone.

------------------
Look for my current project, The Force in Your Soul.
Last week I cudn't evn spel grajuat, but now I is one.

*Takes out his blaster and fires shots at the wall, the blastmarks leave the words "S-TROOPER WUZ 'ERE!!!"
2003-07-14, 5:28 PM #10
Nice solution, DeathSythe. Don't often see editors make use of the changed event.

------------------
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
2003-07-14, 5:33 PM #11
thanks [http://forums.massassi.net/html/smile.gif]

------------------
Famous last words - "It seemed like a good idea at the time."
Famous last words - "It seemed like a good idea at the time."

↑ Up to the top!