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 → Once agian I come...
Once agian I come...
2003-04-23, 6:02 AM #1
with an advanced question.

Requirements - This one is not for the simple cogger, you must be familiar and crafty with the use of sounds.

Background - I'm creating a sniper rifle cog for my mods and System Overrides' mod. This is totally different then what you've seen before because of certain characteristics, and you're going to help me with one.

The problem/question - to cancel out all of the sounds that the ghost fired would hear and play the sounds that the player would normally hear, so that the user will be able to hear them as if the user was the player, not the scope's ghost (perferably local).

The cog so far (inc right now, but scope can be tested).
Code:
# Jedi Knight Cog Script
#
# WEAP_CONCRIFLE.COG
#
# WEAPON 9 Script - Sniper Rifle
#
# Sniper Rifle
#
# - Not affected by MagSealed sectors/surfaces.
#
# [DP]
#

symbols

model       povModel=conv.3do                   local
model       weaponMesh=cong.3do                 local

keyframe    mountAnim=ConVmnt.key               local
keyframe    dismountAnim=ConVdis.key            local
keyframe    povfireAnim=ConVpst1.key            local
keyframe    holsterAnim=kyhlstr.key             local

sound       mountSound=df_rif_ready.wav         local
sound       dismountSound=PutWeaponAway01.wav   local
sound       fireSound=srfire.wav                local
sound       outSound=concuss1.wav               local
sound       zoomSound=scope.wav                 local

flex        fireWait=1.5                        local
flex        powerBoost                          local
flex        autoAimFOV=30                       local
flex        autoAimMaxDist=5                    local
flex        holsterWait                         local

int         dummy                               local

template    projectile=+concbullet              local
template    camera=+zoom                        local

thing       player                              local
int         trackID=-1                          local
int         mode                                local
int         holsterTrack                        local
int         selectMode=1                        local

flex        mag=0.25                            local
flex        zoom=0                              local
flex        temp                                local
int         reloading=0                         local
int         moving=0                            local
int         count=0                             local
int         scope=-1                            local
int         oldCam                              local
int         on=0                                local
int         zoomChannel=-1                      local
vector      tempVec                             local
vector      zoomVec                             local

message     activated
message     deactivated
message     selected
message     deselected
message     autoselect
message     user1
message     timer
message     pulse

end

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

code

User1:
   If(reloading) Return;
   // Check that the player is still alive.
   If(GetThingHealth(player) <= 0)
      Return;

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

   SetPOVShake('0 -.03 0', '4 0 0', .05, 80);

   FireProjectile(player, projectile, fireSound, 8, '0.02 0.15 0.0', '0 0 0', 1.0, 0x20, autoAimFOV, autoAimMaxDist);
   ChangeInv(player, 12, -1);
   reloading = 1;

   jkPlayPOVKey(player, povfireAnim, 1, 0x38);

   // Provide a kick backwards
   ApplyForce(player, VectorScale(GetThingLVec(player), -80));

   powerBoost = GetInv(player, 63);
   SetTimerEx(fireWait/powerBoost, 1, 0, 0);

   Return;

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

Activated:
   player = GetSourceRef();
   mode = GetSenderRef();

   If(!on)
   {
      oldCam = GetCurrentCamera();
      If(mode == 1) mag = 5;
   }
   jkSetWaggle(player, '0 0 0', 0);
   zoomChannel = PlaySoundLocal(zoomSound, 1, 0, 0x1);
   count = 0;
   moving = 1;
   on = 1;
   zoom = .5 - mode;
   SetPulse(0.01);

   Return;

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

Deactivated:
   player = GetSourceRef();
   mode = GetSenderRef();

   jkSetWaggle(player, '10 7 0', 350);
   moving = 0;
   If(zoomChannel != -1)
   {
      StopSound(zoomChannel, 0);
      zoomChannel = -1;
   }

   If(count <= 2) // If the zoom keys are tapped
   {
      If(mode == 1)
      {
         If(mag < 5) call scope_off;
         Else mag = 2.5;
      }
      Else
      {
         If(mag < 2.5) mag = 2.5;
         Else If(mag < 5) mag = 5;
         Else call scope_off;
      }
   }
   Return;

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

Selected:
   player = GetSourceRef();

   // Play external mounting animation
   PlayMode(player, 41);

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

   // Play mounting sound.
   PlaySoundThing(mountSound, player, 1.0, -1.0, -1.0, 0x80);

   // Play the animation (NOLOOP + UNIQUE + ENDPAUSE).
   // The animation is held at the last frame after it is played.
   trackID = jkPlayPOVKey(player, mountAnim, 0, 20);
   SetMountWait(player, GetKeyLen(mountAnim));

   // Clear saber flags, and allow activation of the weapon
   jkClearFlags(player, 0x5);
   SetCurWeapon(player, 9);

   // Check Ammo - If we are out, autoselect best weapon.
   If(GetInv(player, 12) < 2)
   {
      PlaySoundThing(outSound, player, 1.0, -1, -1, 0x80);
      if(GetAutoSwitch() & 1)
         SelectWeapon(player, AutoSelectWeapon(player, 1));
   }
   mag = 0.25;
   If(reloading) SetTimerEx(fireWait/powerBoost, 1, 0, 0);

   Return;

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

Deselected:
   player = GetSourceRef();
   If(on) call scope_off;
   If(reloading) KillTimerEx(1);

   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);

   Return;

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

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

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

