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 → Targeting reticules on weapons.
Targeting reticules on weapons.
2002-02-08, 8:00 PM #1
I'm giving a weapon a targetting reticle..It should put the reticule around the player and auto aim it at him when you shoot it. But it only shows the reticule and otherwise works like usual ( don't auto-aim to the reticule )

Code:
# Jedi Knight Cog Script
#
# WEAP_THERMDET.COG
#
# WEAPON 4 Script - Thermal Detonator
#
# Fun to use and handy for clearing some elbow room.  Not recommending
#  for those with noodle arms. The longer you hold down the fire key
#  (CTRL/Z) the farther you throw the detonator.
#
# The primary fire throws the detonator with the 3 second delay, the
#  secondary makes it explode on impact.
#
# - Not affected by MagSealed sectors/surfaces.
#
# [YB & CYW]
#
# (C) 1997 LucasArts Entertainment Co. All Rights Reserved
# ========================================================================================

symbols

model        povModel=bowv.3do                  local                         
model        weaponMesh=bowg.3do                local                         

keyframe     mountAnim=detvmnt.key              local                         
keyframe     dismountAnim=detvdis.key           local                         
keyframe     povFireAnim=detvpst1.key           local                         
keyframe     prePOVThrowAnim=detvpre1.key       local                         
#keyframe    preThrowAnim=kyrthro0.key          local                         
keyframe     holsterAnim=kyhlstr.key            local                         

template     projectile=+arrow                  local                         
template     projectile1=+arrow                 local                         

sound        throwSound=arrow.wav               local                         
sound        clickSound=draw.wav                local                         
sound        clickSound2=draw.wav               local                         
sound        loopSound=ThermLoop01.wav          local                         

flex         delayTime=1.0                      local                         
flex         throwWait=0.8                      local                         
flex         mountWait                          local                         
flex         autoAimFOV=30                      local                         
flex         autoAimMaxDist=5                   local                         
flex         holsterWait                        local                         

thing        player                             local                         
thing        potential                          local                         
thing        victim                             local                         

int          FireVec=-1                         local                         
int          preThrowTrack                      local                         
int          selectTrack                        local                         
int          prePOVThrowTrack                   local                         
int          mode                               local                         
int          cocked=0                           local                         
int          holsterTrack                       local                         

int          selectMode=1                       local                         

message      startup                                                          
message      activated                                                        
message      deactivated                                                      
message      selected                                                         
message      deselected                                                       
message      autoselect                                                       
message      timer                                                            
message      newplayer                                                        
message      pulse                                                            

end                                                                           

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

code

startup:
   // Setup delays and variables.
   mountWait    = GetKeyLen(mountAnim);

   preThrowTrack=-1;
   selectTrack=-1;
   prePOVThrowTrack=-1;

   Return;

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

activated:
   player = GetSourceRef();
   mode = GetSenderRef();
   if (mode > 1)
      Return;

   PlaySoundThing(clickSound[mode], player, 1.0, -1.0, -1.0, 0x80);

   // Cock arm back for throw.
   if(preThrowTrack == -1 && prePOVThrowTrack == -1)
   {
      prePOVThrowTrack = jkPlayPOVKey(player, prePOVThrowAnim, 1, 0x14);
      preThrowTrack = PlayMode( player, 38 );
      ActivateWeapon(player, 0, mode);
   }
   Return;

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

deactivated:
	FireVec=-1;
   player = GetSourceRef();
   mode = GetSenderRef();

   delayTime = DeactivateWeapon(player, mode);        // allow activated messages again.

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

   // Set maximum scale factor (2 second hold.)
   if(delayTime > 2)
      delayTime = 2;

   // Set minimum scale factor
   if(mode == 0)
   {
      if(delayTime < 0.7) delayTime = 0.7;
   }
   else
   {
      if(delayTime < 0.25) delayTime = 0.25;
   }

   if(preThrowTrack != -1 && prePOVThrowTrack != -1)
   {
      jkStopPOVKey(player, prePOVThrowTrack, 0);
      StopKey(player, preThrowTrack, 0);
      preThrowTrack = -1;
      prePOVThrowTrack = -1;
   }

   // Throw the appropriate detonator.
   SetPOVShake('0.0 -.003 0.0', '0.5 0.0 0.0', .05, 40.0);
   jkPlayPOVKey(player, povfireAnim, 1, 0x38);
   PlaySoundThing(throwSound, player, 1.0, 0.5, 2.5, 0x80);
	//if we dont have a victim, shoot the arrow straight, otherwise shoot at the victim.
	if(victim==-1) FireProjectile(player, projectile[mode], -1, 15, '0.05 0 0', '0 0 0', delayTime, 0x1, 0.0, 0.0);

        else if(victim!=-1) {

	FireVec = VectorNorm(VectorSub(GetThingPos(victim), GetThingPos(player)));
	 FireProjectile(player, projectile[mode], -1, 15, '0.05 0 0', FireVec, delayTime, 0x1, 0.0, 0.0);
	}
   ChangeInv(player, 4, -1.0);
   SetMountWait(player, throwWait);

   // If out of ammo try to autoswitch to another weapon
   // if autoswitch is enabled else just switch to fists.
   if(GetInv(player, 4) < 1)
   {
      if(GetAutoSwitch() & 1)
      {
         SelectWeapon(player, AutoSelectWeapon(player, 1));
      }
      else
      {
         SelectWeapon(player, 1);
      }
   }

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

   Return;

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

