Registration - or - Enter
Half-Life : The Alpha UnitHalf-Life : The Alpha Unit

История Капрала Даниэля Флэтчера...

4/12/2011

weapon_knife (Нож) с двумя режимами атаки: Slash и Stab.


  • Description
  • Link and installation

Исходный код ножа

weapon_knife (Нож) с двумя режимами атаки: Slash и Stab.


Author/s of lesson : Ku2zoff
Views : 988 ( +1 )
Downloads : 0
Uploaded by : Streit
Created : 04/07/2011 5:41:30 PM
Source : http://www.hlfx.ru/forum
Rating :
 ( 0 ) 
Share :


Available following translations : | russian |

Вот значит, weapon_knife (Нож) с двумя режимами атаки: Slash и Stab. Нож мой похож на нож в Counter-Strike. Кто хочет - юзайте как хотите и где хотите. В Readme можете меня не упомянать(Если не хотите).

Для начала надо добавить в проект файл knife.cpp

Code: knife.cpp

/***
*
* Copyright (c) 1996-2002, Valve LLC. All rights reserved.
*
* This product contains software technology licensed from Id
* Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc.
* All Rights Reserved.
*
* Use, distribution, and modification of this source code and/or resulting
* object code is restricted to non-commercial enhancements to products from
* Valve LLC. All other use, distribution, or modification is prohibited
* without written permission from Valve LLC.
*
* This weapon written by Ku2zoff
*
*
****/

#include "extdll.h"
#include "util.h"
#include "cbase.h"
#include "monsters.h"
#include "weapons.h"
#include "nodes.h"
#include "player.h"
#include "gamerules.h"

#define KNIFE_BODYHIT_VOLUME 128
#define KNIFE_WALLHIT_VOLUME 512

LINK_ENTITY_TO_CLASS( weapon_knife, CKnife );

enum knife_e {
   KNIFE_IDLE = 0,
   KNIFE_DRAW,
   KNIFE_HOLSTER,
   KNIFE_SLASH,
   KNIFE_STAB,
   KNIFE_STABMISS
};

void CKnife::Spawn( )
{
   Precache( );
   m_iId = WEAPON_KNIFE;
   SET_MODEL(ENT(pev), "models/w_knife.mdl");
   m_iClip = -1;

   FallInit();// get ready to fall down.
}


void CKnife::Precache( void )
{
   PRECACHE_MODEL("models/v_knife.mdl");
   PRECACHE_MODEL("models/w_knife.mdl");
   PRECACHE_MODEL("models/p_knife.mdl");
   PRECACHE_SOUND("weapons/knife_hit1.wav");
   PRECACHE_SOUND("weapons/knife_hit2.wav");
   PRECACHE_SOUND("weapons/knife_hitbod1.wav");
   PRECACHE_SOUND("weapons/knife_hitbod2.wav");
   PRECACHE_SOUND("weapons/knife_miss1.wav");
   PRECACHE_SOUND("weapons/knife_stab.wav");

   m_usKnife = PRECACHE_EVENT ( 1, "events/knife.sc" );
}

int CKnife::GetItemInfo(ItemInfo *p)
{
   p->pszName = STRING(pev->classname);
   p->pszAmmo1 = NULL;
   p->iMaxAmmo1 = -1;
   p->pszAmmo2 = NULL;
   p->iMaxAmmo2 = -1;
   p->iMaxClip = WEAPON_NOCLIP;
   p->iSlot = 0;
   p->iPosition = 1;
   p->iId = WEAPON_KNIFE;
   p->iWeight = KNIFE_WEIGHT;
   return 1;
}

BOOL CKnife::Deploy( )
{
   return DefaultDeploy( "models/v_knife.mdl", "models/p_knife.mdl", KNIFE_DRAW, "crowbar" );
}

void CKnife::Holster( int skiplocal /* = 0 */ )
{
   m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + 0.5;
   SendWeaponAnim( KNIFE_HOLSTER );
}

void CKnife::PrimaryAttack()
{
   if (! Slash( 1 ))
   {
     SetThink( SlashAgain );
     pev->nextthink = gpGlobals->time + 0.1;
   }
   m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 1.9;
}

