Итак, создаем weapon_ar1.cpp и пишем код: //========= Copyright © 1996-2003, Valve LLC, All rights reserved. ============ // // Purpose: // //============================================================================= #include "cbase.h" #include "basehlcombatweapon.h" #include "NPCevent.h" #include "basecombatcharacter.h" #include "AI_BaseNPC.h" #include "player.h" #include "in_buttons.h" #define DAMAGE_PER_SECOND 10 #define MAX_SETTINGS 5 float RateOfFire[ MAX_SETTINGS ] = { 0.1, 0.2, 0.5, 0.7, 1.0, }; float Damage[ MAX_SETTINGS ] = { 2, 4, 10, 14, 20, }; //========================================================= //========================================================= class CWeaponAR1 : public CHLMachineGun { DECLARE_DATADESC(); public: DECLARE_CLASS( CWeaponAR1, CHLMachineGun ); DECLARE_SERVERCLASS(); CWeaponAR1(); int m_ROF; void Precache( void ); bool Deploy( void ); float GetFireRate( void ) {return RateOfFire[ m_ROF ];} int CapabilitiesGet( void ) { return bits_CAP_WEAPON_RANGE_ATTACK1; } void SecondaryAttack( void ); void FireBullets(int cShots, const Vector &vecSrc, const Vector &vecDirShooting, const Vector &vecSpread, float flDistance, int iBulletType, int iTracerFreq); virtual const Vector& GetBulletSpread( void ) { static const Vector cone = VECTOR_CONE_10DEGREES; return cone; } void Operator_HandleAnimEvent( animevent_t *pEvent, CBaseCombatCharacter *pOperator ) { switch( pEvent->event ) { case EVENT_WEAPON_AR1: { Vector vecShootOrigin, vecShootDir; vecShootOrigin = pOperator->Weapon_ShootPosition( ); CAI_BaseNPC *npc = pOperator->MyNPCPointer(); ASSERT( npc != NULL ); vecShootDir = npc->GetActualShootTrajectory( vecShootOrigin ); WeaponSound(SINGLE_NPC); pOperator->FireBullets( 1, vecShootOrigin, vecShootDir, VECTOR_CONE_PRECALCULATED, MAX_TRACE_LENGTH, m_iPrimaryAmmoType, 2 ); } break; default: CBaseCombatWeapon::Operator_HandleAnimEvent( pEvent, pOperator ); break; } } DECLARE_ACTTABLE(); }; IMPLEMENT_SERVERCLASS_ST(CWeaponAR1, DT_WeaponAR1) END_SEND_TABLE() LINK_ENTITY_TO_CLASS( weapon_ar1, CWeaponAR1 ); PRECACHE_WEAPON_REGISTER(weapon_ar1); acttable_t CWeaponAR1::m_acttable[] = { { ACT_RANGE_ATTACK1, ACT_RANGE_ATTACK_AR1, true }, }; IMPLEMENT_ACTTABLE(CWeaponAR1); //--------------------------------------------------------- // Save/Restore //--------------------------------------------------------- BEGIN_DATADESC( CWeaponAR1 ) // DEFINE_FIELD( CWeaponAR1, m_ROF, FIELD_INTEGER ), END_DATADESC() CWeaponAR1::CWeaponAR1( ) { m_ROF = 0; } void CWeaponAR1::Precache( void ) { BaseClass::Precache(); } bool CWeaponAR1::Deploy( void ) { //CBaseCombatCharacter *pOwner = m_hOwner; return BaseClass::Deploy(); } //========================================================= //========================================================= void CWeaponAR1::FireBullets(int cShots, const Vector &vecSrc, const Vector &vecDirShooting, const Vector &vecSpread, float flDistance, int iBulletType, int iTracerFreq) { if(CBasePlayer *pPlayer = ToBasePlayer( GetOwner() )) { pPlayer->FireBullets(cShots, vecSrc, vecDirShooting, vecSpread, flDistance, iBulletType, iTracerFreq, -1, -1, Damage[ m_ROF ] ); } } void CWeaponAR1::SecondaryAttack( void ) { CBasePlayer *pPlayer = ToBasePlayer( GetOwner() ); if ( pPlayer ) { pPlayer->m_nButtons &= ~IN_ATTACK2; } m_flNextSecondaryAttack = gpGlobals->curtime + 0.1; m_ROF += 1; if( m_ROF == MAX_SETTINGS ) { m_ROF = 0; } int i; Msg( "\n" ); for( i = 0 ; i < MAX_SETTINGS ; i++ ) { if( i == m_ROF ) { Msg( "|" ); } else { Msg( "-" ); } } Msg( "\n" ); } Теперь лезем в стабсы (c_weapon__stubs) и там прописуем наше новое оружие: STUB_WEAPON_CLASS( weapon_ar1, WeaponAR1, C_HLMachineGun ); Все, теперь скрипт. Создаем в папке scripts файл weapon_ar1.txt и пешем туда: // Assault Rifle 1 WeaponData { // Weapon data is loaded by both the Game and Client DLLs. "printname" "AR1" "viewmodel" "models/weapons/v_rif_ak47.mdl" \\модель из тутора "playermodel" "models/weapons/w_rif_ak47.mdl" \\модель из тутора "anim_prefix" "ar2" "bucket" "2" "bucket_position" "1" "clip_size" "30" "default_clip" "30" "clip2_size" "-1" "default_clip2" "-1" "primary_ammo" "AR2" "secondary_ammo" "None" "weight" "5" "item_flags" "0" // Sounds for the weapon. There is a max of 16 sounds per category (i.e. max 16 "single_shot" sounds) { "empty" "Weapon_AR1.Empty" "reload" "Weapon_AR1.Reload" "single_shot" "Weapon_AR1.Single" "double_shot" "Weapon_AR1.Double" // NPC SECTION "single_shot_npc" "Weapon_AR1.NPC_Single" "reload_npc" "Weapon_AR1.NPC_Reload" "double_shot_npc" "Weapon_AR1.NPC_Double" }// Weapon Sprite data is loaded by the Client DLL. TextureData { "weapon" { "font" "WeaponIcons" "character" "l" } "weapon_s" { "font" "WeaponIconsSelected" "character" "l" } "ammo" { "font" "WeaponIcons" "character" "u" } "ammo2" { "font" "WeaponIcons" "character" "z" } "crosshair" { "font" "Crosshairs" "character" "Q" } "autoaim" { "file" "sprites/crosshairs" "x" "0" "y" "48" "width" "24" "height" "24" } } } Все, теперь запускаем игру и в консоли прописуем give weapon_ar1 и радуемся жизни! АГА, я так и знал! ТЫ ЗАБЫЛ СДЕАТЬ ЗВУКИ!!! Снову идем в скриптс и в файл game_sounds_weapons.txt дописуем: // weapon_ar1.txt "Weapon_AR1.Empty" { "channel" "CHAN_WEAPON" "volume" "1.0" "soundlevel" "SNDLVL_NORM" "wave" "weapons/ar2/ar2_empty.wav" } "Weapon_AR1.Reload" { "channel" "CHAN_ITEM" "volume" "1.0" "soundlevel" "SNDLVL_NORM" "wave" "weapons/ar2/ar2_reload.wav" } "Weapon_AR1.Single" { "channel" "CHAN_WEAPON" "volume" "1.0" "soundlevel" "SNDLVL_GUNFIRE" "pitch" "95,105" "wave" "weapons/ar2/ar2_fire1.wav" } "Weapon_AR1.Double" { "channel" "CHAN_WEAPON" "volume" "1.0" "soundlevel" "SNDLVL_GUNFIRE" "wave" "weapons/ar2/ar2_altfire.wav" } "Weapon_AR1.NPC_Single" { "channel" "CHAN_WEAPON" "volume" "1.0" "soundlevel" "SNDLVL_GUNFIRE" "pitch" "95,105" "wave" "weapons/ar2/npc_ar2_fire1.wav" } "Weapon_AR1.NPC_Reload" { "channel" "CHAN_ITEM" "volume" "1.0" "soundlevel" "SNDLVL_NORM" "wave" "weapons/ar2/npc_ar2_reload.wav" } "Weapon_AR1.NPC_Double" { "channel" "CHAN_WEAPON" "volume" "1.0" "soundlevel" "SNDLVL_GUNFIRE" "wave" "weapons/ar2/npc_ar2_altfire.wav" } Модели к тутору качать здесь.
|