timer:
   if (GetSenderId() == 0)
   {
      // Start waggling after the throw.
      jkSetWaggle(player, '10.0 7.0 0.0', 350);
   }
   else
   if (GetSenderId() == 2)
   {
      StopKey(player, holsterTrack, 0.0);
   }
   Return;

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

selected:
   
   player = GetSourceRef();

   victim = -1;
   SetPulse(.1);


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

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

   // Setup the meshes and models.
   jkSetPOVModel(player, povModel);
   SetArmedMode(player, 0);
   jkSetWeaponMesh(player, weaponMesh);

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

   // Clear Lightsaber flag, and enable activation messages.
   jkClearFlags(player, 0x5);
   SetCurWeapon(player, 4);
   SetMountWait(player, GetKeyLen(mountAnim));

   Return;

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

deselected:

SetPulse(0); 
jkEndTarget();    // Turn circles off 


   player = GetSourceRef();

   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(selectTrack != -1)
   {
      jkStopPOVKey(player, selectTrack, 0);
      selectTrack = -1;
   }
   jkSetWaggle(player, '0.0 0.0 0.0', 0);
   KillTimerEx(0);

   if(preThrowTrack != -1 && prePOVThrowTrack != -1)
   {
      jkStopPOVKey(player, prePOVThrowTrack, 0);
      StopKey(player, preThrowTrack, 0);
      preThrowTrack = -1;
      prePOVThrowTrack = -1;
   }

   Return;

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

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

   // If the player has ammo
   if(GetInv(player, 4) != 0)
   {

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

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

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

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

      ReturnEx(-2.0);
      Return;

   }
   else
   {
      ReturnEx(-1.0);
   }

   Return;

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

newplayer:
   if(preThrowTrack != -1 && prePOVThrowTrack != -1)
   {
      jkStopPOVKey(player, prePOVThrowTrack, 0);
      StopKey(player, preThrowTrack, 0);
      preThrowTrack = -1;
      prePOVThrowTrack = -1;
   }
   Return;

# ........................................................................................
pulse: 

   victim = -1; 

   potential = FirstThingInView(player, 90, 8, 0x404);  // Get the First thing in player's sight that is either a player (0x400) or an actor (0x4) 

   while(potential != -1) 
   { 
     if( 
         HasLOS(player, potential) &&    // If the player can see potential 
         (potential != player) &&    // if the player isn't potential 
         (VectorDist(GetThingPos(player), GetThingPos(potential)) <= 6) &&    // Make sure potential is no farther then MaxDist (5 JKUs) 
         !(GetThingFlags(potential) & 0x200)    // *shrugs* 
       ) 
        { 
            victim = potential;    // If potential passes all the filters, then make it the victim.
      } 

      potential = NextThingInView();    // Get the next thing if potential was filtered out 
   } 

   if(victim != -1)     // If we have a victim targeted 
   { 
      jkSetTargetColors(6, 7, 8);    // Set the colors for the target circles 
      jkSetTarget(victim);    // Set Victim as the target and activates the circles 
   } 
   else 
   { 
      jkEndTarget();    // If we have no victim, then turn off the circles/cancel the last target. 
   } 
  

return; 

end
Save a tree, Kill a beaver!
2002-02-08, 8:17 PM #2
I dunno, you might want to use vectorscale, though i don't see why...
firevec = VectorScale(VectorNorm(VectorSub(GetThingPos(player), GetThingPos(victim))), 300.0);

------------------
Life is like... skating... yeah, skating is a good example. You see someone skating and think "Hey, that looks like fun and easy!". You go and buy a skateboard and try, you get a few broken bones, asphalt-face and stuff... But hey, i'm not the one who gets hurt!
Last edited by mb; today at 10:55 AM.
2002-02-09, 9:44 AM #3
dude Frantie , i'm serious , just have a sprite pulsed to fire autoaimed as a crosshair. then you can just look to lock on to whichever player you wanna shoot , and then any projectile you shoot with the same autoaimdist and fov by default will hit them. no ?
[i've got hours and hours{literally} of college homework to do today or i would put together a sample cog]
Also, I can kill you with my brain.
2002-02-11, 9:40 AM #4
I think the second vector parameter of FireProjectile() is supposed to be used for aiming error, not to orient the projectile. So use something like this instead:
Code:
	dummy = FireProjectile(player, temp, wav, key, '0 0 0', '0 0 0', 1, 0, 0, 0);
   	lvec=VectorNorm(VectorSub(GetThingPos(victim), GetThingPos(player)));
	SetThingLook(dummy, lvec);
	SetThingVel(dummy, VectorScale(lvec, orig_speed));


That should do it [http://forums.massassi.net/html/wink.gif]

------------------
Each cog better than the next
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
2002-02-11, 10:00 AM #5
Just to clarify..

In the FireProjectile() the first vector is the position the shot originates at, while the second vector is sort of strange. It does change the angle at which the shot is fired, so if you used 0 0 0, it'd fire straight ahead, and 1 1 1, it would fire up, right, and forward. I think it tries to shoot at an angle so that it would hit an object at 1 1 1, if there were an object there. However, these vectors are based off the actor, whereas the actor's position is based off the world coordinates, so you would need to throw in some fancy math to do it via this vector.

In short, SaberMaster's way is much easier [http://forums.massassi.net/html/smile.gif]

-Greven

↑ Up to the top!