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 → Stumped...
Stumped...
2005-02-06, 11:09 PM #1
Okay, I have a weap_bryar.cog that is supposed to allow a charge-up mode for secondary fire of the bryar pistol. In-game levels 1 & 2 allow it to function, but warping to level 3 causes only the primary projectile to fire.

Also note that the auto-aim function does not appear to work (in any level).

This cog is based on the Bowcaster (weap_crossbow) cog. Can somebody take a look at this and help me troubleshoot what's going on here...? (cog posted below)

Code:
# Jedi Knight Cog Script
#
# WEAP_BRYAR.COG
#
# WEAPON 2 Script - Bryar Pistol
#
# The trusty weapon of Kyle Katarn. This is actually an older modified rifle
# that has been cut down to more of a pistol size. It is very accurate.
# Primary fire = low power
# Secondary Fire = heavy blaster/charge-up mode
#
# - Affected by MagSealed sectors/surfaces.
#
# [YB & CYW] 
#
# (C) 1997 LucasArts Entertainment Co. All Rights Reserved


symbols

model       povModel=bryv.3do                   local
model       weaponMesh=bryg.3do                 local

keyframe    mountAnim=bryvmnt.key               local
keyframe    dismountAnim=bryvdis.key            local
keyframe    povfireAnim=bryvpst1.key            local
keyframe    holsterAnim=kyhlstr.key             local

sound       mountSound=df_bry_ready.wav         local
sound       dismountSound=PutWeaponAway01.wav   local

sound       chargeSound=brycharge.wav           local
sound       fireSound1=pistol-1.wav             local
sound       fireSound2=DL-44.wav                local
sound       outSound=pistout1.wav               local

template    projectile=+bryarbolt 			local
template    projectile2=+ebolt 		      local

flex        fireWait=0.5                        local
flex        delayTime                           local
flex        autoAimFOV=30                       local
flex        autoAimMaxDist=5                    local
flex        powerBoost                          local
flex        holsterWait                         local

thing       player                              local

int         trackID=-1                          local
int         channel=-1                          local
int         holsterTrack                        local

message     startup
message     activated
message     deactivated
message     selected
message     deselected
message     newplayer
message     autoselect
message     fire
message     killed
message     timer

end

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

code

startup:
   player = GetLocalPlayerThing();

   Return;

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

activated:
   mode = GetSenderRef();

   jkSetWaggle(player, '0.0 0.0 0.0', 0);

   // Check Ammo - If we are out, autoselect best weapon.
   if(GetInv(player, 11) < 1.0)
   {
      if((GetAutoSwitch() & 1))
         SelectWeapon(player, AutoSelectWeapon(player, 1));
      else
         PlaySoundThing(outSound, player, 1.0, -1, -1, 0x80);

      Return;
   }

   if(mode == 1)
   {
      ActivateWeapon(player, 0, mode);

      if(channel == -1)
      {
         channel = PlaySoundThing(chargeSound, player, 0.0, -1, -1, 0x181);

         if(channel != -1)
         {
            ChangeSoundPitch(channel, 0.3, 0.01);
            Sleep(0.03);

            // looks stupid... but if the user taps quickly deactivated:
            // gets called during the sleep, and channel becomes invalid !
            if(channel != -1)
            {
               ChangeSoundVol(channel, 1.0, 0.6);
               ChangeSoundPitch(channel, 1.0, 1.2);
            }
         }
      }
   }
   else
   {
      powerBoost = GetInv(player, 63);
      ActivateWeapon( player, fireWait/powerBoost, mode);
   }

   Return;

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

fire:
   // 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)
   {
      SelectWeapon(player, AutoSelectWeapon(player, 1));
      Return;
   }

    	SetPOVShake('0.0 -.01 0.0', '2.0 0.0 0.0', .05, 80.0);
    FireProjectile(player, projectile, fireSound1, 18, '0.0135 0.1624 0.0',  '0 0 0', 0.75, 0x2, autoAimFOV, autoAimFOV*2);

   ChangeInv(player, 11, -1.0);
   jkPlayPOVKey(player, povfireAnim, 1, 0x38);

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

   Return;


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

deactivated:
   mode = GetSenderRef();

   jkSetWaggle(player, '10.0 7.0 0.0', 350);

   if(mode == 1)
   {
      delayTime = DeactivateWeapon(player, mode);

      if(channel != -1)
      {
         StopSound(channel, 0);
         channel = -1;
      }

      // Set a delay, even if we don't fire here.
      SetMountWait(player, fireWait/powerBoost);

      // Make sure both keys are up before continuing.
      if (GetCurWeaponMode() != -1) Return;

      // make sure we still have ammo
      if(GetInv(player, 11) < 1.0) Return;

   SetPOVShake('0.0 -.01 0.0', '2.0 0.0 0.0', .05, 80.0);

  FireProjectile(player, projectile, fireSound1, 8, '0.0135 0.1624 0.0',  '0 0 0', 0.75, 0x2, autoAimFOV, autoAimFOV*2);
            ChangeInv(player, 11, -1.0);

	if(delayTime > 1.0)
      {
         if(GetInv(player, 11) > 0.0)
         {

  FireProjectile(player, projectile2, fireSound2, 18, '0.0135 0.1624 0.0',  '0 0 0', 7.5, 0x2, autoAimFOV, autoAimFOV*2)*4;
            ChangeInv(player, 11, -4.0);
         }
      }
      // Play animation and set delay.
      jkPlayPOVKey(player, povfireAnim, 1, 0x38);
      powerBoost = GetInv(player, 63);
   }
   else
   {
      DeactivateWeapon(player, mode);
   }

   Return;

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

