Welcome, Guest! Login | Register

Butter Fingers Bullet [Print this Article]
Posted by: ScoBra7
Date posted: Apr 07 2003
User Rating: 4.5 out of 5.0
Number of views: 5730
Number of comments: 1
Description: The headless chicken run!
This tutorial will show you how to create new bullet types. Also the new bullet will cause the target player to lose all weapons, including the crowbar. Look at them running like headless chickens to find something to hit back with!

First we are going to define the new bullet type. Open weapons.h and find
 CODE  
 typedef    enum
{
    BULLET_NONE = 0,
    BULLET_PLAYER_9MM, // glock
    BULLET_PLAYER_MP5, // mp5
    BULLET_PLAYER_357, // python
    BULLET_PLAYER_BUCKSHOT, // shotgun
    BULLET_PLAYER_CROWBAR, // crowbar swipe

    BULLET_MONSTER_9MM,
    BULLET_MONSTER_MP5,
    BULLET_MONSTER_12MM,
} Bullet;
add the following after BULLET_MONSTER_12MM,
 CODE  
 BULLET_PLAYER_9MM_BF,
Save weapons.h

Open cbase.h and find
 CODE  
#define DMG_MORTAR (1 << 23)
and add this
 CODE  
#define DMG_BUTTER_FINGERS     (1 << 24)   // Hit by butter fingers bullet
Save cbase.h.

Open combat.cpp and in the function void CBaseEntity::FireBullets(ULONG cShots, Vector vecSrc, Vector vecDirShooting, Vector vecSpread, float flDistance, int iBulletType, int iTracerFreq, int iDamage, entvars_t *pevAttacker ) find
 CODE  
 else switch(iBulletType)
   {
   default:
   case BULLET_PLAYER_9MM:  
    pEntity->TraceAttack(pevAttacker, gSkillData.plrDmg9MM, vecDir, &tr, DMG_BULLET);
    break;

Now add after this:
 CODE  
 case BULLET_PLAYER_9MM_BF:
    {
      pEntity->TraceAttack(pevAttacker, gSkillData.plrDmg9MM, vecDir, &tr, DMG_BUTTER_FINGERS);
      break;
    }
Save combat.cpp.

Open client.cpp and in void ClientPrecache( void ) add
 CODE  
PRECACHE_SOUND("ambience/warn1.wav");
Save client.cpp.

Next open player.cpp. In void CBasePlayer :: TraceAttack( entvars_t *pevAttacker, float flDamage, Vector vecDir, TraceResult *ptr, int bitsDamageType) after the switch statement add
 CODE  
 if(bitsDamageType == DMG_BUTTER_FINGERS)
   {
   RemoveAllItems( FALSE );
   //Play sound
   EMIT_SOUND(ENT(pev), CHAN_BODY, "ambience/warn1.wav", 1, ATTN_NORM);
   }

When hit by a Butter Finger bullet the victimís weapons will be remove, we leave the suite (FALSE parameter of RemoveAllItems), take some damage and he / she will hear a sound.

In the function int CBasePlayer :: TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType ) find
 CODE  
 if (bitsDamage & DMG_SHOCK)
  {
   bitsDamage &= ~DMG_SHOCK;
   ffound = TRUE;
  }
and add
 CODE  
 if (bitsDamage & DMG_BUTTER_FINGERS)
  {
   bitsDamage &= ~ DMG_BUTTER_FINGERS;
   ffound = TRUE;
  }
Save player.cpp.

We will implement this for the Glock, but you can do so for any weapons that use the FireBullets. So open hl_wpn_glock.cpp and in the function void CGlock::GlockFire( float flSpread , float flCycleTime, BOOL fUseAutoAim ) find
 CODE  
 m_pPlayer->FireBullets( 1, vecSrc, vecAiming, Vector( flSpread, flSpread, flSpread ), 8192, BULLET_PLAYER_9MM, 0 );
and replace with
 CODE  
 m_pPlayer->FireBullets( 1, vecSrc, vecAiming, Vector( flSpread, flSpread, flSpread ), 8192, fUseAutoAim ? BULLET_PLAYER_9MM : BULLET_PLAYER_9MM_BF, 0 );
Save hl_wpn_glock.cpp.

The secondary fire for the Glock set fUseAutoAim to false, so we can use it to determine if Primary or Secondary fire was used. Thus Primary fire will use normal bullets while secondary fire will use the Butter Finger bullets. There are different ways to implement this for the Glock.

That's all, Enjoy! Thatís all folks. You can e-mail me at scobra@ananzi.co.za for comments and questions.

Rate This Article
This article is currently rated: 4.5 out of 5.0 (2 Votes)

You have to register to rate this article.
User Comments Showing comments 1-1

Posted By: Exomoto on Nov 15 2005 at 04:19:28
"Open combat.cpp and in the function void CBaseEntity::FireBullets(ULONG cShots, Vector vecSrc, Vector vecDirShooting, Vector vecSpread, float flDistance, int iBulletType, int iTracerFreq, int iDamage, entvars_t *pevAttacker ) find...."

The code you specify to look for is in CBaseEntity::FireBulletsPlayer(...) not CBaseEntity::FireBullets(...).
Also, you code you add there doesn't need to be held in braces, since it's just a single line.Edited by Exomoto on Nov 15 2005, 04:20:51


You must register to post a comment. If you have already registered, you must login.

Latest Articles
3rd person View in Multiplayer
Half-Life 2 | Coding | Client Side Tutorials
How to enable it in HL2DM

By: cct | Nov 13 2006

Making a Camera
Half-Life 2 | Level Design
This camera is good for when you join a map, it gives you a view of the map before you join a team

By: slackiller | Mar 05 2006

Making a camera , Part 2
Half-Life 2 | Level Design
these cameras are working monitors that turn on when a button is pushed.

By: slackiller | Mar 04 2006

Storing weapons on ladder
Half-Life 2 | Coding | Snippets
like Raven Sheild or BF2

By: British_Bomber | Dec 24 2005

Implementation of a string lookup table
Half-Life 2 | Coding | Snippets
A string lookup table is a set of functions that is used to convert strings to pre-defined values

By: deathz0rz | Nov 13 2005


Latest Comments
knock knock
General | News
By: MIFUNE | Dec 31 2017
 
knock knock
General | News
By: omega | Dec 22 2016
 
knock knock
General | News
By: MIFUNE | Oct 10 2015
 
New HL HUD Message System
Half-Life | Coding | Shared Tutorials
By: chbrules | Dec 31 2011
 
knock knock
General | News
By: Whistler | Nov 05 2011
 
Particle Engine tutorial part 4
Half-Life | Coding | Client Side Tutorials
By: darkPhoenix | Feb 18 2010
 
Particle Engine tutorial part 2
Half-Life | Coding | Client Side Tutorials
By: darkPhoenix | Feb 11 2010
 
Particle Engine tutorial part 3
Half-Life | Coding | Client Side Tutorials
By: darkPhoenix | Feb 11 2010
 
Game Movement Series #2: Analog Jumping and Floating
Half-Life 2 | Coding | Shared Tutorials
By: mars3554 | Oct 26 2009
 
Particle Engine tutorial part 5
Half-Life | Coding | Client Side Tutorials
By: Deadpool | Aug 02 2009
 

Site Info
297 Approved Articless
8 Pending Articles
3940 Registered Members
0 People Online (7 guests)
About - Credits - Contact Us

Wavelength version: 3.0.0.9
Valid XHTML 1.0! Valid CSS!