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: 3197
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 14 2005 at 22: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 14 2005, 22: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 04 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
Spinning Corpses Simple Fix
Half-Life | Coding | Snippets
By: darkPhoenix | Sep 05 2008
 
Where do we go from here
General | News
By: MIFUNE | Jun 09 2008
 
The Input/Output system
Half-Life 2 | Level Design
By: nazitaco | Dec 23 2007
 
Where do we go from here
General | News
By: Rob_F | Nov 22 2007
 
Rescaling Half-Life
Half-Life | Coding | Shared Tutorials
By: christoph | Nov 12 2007
 
GameUI
Half-Life 2 | Coding | Client Side Tutorials
By: Evil_j | Oct 29 2007
 
3 State Zoom For Any Weapon
Half-Life 2 | Coding | Server Side Tutorials
By: Ennuified | Oct 18 2007
 
Storing weapons on ladder
Half-Life 2 | Coding | Snippets
By: cct | Sep 07 2007
 
CTF Gameplay Part 1
Half-Life | Coding | Shared Tutorials
By: DarkNight | Aug 28 2007
 
CTF Gameplay Part 1
Half-Life | Coding | Shared Tutorials
By: deedok | Aug 20 2007
 

Site Info
296 Approved Articless
5 Pending Articles
3940 Registered Members
4 People Online (26 guests)
About - Credits - Contact Us

Wavelength version: 3.0.0.9
Valid XHTML 1.0! Valid CSS!