void CKnife::SecondaryAttack()
{
   if (! Stab( 1 ))
   {
     SetThink( StabAgain );
     pev->nextthink = gpGlobals->time + 0.1;
   }
    m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 1.9;
}

void CKnife::Smack( )
{
   DecalGunshot( &m_trHit, BULLET_PLAYER_KNIFE );
}

void CKnife::SlashAgain( void )
{
   Slash( 0 );
}

int CKnife::Slash( int fFirst )
{
   int fDidHit = FALSE;

   TraceResult tr;

   UTIL_MakeVectors (m_pPlayer->pev->v_angle);
   Vector vecSrc = m_pPlayer->GetGunPosition( );
   Vector vecEnd = vecSrc + gpGlobals->v_forward * 32;

   UTIL_TraceLine( vecSrc, vecEnd, dont_ignore_monsters, ENT( m_pPlayer->pev ), &tr );

   #ifndef CLIENT_DLL
   if ( tr.flFraction >= 1.0 )
   {
     UTIL_TraceHull( vecSrc, vecEnd, dont_ignore_monsters, head_hull, ENT( m_pPlayer->pev ), &tr );
     if ( tr.flFraction < 1.0 )
     {
        // Calculate the point of intersection of the line (or hull) and the object we hit
       // This is and approximation of the "best" intersection
       CBaseEntity *pHit = CBaseEntity::Instance( tr.pHit );
       if ( !pHit || pHit->IsBSPModel() )
         vecEnd = tr.vecEndPos; // This is the point on the actual surface (the hull could have hit space)
     }
   }
   #endif

   PLAYBACK_EVENT_FULL( FEV_NOTHOST, m_pPlayer->edict(), m_usKnife, 0.0, (float *)&g_vecZero, (float *)&g_vecZero, 0, 0, 0,0.0, 0, 0.0 );

   SendWeaponAnim( KNIFE_SLASH );

   if ( tr.flFraction >= 1.0 )
   {
     if (fFirst)
     {
       // miss
       m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + 0.5;

       // player "shoot" animation
       m_pPlayer->SetAnimation( PLAYER_ATTACK1 );
     }
   }
   else
   {
     // player "shoot" animation
     m_pPlayer->SetAnimation( PLAYER_ATTACK1 );

     #ifndef CLIENT_DLL

     // hit
     fDidHit = TRUE;
     CBaseEntity *pEntity = CBaseEntity::Instance(tr.pHit);

     ClearMultiDamage( );

     if ( (m_flNextPrimaryAttack + 1 < UTIL_WeaponTimeBase() ) || g_pGameRules->IsMultiplayer() )
     {
       // first slash does full damage
       pEntity->TraceAttack(m_pPlayer->pev, gSkillData.plrDmgKnife, gpGlobals->v_forward, &tr, DMG_CLUB );
     }
     else
     {
        // subsequent slashs do half
       pEntity->TraceAttack(m_pPlayer->pev, gSkillData.plrDmgKnife / 2, gpGlobals->v_forward, &tr, DMG_CLUB );
     }
     ApplyMultiDamage( m_pPlayer->pev, m_pPlayer->pev );

     // play thwack, smack, or dong sound
     float flVol = 1.0;
     int fHitWorld = TRUE;

     if (pEntity)
     {
       if ( pEntity->Classify() != CLASS_NONE && pEntity->Classify() != CLASS_MACHINE )
       {
         // play thwack or smack sound
         switch( RANDOM_LONG(0,1) )
         {
         case 0:
           EMIT_SOUND(ENT(m_pPlayer->pev), CHAN_ITEM, "weapons/knife_hitbod1.wav", 1, ATTN_NORM); break;
         case 1:
           EMIT_SOUND(ENT(m_pPlayer->pev), CHAN_ITEM, "weapons/knife_hitbod2.wav", 1, ATTN_NORM); break;
         }
         m_pPlayer->m_iWeaponVolume = KNIFE_BODYHIT_VOLUME;

         fHitWorld = FALSE;
       }
     }

     // play texture hit sound
     // UNDONE: Calculate the correct point of intersection when we hit with the hull instead of the line

     if (fHitWorld)
     {
       float fvolbar = TEXTURETYPE_PlaySound(&tr, vecSrc, vecSrc + (vecEnd-vecSrc)*2, BULLET_PLAYER_KNIFE);

       if ( g_pGameRules->IsMultiplayer() )
       {
         // override the volume here, cause we don't play texture sounds in multiplayer,
        // and fvolbar is going to be 0 from the above call.

         fvolbar = 1;
       }

       // also play crowbar strike
      switch( RANDOM_LONG(0,1) )
      {
      case 0:
        EMIT_SOUND_DYN(ENT(m_pPlayer->pev), CHAN_ITEM, "weapons/knife_hit1.wav", fvolbar, ATTN_NORM, 0, 98 + RANDOM_LONG(0,3));
        break;
      case 1:
        EMIT_SOUND_DYN(ENT(m_pPlayer->pev), CHAN_ITEM, "weapons/knife_hit2.wav", fvolbar, ATTN_NORM, 0, 98 + RANDOM_LONG(0,3));
        break;
      }

       // delay the decal a bit
       m_trHit = tr;
     }

     m_pPlayer->m_iWeaponVolume = flVol * KNIFE_WALLHIT_VOLUME;
     #endif
     m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + 0.3;

     SetThink( Smack );
     pev->nextthink = UTIL_WeaponTimeBase() + 0.2;
   }
   return fDidHit;
}

