Итак, сегодня я вам расскажу, как создавать СМГ2 из бетки. Если кто не в курсе – это тот же СМГ1, только с двумя режимами стрельбы. Итак создаем на сервера файл weapon_smg2.cpp и пишем туда этот код: //========= Copyright © 2007, Valve LLC, OlegS, All rights reserved. ============ // // Purpose: Экскулюзив для detler.ucoz.ru // //============================================================================= #include "cbase.h" #include "basehlcombatweapon.h" #include "NPCevent.h" #include "basecombatcharacter.h" #include "AI_BaseNPC.h" #include "player.h" #include "game.h" #include "in_buttons.h" class CWeaponSMG2 : public CHLSelectFireMachineGun { public: DECLARE_CLASS( CWeaponSMG2, CHLSelectFireMachineGun ); CWeaponSMG2(); DECLARE_SERVERCLASS(); const Vector &GetBulletSpread( void ); void Precache( void ); void AddViewKick( void ); void Operator_HandleAnimEvent( animevent_t *pEvent, CBaseCombatCharacter *pOperator ); float GetFireRate( void ) { return 0.1f; } int CapabilitiesGet( void ) { return bits_CAP_WEAPON_RANGE_ATTACK1; } DECLARE_ACTTABLE(); }; IMPLEMENT_SERVERCLASS_ST(CWeaponSMG2, DT_WeaponSMG2) END_SEND_TABLE() LINK_ENTITY_TO_CLASS( weapon_smg2, CWeaponSMG2 ); PRECACHE_WEAPON_REGISTER(weapon_smg2); acttable_t CWeaponSMG2::m_acttable[] = { { ACT_RANGE_ATTACK1, ACT_RANGE_ATTACK_SMG2, true }, }; IMPLEMENT_ACTTABLE(CWeaponSMG2); //========================================================= CWeaponSMG2::CWeaponSMG2( ) { m_fMaxRange1 = 2000; m_fMinRange1 = 32; m_iFireMode = FIREMODE_3RNDBURST; } void CWeaponSMG2::Precache( void ) { BaseClass::Precache(); } //----------------------------------------------------------------------------- // Purpose: // Output : const Vector //----------------------------------------------------------------------------- const Vector &CWeaponSMG2::GetBulletSpread( void ) { static const Vector cone = VECTOR_CONE_10DEGREES; return cone; } //----------------------------------------------------------------------------- // Purpose: // Input : *pEvent - // *pOperator - //----------------------------------------------------------------------------- void CWeaponSMG2::Operator_HandleAnimEvent( animevent_t *pEvent, CBaseCombatCharacter *pOperator ) { switch( pEvent->event ) { case EVENT_WEAPON_SMG2: { 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 ); m_iClip1 = m_iClip1 - 1; } break; default: BaseClass::Operator_HandleAnimEvent( pEvent, pOperator ); break; } } //----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CWeaponSMG2::AddViewKick( void ) { #define EASY_DAMPEN 0.5f #define MAX_VERTICAL_KICK 2.0f //Degrees #define SLIDE_LIMIT 1.0f //Seconds //Get the view kick CBasePlayer *pPlayer = ToBasePlayer( GetOwner() ); if (!pPlayer) return; DoMachineGunKick( pPlayer, EASY_DAMPEN, MAX_VERTICAL_KICK, m_fFireDuration, SLIDE_LIMIT ); } Теперь лезем на клиент и открываем файл c_weapon__stubs.cpp и пишем после строки STUB_WEAPON_CLASS( weapon_smg1, WeaponSMG1, C_HLSelectFireMachineGun ); пишем эту строку STUB_WEAPON_CLASS( weapon_smg2, WeaponSMG2, C_HLSelectFireMachineGun ); Все, теперь пишем скрипт для нашего оружия. Итак, лезем в %ПАПКУ_С_МОДОМ\scripts и создаём файл weapon_smg2.txt. Туда пишем такой текст: // Small Machine Gun 2 WeaponData { // Weapon data is loaded by both the Game and Client DLLs. "printname" "SMG2" "viewmodel" "models/weapons/v_smg2.mdl" \\модель из тутора "playermodel" "models/weapons/w_smg2.mdl" \\модель из тутора "anim_prefix" "smg2" "bucket" "2" "bucket_position" "2" "clip_size" "45" "clip2_size" "-1" "default_clip" "45" "default_clip2" "-1" "primary_ammo" "SMG1" "secondary_ammo" "SMG1" "weight" "3" "item_flags" "0" // Sounds for the weapon. There is a max of 16 sounds per category (i.e. max 16 "single_shot" sounds) SoundData { "reload" "Weapon_SMG2.Reload" "single_shot" "Weapon_SMG2.Single" "special1" "Weapon_SMG2.Special1" "special2" "Weapon_SMG2.Special2" "burst" "Weapon_SMG2.Burst" "single_shot_npc" "Weapon_SMG2.NPC_Single" "reload_npc" "Weapon_SMG2.NPC_Reload" } // Weapon Sprite data is loaded by the Client DLL. TextureData { "weapon" { "font" "WeaponIcons" "character" "a" } "weapon_s" { "font" "WeaponIconsSelected" "character" "a" } "ammo" { "font" "WeaponIcons" "character" "r" } "ammo2" { "font" "WeaponIcons" "character" "t" } "crosshair" { "font" "Crosshairs" "character" "Q" } "autoaim" { "file" "sprites/crosshairs" "x" "0" "y" "48" "width" "24" "height" "24" } } } Все, с скриптом закончили, теперь разберёмся со звуками. Для добавления звуков оружия нам нужен файл game_sounds_weapons.txt и добавляем следующее: "Weapon_SMG2.Reload" { "channel" "CHAN_ITEM" "volume" "0.7" "soundlevel" "SNDLVL_NORM" "wave" "weapons/smg2/smg2_reload.wav" } "Weapon_SMG2.NPC_Reload" { "channel" "CHAN_ITEM" "volume" "0.7" "soundlevel" "SNDLVL_NORM" "wave" "weapons/smg2/smg2_reload.wav" } "Weapon_SMG2.Empty" { "channel" "CHAN_WEAPON" "volume" "0.7" "soundlevel" "SNDLVL_NORM" "wave" "weapons/pistol/pistol_empty.wav" } "Weapon_SMG2.Single" { "channel" "CHAN_WEAPON" "volume" "0.55" "soundlevel" "SNDLVL_GUNFIRE" "pitch" "95,105" "wave" "weapons/smg2/smg2_fire1.wav" } "Weapon_SMG2.Double" { "channel" "CHAN_WEAPON" "volume" "0.61" "soundlevel" "SNDLVL_GUNFIRE" "wave" "weapons/ar2/ar2_altfire.wav" } "Weapon_SMG2.NPC_Single" { "channel" "CHAN_WEAPON" "volume" "0.7" "soundlevel" "SNDLVL_GUNFIRE" "pitch" "95,105" "wave" "weapons/smg1/npc_smg2_fire1.wav" } "Weapon_SMG2.Special1" { "channel" "CHAN_WEAPON" "volume" "0.7" "soundlevel" "SNDLVL_NORM" "wave" "weapons/smg1/switch_single.wav" } "Weapon_SMG2.Special2" { "channel" "CHAN_WEAPON" "volume" "0.7" "soundlevel" "SNDLVL_NORM" "wave" "weapons/smg1/switch_burst.wav" } "Weapon_SMG2.Burst" { "channel" "CHAN_WEAPON" "volume" "0.7" "soundlevel" "SNDLVL_GUNFIRE" "pitch" "98,105" "wave" "weapons/smg2/smg2_fire1.wav" } Модели и звуки к туториалу
|