selected:
   // Play external animation
   PlayMode(player, 41);

   // Set up meshes and models.
   jkSetPOVModel(player, povModel);
   SetArmedMode(player, 1);
   jkSetWeaponMesh(player, weaponMesh);
   jkSetWaggle(player, '10.0 7.0 0.0', 350);

   // Play sound and animation.
   PlaySoundThing(mountSound, player, 1.0, -1, -1, 0x80);
   trackID = jkPlayPOVKey(player, mountAnim, 0, 20);
   SetMountWait(player, GetKeyLen(mountAnim));

   // Set flags, etc.
   jkClearFlags(player, 0x5);
   SetCurWeapon(player, 2);

   // Check Ammo - If we are out, autoselect best weapon.
   if(GetInv(player, 11) < 1.0)
   {
      if((GetAutoSwitch() & 1))
         SelectWeapon(player, AutoSelectWeapon(player, 1));
   }

   Return;

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

deselected:
   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, 2, 0.0, 0.0);
   if (trackID != -1)
   {
      jkStopPOVKey(player, trackID, 0);
      trackID = -1;
   }
   jkSetWaggle(player, '0.0 0.0 0.0', 0);
   
   if(channel != -1)
   {
      StopSound(channel, 0.1);
      channel = -1;
   }

   Return;

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

killed:
   if (player == GetSenderRef())
   {
      if(channel != -1)
      {
         StopSound(channel, 0.1);
         channel = -1;
      }
   }
   Return;

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

newplayer:
//   // Make sure that if the player is respawning, the old mount isn't playing anymore.
//   if (trackID != -1)
//   {
//      jkStopPOVKey(player, trackID, 0);
//      trackID = -1;
//   }

   if(channel != -1)
   {
      StopSound(channel, 0.1);
      channel = -1;
   }

   Return;

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

autoselect:
   // If the player has the weapon
   if(GetInv(player, 2) != 0.0)
   {
      // If the player has ammo
      if(GetInv(player, 11) > 1.0)
      {
         ReturnEx(700.0);
      }
      else
      {
         ReturnEx(-1.0);
      }
   }
   else
   {
      ReturnEx(-1.0);
   }

   Return;

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

timer:
   StopKey(player, holsterTrack, 0.0);
   Return;

end
______________________________________________

[Code tags please...]

Any help is MUCH appreciated.

_K_
2005-02-07, 3:55 AM #2
I just had a glance over it and found out that you have an error in deactivated on the Second Fireprojectile line. the *4 at the end should be inside the brackets.
Not sure if that fixes your problem, though...
"Häb Pfrässe, süsch chlepfts!" - The coolest language in the world (besides Cherokee)
2005-02-07, 8:25 AM #3
Hmmm... that's not it. Just checked it out again and found that it now fires the second projectile (along with accompanying sound) when charged > than 1.0 second even when there's not enough ammo (and have an ammo cost of up to the second projectiles ammo cost) ... it used to fire the non-charged projectile along with the non-charged blast sound and subsequently have an ammo cost of 1. Very weird.

_K_
2005-02-07, 9:55 AM #4
Where is the third level? I only see two. Or are you talking about game levels :confused:?
"Häb Pfrässe, süsch chlepfts!" - The coolest language in the world (besides Cherokee)
2005-02-07, 11:21 AM #5
if(GetInv(player, 11) > 0.0)
... Just before that second "FireProjectile" should be.
if(GetInv(player, 11) > 4.0)
_ _ _____________ _ _
Wolf Moon
Cast Your Spell On Me
Beware
The Woods At Night
The Wolf Has Come
2005-02-07, 2:07 PM #6
LoL...! Yes, I mean the in-game Level 3 (Return to Sulon, or something like that).

Silly me...! I reset the "if(GetInv(player, 11) > 0.0)" to 4.0... still doesn't solve the problem, tho...

_K_
2005-02-07, 8:38 PM #7
I've encountered this problem before. Try reading this thread. It may have your answer.
Spoting an error in post will result in a $100 reward.
Offer expires on 6/6/06. Valid one per customer, per day.

Rangi
2005-02-08, 8:53 AM #8
Okay... first off: Thanx everybody...! I now have the problem solved as to the missing second projectile (I had been lacking a template).

But I still cannot figure out why the auto-aiming function does not work...

_K_
2005-02-08, 9:52 AM #9
You mean the last two parameters of FireProjectile? They only work in singleplayer, when the "auto aiming" or whatever-it-is-called-option is enabled.
"Häb Pfrässe, süsch chlepfts!" - The coolest language in the world (besides Cherokee)
2005-02-08, 1:05 PM #10
In Datamaster, there's a tutorial on how to do autoaiming as I remember. (Uses vectors to figure out the new vector. You can control FOV by ThingViewDot)
_ _ _____________ _ _
Wolf Moon
Cast Your Spell On Me
Beware
The Woods At Night
The Wolf Has Come
2005-02-09, 5:05 PM #11
Got it...! Setting the projectile flags from 0x20 to 0x2 apparently affected the single player auto-aim function...!

_K_
2005-02-10, 1:02 AM #12
You know, flags can be added. So, if you want damage scale (0x2) AND sp auto aim (0x20), just add them (0x22).
"Häb Pfrässe, süsch chlepfts!" - The coolest language in the world (besides Cherokee)
2005-02-10, 12:43 PM #13
Gotcha...!

Thanx zagibu...!

_K_

↑ Up to the top!