void CKnife::StabAgain( void )
{
   Stab( 0 );
}

int CKnife::Stab( int fFirst )
{
   int fDidStab = FALSE;

   TraceResult tr;

   UTIL_MakeVectors (m_pPlayer->pev->v_angle);
   Vector vecSrc = m_pPlayer->GetGunPosition( );
   Vector vecEnd = vecSrc + gpGlobals->v_forward * 32;

   UTIL_TraceLine( vecSrc, vecEnd, dont_ignore_monsters, ENT( m_pPlayer->pev ), &tr );

   #ifndef CLIENT_DLL
   if ( tr.flFraction >= 1.0 )
   {
     UTIL_TraceHull( vecSrc, vecEnd, dont_ignore_monsters, head_hull, ENT( m_pPlayer->pev ), &tr );
     if ( tr.flFraction < 1.0 )
     {
       // Calculate the point of intersection of the line (or hull) and the object we hit
       // This is and approximation of the "best" intersection
       CBaseEntity *pHit = CBaseEntity::Instance( tr.pHit );
       if ( !pHit || pHit->IsBSPModel() )
         vecEnd = tr.vecEndPos; // This is the point on the actual surface (the hull could have hit space)
     }
   }
   #endif
   PLAYBACK_EVENT_FULL( FEV_NOTHOST, m_pPlayer->edict(), m_usKnife, 0.0, (float *)&g_vecZero, (float *)&g_vecZero, 0, 0, 0,0.0, 0, 0.0 );

   if ( tr.flFraction >= 1.0 )
   {
     if (fFirst)
     {
       // miss
       m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + 1.2;

       SendWeaponAnim( KNIFE_STABMISS );

       // player "shoot" animation
       m_pPlayer->SetAnimation( PLAYER_ATTACK1 );
     }
   }
   else
   {
     SendWeaponAnim( KNIFE_STAB );

     // player "shoot" animation
     m_pPlayer->SetAnimation( PLAYER_ATTACK1 );

     #ifndef CLIENT_DLL

     // hit
     fDidStab = TRUE;
     CBaseEntity *pEntity = CBaseEntity::Instance(tr.pHit);

     ClearMultiDamage( );

     if ( (m_flNextSecondaryAttack + 1 < UTIL_WeaponTimeBase() ) || g_pGameRules->IsMultiplayer() )
     {
       // first stab does full damage
       pEntity->TraceAttack(m_pPlayer->pev, gSkillData.plrDmgKnifeStab, gpGlobals->v_forward, &tr, DMG_BULLET );
     }
     else
     {
       // subsequent stabs do half
       pEntity->TraceAttack(m_pPlayer->pev, gSkillData.plrDmgKnifeStab / 2, gpGlobals->v_forward, &tr, DMG_BULLET );
     }
     ApplyMultiDamage( m_pPlayer->pev, m_pPlayer->pev );

     // play thwack, smack, or dong sound
     float flVol = 1.0;
     int fHitWorld = TRUE;

     if (pEntity)
     {
       if ( pEntity->Classify() != CLASS_NONE && pEntity->Classify() != CLASS_MACHINE )
       {
         // play thwack or smack sound
         EMIT_SOUND(ENT(m_pPlayer->pev), CHAN_ITEM, "weapons/knife_stab.wav", 1, ATTN_NORM);

         m_pPlayer->m_iWeaponVolume = KNIFE_BODYHIT_VOLUME;

         fHitWorld = FALSE;
       }
     }

     // play texture hit sound
     // UNDONE: Calculate the correct point of intersection when we hit with the hull instead of the line

     if (fHitWorld)
     {
       float fvolbar = TEXTURETYPE_PlaySound(&tr, vecSrc, vecSrc + (vecEnd-vecSrc)*2, BULLET_PLAYER_KNIFE );

       if ( g_pGameRules->IsMultiplayer() )
       {
          // override the volume here, cause we don't play texture sounds in multiplayer,
         // and fvolbar is going to be 0 from the above call.

         fvolbar = 1;
       }

       // also play crowbar strike
       switch( RANDOM_LONG(0,1) )
       {
       case 0:
         EMIT_SOUND_DYN(ENT(m_pPlayer->pev), CHAN_ITEM, "weapons/knife_hit1.wav", fvolbar, ATTN_NORM, 0, 98 + RANDOM_LONG(0,3));
         break;
       case 1:
         EMIT_SOUND_DYN(ENT(m_pPlayer->pev), CHAN_ITEM, "weapons/knife_hit2.wav", fvolbar, ATTN_NORM, 0, 98 + RANDOM_LONG(0,3));
         break;
       }

       // delay the decal a bit
       m_trHit = tr;
     }

     m_pPlayer->m_iWeaponVolume = flVol * KNIFE_WALLHIT_VOLUME;
     #endif
     m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + 1.2;

     SetThink( Smack );
     pev->nextthink = UTIL_WeaponTimeBase() + 0.2;

   }
   return fDidStab;
}