Autoselect:
   selectMode = GetSenderRef();
   player = GetSourceRef();

   // If the player has the weapon
   if(GetInv(player, 9) != 0.0)
   {
      // If the player has ammo
      if(GetInv(player, 12) > 7.0)
      {

         // query for ammo
         if(selectMode == -1)
         {
            ReturnEx(1000.0);
            Return;
         }

         if((selectMode == 0) && !(GetAutoPickup() & 2))
         {
            ReturnEx(1000.0);
            Return;
         }

         if((selectMode == 1) && !(GetAutoSwitch() & 2))
         {
            ReturnEx(1000.0);
            Return;
         }

         if((selectMode == 2) && !(GetAutoPickup() & 2))
         {
            ReturnEx(1000.0);
            Return;
         }

         ReturnEx(-2.0);
         Return;

      }
      else
      {
         ReturnEx(-1.0);
      }
   }
   else
   {
      ReturnEx(-1.0);
   }

   Return;

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

Timer:
   If(GetSenderID() == 1)
   {
      reloading = 0;
      Return;
   }
   StopKey(player, holsterTrack, 0.0);
   Return;

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

Scope_off:
   If(zoomChannel != -1)
   {
      StopSound(zoomChannel, 0);
      zoomChannel = -1;
   }
   SetPulse(0);
   mag = 0.25;
   on = 0;
   SetCameraFocus(0, player);
   If(oldCam) CycleCamera();
   Return;

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

Pulse:
   If(GetThingHealth(player) <= 0)
   {
      call scope_off;
      Return;
   }

   If(GetCurrentCamera()) CycleCamera();
   If(moving)
   {
      mag = mag + zoom * count * 0.005;
      If(mag > 5) mag = 5;
      If(mag < .25) mag = .25;
      count = count + 1;
   }
   zoomVec = VectorSet(0, mag, 0.037);
   If(mag <= 0.25 && zoom < 0)
   {
      call scope_off;
      Return;
   }

   scope = FireProjectile(player, camera, -1, -1, zoomVec, '0 0 0', 1, 0, 0, 0);
   temp = mag;
   // This is to see if the scope thing is on the direct straight ahead line from the player
   // The reason is that the scope slides one way or another when the mag gets too great
   While(VectorSub(GetThingPos(scope), GetThingPos(player)) != GetThingLVec(player))
   {
      temp = temp - .005;
      zoomVec = VectorSet(0, temp, 0.037);
      DestroyThing(scope);
      scope = FireProjectile(player, camera, -1, -1, zoomVec, '0 0 0', 1, 0, 0, 0);
   }
   tempVec = VectorAdd(GetThingPos(scope), VectorScale(VectorNorm(GetThingLVec(scope)), -0.1));
   SetThingPos(scope, tempVec);
   SetCameraFocus(0, scope);

   Return;

end
All ideas are welcome.

------------------
The Sniper Missions. Current project, The Sniper Missions

The Magician Saber System.

[This message has been edited by Descent_pilot (edited April 23, 2003).]
Major projects working on:
SATNRT, JK Pistol Mod, Aliens TC, Firearms

Completed
Judgement Day (HLP), My level pack
2003-04-23, 2:36 PM #2
I could also use some help down in the pulse section w/ the direct line stuff.

1 word yelled very load - Help!

------------------
The Sniper Missions. Current project, The Sniper Missions

The Magician Saber System.
Major projects working on:
SATNRT, JK Pistol Mod, Aliens TC, Firearms

Completed
Judgement Day (HLP), My level pack
2003-04-24, 5:33 AM #3
Any input? Anyone?

------------------
The Sniper Missions. Current project, The Sniper Missions

The Magician Saber System.
Major projects working on:
SATNRT, JK Pistol Mod, Aliens TC, Firearms

Completed
Judgement Day (HLP), My level pack
2003-04-24, 6:56 PM #4
Sounds are heard from the camera... So I'm not really certian of a way to modify the view without also modifying how the player would percieve sounds. IE, the way you have it, if someone came to the player and slashed his saber, you probably wouldn't hear it, pending on how far away the zoom is from the player. Tricky..... yes..... Impossible it would seem. [http://forums.massassi.net/html/frown.gif]

For the actual scope camera, I would reccomend having a template with a timer of 0.001 with an attached cog that changes the view to it when it's created. This coupled with a pulse of 0.001 would always keep the camera along the players lookvector. (and keeping excess code away from the actual funcions of your sniper rifle)

Would also help to mention that when you'd stop the pulse, also setting the camera back the next line afterwards. [http://forums.massassi.net/html/wink.gif]

------------------
-Hell Raiser
Remember kiddies, trial and error.
Without struggles there is no progress
DBZ: The Destruction is Real

[This message has been edited by Hell Raiser (edited April 24, 2003).]
-Hell Raiser
2003-04-27, 5:02 AM #5
sorry it took so long to respond, busy week.

Okay, so the first part is pretty much impossible? I remember a topic about cancelling out all sound, but I really don't want to go digging for it right now. I was thinking maybe something along those lines, but I'll do that on my own I guess. [http://forums.massassi.net/html/frown.gif]

But for the scope on line w/ the player Lvec. I don't quite understand what you're saying, the way I percive it is that it will have the same effect as what is given. I don't quite comprehend how that will keep it on the player's Lvec line. Can you give the reasons or some examples?

------------------
The Sniper Missions. Current project, The Sniper Missions

The Magician Saber System.
Major projects working on:
SATNRT, JK Pistol Mod, Aliens TC, Firearms

Completed
Judgement Day (HLP), My level pack

↑ Up to the top!