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 → Shot From Behind
Shot From Behind
2004-09-08, 5:49 AM #1
I want to push, say force_grip and have a few raildets hit an enemy from behind, dead on. It wouldnt matter where I was, the bullet would spawn a few meters behind the enemy.

I want the bullet to only hit the enemy from behind, out of the enemy's point of view.


Any Ideas?
2004-09-08, 7:14 AM #2
Use the FireProjectile() Verb with the victim as origin and use a '0 -0.2 0' vector as fire offset.
"Häb Pfrässe, süsch chlepfts!" - The coolest language in the world (besides Cherokee)
2004-09-08, 7:32 AM #3
I tried that and it just makes the enemy fire from his point of view...
2004-09-08, 9:10 AM #4
That won't work. It's a bit more complicated (and please, use the code tags next time). Tell us exactly how you want the cog to work.
1. Is it a weapon, item or a force power?
2. Do you want it to target victims in a certain angle / range, or just the nearest victim
3. Does it have to consume some energy, power, battery or force upon activation
4. Should it fire once per button press or as long as you hold the button or until you press the button again?
5. Do you want it to be able to target npcs, too, or just players?
6. etc.
"Häb Pfrässe, süsch chlepfts!" - The coolest language in the world (besides Cherokee)
2004-09-08, 9:21 AM #5
Ok, let me write this again.

I want to fire weap_bryar.cog, somewhere in the level a enemy will be shot from behind(horizantally) with a conc bullet.

Ammo/force consumtion dosent matter.


Let me know if there's anything else you need to know.
2004-09-08, 2:53 PM #6
This should work:
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 but
# somewhat of a low power weapon. This weapon has only one type of fire.
#
# - 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       outSound=pistout1.wav               local
sound       mountSound=df_bry_ready.wav         local
sound       dismountSound=PutWeaponAway01.wav   local
sound       fireSound=pistol-1.wav              local

template    projectile=+concbullet              local
template	ghosty=healthpack		local

thing       player                              local
thing       victim                              local
thing       potential                           local
thing		dummy1				local
thing		dummy2				local

flex        dot                                 local
flex        maxDot                              local

flex        fireWait=0.5                        local
flex        holsterWait                         local
flex        fireDelay=0.6                       local
flex        powerBoost                          local
flex        autoAimFOV=30                       local
flex        autoAimMaxDist=5                    local

int         weaponIndex                         local
int         trackID=-1                          local
int         mode                                local
int         holsterTrack                        local

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

end

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

code

fire:
   player = GetSourceRef();

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

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

	potential = -1;
	for(i = 0; i < GetSectorCount(); i = i + 1)
	{
		potential = FirstThingInSector(i);
		while(potential != -1)
		{
			if((GetThingType(potential) == 2) || (GetThingType(potential) == 10))
			{
				if(potential != player)
				{
					victim = potential;
					potential = -1;
					i = GetSectorCount();
				}
				else
					potential = NextThingInSector(potential);
			}
			else
				potential = NextThingInSector(potential);
		}
	}
	dummy1 = CreateThing(ghosty, victim);
	SetThingPos(dummy1, VectorAdd(GetThingPos(victim), VectorScale(GetThingLVec(victim), -0.7)));
	SetThingLook(dummy1, VectorNorm(VectorAdd(GetThingLVec(victim), '0 0 0.05')));
	dummy2 = FireProjectile(dummy1, projectile, -1, -1, '0 0 0', '0 0 0', 0, 0, 0, 0);
	DestroyThing(dummy1);
   //ChangeInv(player, 11, -1.0);
   jkPlayPOVKey(player, povfireAnim, 1, 0x38);

   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();
   mode = GetSenderRef();

   jkSetWaggle(player, '10.0 7.0 0.0', 350);
   DeactivateWeapon( player, mode );
   Return;

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

selected:
   player = GetSourceRef();

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

   // Play mounting sound.
   PlayMode(player, 41);
   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, 0x14);
   jkSetWaggle(player, '10.0 7.0 0.0', 350);

   // Clear saber flags, and allow activation of the weapon
   jkClearFlags(player, 0x5);
   SetCurWeapon(player, 2);
   SetMountWait(player, GetKeyLen(mountAnim));

   Return;

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

deselected:
   player = GetSourceRef();
   weaponIndex = GetSenderRef();
   
   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, 2) != 0.0)
   {
      // If the player has ammo
      if(GetInv(player, 11) != 0.0)
      {
         ReturnEx(500.0);
      }
      else
      {
         ReturnEx(-1.0);
      }
   }
   else
   {
      ReturnEx(-1.0);
   }

   Return;

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

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

end

Don't whine about the form, it's a 5 minute cog. some problems: 1. it targets friendly actors as well. 2. it targets random targets, not the nearest ones...
"Häb Pfrässe, süsch chlepfts!" - The coolest language in the world (besides Cherokee)
2004-09-09, 2:01 PM #7
Perfect. Thank you very much.

I will go test this now....
2004-09-09, 5:02 PM #8
It dosent work, it just fires a conc bullet. Any ideas?

Bullet should just spawn at a ghost position behind the victim, and travel to the victim.
2004-09-09, 11:34 PM #9
Well, it does that for me. You can try to adjust the -0.7 value on the setthingpos line in the fire message (-0.7 = 7 metres behind). Or try changing the projectile=+concbullet to +raildet first...they do not travel this fast and you might better see how it works this way.
"Häb Pfrässe, süsch chlepfts!" - The coolest language in the world (besides Cherokee)

↑ Up to the top!