void CKnife::WeaponIdle( void )
{
   if ( m_flTimeWeaponIdle > UTIL_WeaponTimeBase() )
     return;

   SendWeaponAnim( KNIFE_IDLE, 1 );
   m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 60.0 / 5.0;
}

Потом открываем game.cpp и добавляем в него:

Code:

// Tripmine
cvar_t sk_plr_tripmine1 = {"sk_plr_tripmine1","0"};
cvar_t sk_plr_tripmine2 = {"sk_plr_tripmine2","0"};
cvar_t sk_plr_tripmine3 = {"sk_plr_tripmine3","0"};// <= уже есть этот код

// Knife slash
cvar_t sk_plr_knife1 = {"sk_plr_knife1","0"};
cvar_t sk_plr_knife2 = {"sk_plr_knife2","0"};
cvar_t sk_plr_knife3 = {"sk_plr_knife3","0"};

// Knife stab
cvar_t sk_plr_knife_stab1 = {"sk_plr_knife_stab1","0"};
cvar_t sk_plr_knife_stab2 = {"sk_plr_knife_stab2","0"};
cvar_t sk_plr_knife_stab3 = {"sk_plr_knife_stab3","0"}; //новый код

Затем спускаемся ниже и аналогично добавляем:

Code:

// Tripmine
CVAR_REGISTER ( &sk_plr_tripmine1 );// {"sk_plr_tripmine1","0"};
CVAR_REGISTER ( &sk_plr_tripmine2 );// {"sk_plr_tripmine2","0"};
CVAR_REGISTER ( &sk_plr_tripmine3 );// {"sk_plr_tripmine3","0"};//существующий код

// Knife slash
CVAR_REGISTER ( &sk_plr_knife1 );// {"sk_plr_knife1","0"};
CVAR_REGISTER ( &sk_plr_knife2 );// {"sk_plr_knife2","0"};
CVAR_REGISTER ( &sk_plr_knife3 );// {"sk_plr_knife3","0"};

// Knife stab
CVAR_REGISTER ( &sk_plr_knife_stab1 );// {"sk_plr_knife_stab1","0"};
CVAR_REGISTER ( &sk_plr_knife_stab2 );// {"sk_plr_knife_stab2","0"};
CVAR_REGISTER ( &sk_plr_knife_stab3 );// {"sk_plr_knife_stab3","0"};//новый код

После этого открываем gamerules.cpp и дописываем после

Code:

// Tripmine
gSkillData.plrDmgTripmine = GetSkillCvar( "sk_plr_tripmine");

вот это:

Code:

// Knife slash
gSkillData.plrDmgKnife = GetSkillCvar( "sk_plr_knife");

// Knife stab
gSkillData.plrDmgKnifeStab = GetSkillCvar( "sk_plr_knife_stab");

Потом надо открыть multiplay_gamerules.cpp и точно также после

Code:

// Tripmine
gSkillData.plrDmgTripmine = 150;

добавить:

Code:

// Knife slash
gSkillData.plrDmgKnife = 15;

// Knife stab
gSkillData.plrDmgKnifeStab = 35;//значения могут быть любыми, это убойная сила ножа в мультиплеере

Если вы хотите, чтобы нож можно было получить с помощью команды impulse 101, то откройте player.cpp и сделайте следующее:

Code:

case 101:
   gEvilImpulse101 = TRUE;
   GiveNamedItem( "item_suit" );
   GiveNamedItem( "item_battery" );
   GiveNamedItem( "weapon_crowbar" );
   GiveNamedItem( "weapon_9mmhandgun" );
   GiveNamedItem( "ammo_9mmclip" );
   GiveNamedItem( "weapon_shotgun" );
   GiveNamedItem( "ammo_buckshot" );
   GiveNamedItem( "weapon_9mmAR" );
   GiveNamedItem( "ammo_9mmAR" );
   GiveNamedItem( "ammo_ARgrenades" );
   GiveNamedItem( "weapon_handgrenade" );
   GiveNamedItem( "weapon_tripmine" );
   GiveNamedItem( "weapon_knife" );//новая строчка
#ifndef OEM_BUILD

Затем в файле skill.h добавьте:

Code:

float plrDmgRPG;
float plrDmgGauss;
float plrDmgEgonNarrow;
float plrDmgEgonWide;
float plrDmgHornet;
float plrDmgHandGrenade;
float plrDmgSatchel;
float plrDmgTripmine;
float plrDmgKnife;
float plrDmgKnifeStab;//для ножа

После в weapons.cpp в функцию void W_Precache(void) добавьте

Code:

// knife
UTIL_PrecacheOtherWeapon( "weapon_knife" );

и том же файле чуть выше

Code:

case BULLET_PLAYER_CROWBAR:
case BULLET_PLAYER_KNIFE: //новая строка

Потом надо добавить новые значения в weapons.h:

Code:

#define WEAPON_HORNETGUN 11
#define WEAPON_HANDGRENADE 12
#define WEAPON_TRIPMINE 13
#define WEAPON_SATCHEL 14
#define WEAPON_SNARK 15
#define WEAPON_KNIFE 16//Новая строчка

Ниже:

Code:

#define HORNETGUN_WEIGHT 10
#define HANDGRENADE_WEIGHT 5
#define AKM_WEIGHT 20
#define SATCHEL_WEIGHT -10
#define TRIPMINE_WEIGHT -10
#define SNARK_WEIGHT -10
#define KNIFE_WEIGHT 10//Новая строчка

Потом после:

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_PLAYER_KNIFE, //новая строчка

И, наконец в самом низу файла после

Code:

class CTripmine : public CBasePlayerWeapon
{
   public:
     void Spawn( void );
     void Precache( void );
     int iItemSlot( void ) { return 5; }
     int GetItemInfo(ItemInfo *p);
     void SetObjectCollisionBox( void )
     {
       //!!!BUGBUG - fix the model!
       pev->absmin = pev->origin + Vector(-16, -16, -5);
       pev->absmax = pev->origin + Vector(16, 16, 28);
     }

     void PrimaryAttack( void );
     BOOL Deploy( void );
     void Holster( int skiplocal = 0 );
     void WeaponIdle( void );

     virtual BOOL UseDecrement( void )
     {
     #if defined( CLIENT_WEAPONS )
       return TRUE;
     #else
       return FALSE;
     #endif
     }

   private:
     unsigned short m_usTripFire;
};

Нужно вставить вот это:

Code:

class CKnife : public CBasePlayerWeapon
{
   public:
     void Spawn( void );
     void Precache( void );
     int iItemSlot( void ) { return 1; }
     void EXPORT SlashAgain( void );
     void EXPORT StabAgain( void );
     int GetItemInfo(ItemInfo *p);
     void EXPORT Smack( void );
     void WeaponIdle( void );

     void PrimaryAttack( void );
     void SecondaryAttack( void );
     int Stab( int fFirst );
     int Slash( int fFirst );
     BOOL Deploy( void );
     void Holster( int skiplocal = 0 );
     int m_iSlash;
     int m_iStab;
     TraceResult m_trHit;

    virtual BOOL UseDecrement( void )
    {
    #if defined( CLIENT_WEAPONS )
      return TRUE;
    #else
      return FALSE;
    #endif
    }
   private:
     unsigned short m_usKnife;
};

Далее в sound.cpp заменим

Code:

if (iBulletType == BULLET_PLAYER_CROWBAR)

на

Code:

if (iBulletType == BULLET_PLAYER_CROWBAR || BULLET_PLAYER_KNIFE)

С сервером мы закончили, переходим на клиент.Добавляем в проект файл knife.cpp

В папке cl_dll находим файл EV_HLDM.cpp и добавляем:

Code:

void EV_EgonStop( struct event_args_s *args );
void EV_HornetGunFire( struct event_args_s *args );
void EV_TripmineFire( struct event_args_s *args );
void EV_SnarkFire( struct event_args_s *args );
void EV_Knife( struct event_args_s *args );//Новая строчка

После спускаемся вниз и после

Code:

//======================
// SQUEAK START
//======================
enum squeak_e {
   SQUEAK_IDLE1 = 0,
   SQUEAK_FIDGETFIT,
   SQUEAK_FIDGETNIP,
   SQUEAK_DOWN,
   SQUEAK_UP,
   SQUEAK_THROW
};

#define VEC_HULL_MIN Vector(-16, -16, -36)
#define VEC_DUCK_HULL_MIN Vector(-16, -16, -18 )

void EV_SnarkFire( event_args_t *args )
{
   int idx;
   vec3_t vecSrc, angles, view_ofs, forward;
   pmtrace_t tr;

   idx = args->entindex;
   VectorCopy( args->origin, vecSrc );
   VectorCopy( args->angles, angles );

   AngleVectors ( angles, forward, NULL, NULL );

   if ( !EV_IsLocal ( idx ) )
     return;

   if ( args->ducking )
     vecSrc = vecSrc - ( VEC_HULL_MIN - VEC_DUCK_HULL_MIN );

   // Store off the old count
   gEngfuncs.pEventAPI->EV_PushPMStates();

   // Now add in all of the players.
   gEngfuncs.pEventAPI->EV_SetSolidPlayers ( idx - 1 );
   gEngfuncs.pEventAPI->EV_SetTraceHull( 2 );
   gEngfuncs.pEventAPI->EV_PlayerTrace( vecSrc + forward * 20, vecSrc + forward * 64, PM_NORMAL, -1, &tr );

   //Find space to drop the thing.
   if ( tr.allsolid == 0 && tr.startsolid == 0 && tr.fraction > 0.25 )
     gEngfuncs.pEventAPI->EV_WeaponAnimation ( SQUEAK_THROW, 0 );

   gEngfuncs.pEventAPI->EV_PopPMStates();
}
//======================
// SQUEAK END
//======================

Добавляем новый event:

Code:

//======================
// KNIFE START
//======================
enum knife_e {
   KNIFE_IDLE = 0,
   KNIFE_DRAW,
   KNIFE_HOLSTER,
   KNIFE_SLASH,
   KNIFE_STAB,
   KNIFE_STABMISS
};

void EV_Knife( event_args_t *args )
{
   int idx;
   vec3_t origin;

   idx = args->entindex;
   VectorCopy( args->origin, origin );

   //Play Swing sound
   gEngfuncs.pEventAPI->EV_PlaySound( idx, origin, CHAN_WEAPON, "weapons/knife_miss1.wav", 1, ATTN_NORM, 0, PITCH_NORM);
}
//======================
// KNIFE END
//======================

Потом идём в файл view.cpp

Code:

{ "models/p_shotgun.mdl", "models/v_shotgun.mdl" },
{ "models/p_squeak.mdl", "models/v_squeak.mdl" },
{ "models/p_tripmine.mdl", "models/v_tripmine.mdl" },
{ "models/p_satchel_radio.mdl", "models/v_satchel_radio.mdl" },
{ "models/p_satchel.mdl", "models/v_satchel.mdl" },
{ "models/p_knife.mdl", "models/v_knife.mdl" },//Новая строчка

После открываем hl_events.cpp

Code:

void EV_HornetGunFire( struct event_args_s *args );
void EV_TripmineFire( struct event_args_s *args );
void EV_SnarkFire( struct event_args_s *args );
void EV_Knife( struct event_args_s *args );//Новая строчка

Затем спускаемся ниже:

Code:

gEngfuncs.pfnHookEvent( "events/firehornet.sc", EV_HornetGunFire );
gEngfuncs.pfnHookEvent( "events/tripfire.sc", EV_TripmineFire );
gEngfuncs.pfnHookEvent( "events/snarkfire.sc", EV_SnarkFire );
gEngfuncs.pfnHookEvent( "events/knife.sc", EV_Knife );//Новая строчка

И последний файл клиента hl_weapons.cpp

Code:

CHgun g_HGun;
CHandGrenade g_HandGren;
CSatchel g_Satchel;
CTripmine g_Tripmine;
CSqueak g_Snark;
CKnife g_Knife;//Новая строчка

Затем ниже в функции void HUD_InitClientWeapons( void )

Code:

HUD_PrepEntity( &g_HGun , &player );
HUD_PrepEntity( &g_HandGren , &player );
HUD_PrepEntity( &g_Satchel , &player );
HUD_PrepEntity( &g_Tripmine , &player );
HUD_PrepEntity( &g_Snark , &player );
HUD_PrepEntity( &g_Knife , &player );//Новая строчка

Ещё ниже после

Code:

case WEAPON_SNARK:
   pWeapon = &g_Snark;
   break;

Пишем:

Code:

case WEAPON_KNIFE:
   pWeapon = &g_Knife;
   break;

Потом идём в ev_hldm.h и вставляем туда

Code:

BULLET_PLAYER_CROWBAR, // crowbar swipe
BULLET_PLAYER_KNIFE, //новая строка

Потом в ev_hldm.cpp заменяем

Code:

if (iBulletType == BULLET_PLAYER_CROWBAR)

на

Code:

if (iBulletType == BULLET_PLAYER_CROWBAR || BULLET_PLAYER_KNIFE)

На этом всё и не забудте создать файл knife.sc в папке events вашего мода.



Similar1. Добавление новых классов для монстр - Мы будем добавлять новый класс Блэк Опс из Оппосинг Форс
2. Динамическое освещение - этой статье будет описан способ добавления динамических вспышек света, которые можно использовать для еффекта молнии
3. Переключение оружия a la HL2 - Мне не нравится, как переключается оружие в ХЛ. Может, кому-то и интересно тыкать по менюшкам худа, но мне больше нравится реализация переключения в Unreal RTN, Quake Mission Packs и HL2
4. Увеличение количества мяса от взрыв - Увеличение количества мяса от взрывов людей или инопланетян.
5. Как сделать вортигонта из HL1 другом - Моя первая статья
6. Звук попадания как в HL2 - Работа на клиенте
Ссылки на объект
Полная ссылка на текущем языке :
Короткая ссылка :
Ссылка на превью-картинку :
Ссылка на картинку в полном размере :
Ссылка для вашего форума или сайта
BB код ссылка:
BB код ссылка с картинкой :
BB код картинки :
HTML код ссылка:
HTML код ссылка с картинкой :
HTML код картинки :
You cannot comment, because you are not registered.
    Персонажи
    Персонажи
    Оружие
    Оружие
    Разное
    Разное
    Моды
    Моды