Приступим. Ищем файл weapon_parse.h _______________________________________________________________________________________________________ В самом низу добавляем строки, с подписью //ADDED class FileWeaponInfo_t { public: FileWeaponInfo_t(); //ironsight Vector m_expOffset; //ADDED QAngle m_expOriOffset; //ADDED .... };_______________________________________________________________________________________________________ Теперь к weapon_parse.cpp _______________________________________________________________________________________________________ Добавим это: void FileWeaponInfo_t::Parse( KeyValues *pKeyValuesData, const char *szWeaponName ) { ... // this just saves off the data in the script file for later use KeyValues *pEt = pKeyValuesData->FindKey("ExpOffset"); if (pEt) { m_expOffset.x = pEt->GetFloat("x", 0.0f); m_expOffset.y = pEt->GetFloat("y", 0.0f); m_expOffset.z = pEt->GetFloat("z", 0.0f); m_expOriOffset.x = pEt->GetFloat("xori", 0.0f); m_expOriOffset.y = pEt->GetFloat("yori", 0.0f); m_expOriOffset.z = pEt->GetFloat("zori", 0.0f); } else { m_expOffset = vec3_origin; m_expOriOffset.Init(); } ... }_______________________________________________________________________________________________________ baseviewmodel_shared.cpp _______________________________________________________________________________________________________ Меняем начало, чтобы оно выглядело вот так: #include "cbase.h" #include "baseviewmodel_shared.h" #if defined( CLIENT_DLL ) #include "iprediction.h" #include "prediction.h" // cin: 070105 - ironsight mode changes #include "convar.h" #include "c_baseplayer.h" #include "c_basecombatweapon.h" #else #include "vguiscreen.h" #endif // memdbgon must be the last include file in a .cpp file!!! #include "tier0/memdbgon.h" Ниже меняем так: #define VIEWMODEL_ANIMATION_PARITY_BITS 3 #define SCREEN_OVERLAY_MATERIAL "vgui/screens/vgui_overlay" #if defined( CLIENT_DLL ) void ExpWpnTestOffset(ConVar *pConVar, char *pszString); ConVar cl_exp_test_wpn_offset("cl_exp_test_wpn_offset", "0", 0, "Tests weapon offsets", (FnChangeCallback)ExpWpnTestOffset); ConVar cl_exp_test_wpn_offset_x("cl_exp_test_wpn_offset_x", "0"); ConVar cl_exp_test_wpn_offset_y("cl_exp_test_wpn_offset_y", "0"); ConVar cl_exp_test_wpn_offset_z("cl_exp_test_wpn_offset_z", "0"); ConVar cl_exp_test_wpn_ori_offset_x("cl_exp_test_wpn_ori_offset_x", "0"); ConVar cl_exp_test_wpn_ori_offset_y("cl_exp_test_wpn_ori_offset_y", "0"); ConVar cl_exp_test_wpn_ori_offset_z("cl_exp_test_wpn_ori_offset_z", "0"); // cin: 070105 - applies existing weapon offsets when // entering test mode (this will not be called upon // weapon change, so beware) // this mode should only be used for calibrating the // ironsighted mode offests for a particular weapon void ExpWpnTestOffset(ConVar *pConVar, char *pszString) { CBasePlayer *pPlayer = UTIL_PlayerByIndex(engine->GetLocalPlayer()); if (pPlayer) { CBaseCombatWeapon *pWeapon = pPlayer->GetActiveWeapon(); if (pWeapon) { cl_exp_test_wpn_offset_x.SetValue(pWeapon->GetWpnData().m_expOffset.x); cl_exp_test_wpn_offset_y.SetValue(pWeapon->GetWpnData().m_expOffset.y); cl_exp_test_wpn_offset_z.SetValue(pWeapon->GetWpnData().m_expOffset.z); cl_exp_test_wpn_ori_offset_x.SetValue(pWeapon->GetWpnData().m_expOriOffset.x); cl_exp_test_wpn_ori_offset_y.SetValue(pWeapon->GetWpnData().m_expOriOffset.y); cl_exp_test_wpn_ori_offset_z.SetValue(pWeapon->GetWpnData().m_expOriOffset.z); } } } // last time ironsighted mode was toggled float gIronsightedTime(0.0f); // i bound this to a key for testing(i.e. bind [ ironsight_toggle) CON_COMMAND(ironsight_toggle, "toggles ironsight mode for the current weapon") { if (gpGlobals->curtime - gIronsightedTime < 0.5f) return; CBasePlayer *pPlayer = UTIL_PlayerByIndex(engine->GetLocalPlayer()); if (pPlayer) { C_BaseViewModel *pVm = pPlayer->GetViewModel(); if (pVm) { //pPlayer->m_Local.m_iHideHUD |= HIDEHUD_CROSSHAIR;) pVm->m_bExpSighted ^= true; gIronsightedTime = gpGlobals->curtime; } } } void CalcExpWpnOffsets(CBasePlayer *owner, Vector &pos, QAngle &ang) { Vector forward, right, up, offset; // this is a simple test mode to help determine the proper values // to place in the weapon script if (cl_exp_test_wpn_offset.GetBool()) { ang.x += cl_exp_test_wpn_ori_offset_x.GetFloat(); ang.y += cl_exp_test_wpn_ori_offset_y.GetFloat(); ang.z += cl_exp_test_wpn_ori_offset_z.GetFloat(); offset.Init(cl_exp_test_wpn_offset_x.GetFloat(), cl_exp_test_wpn_offset_y.GetFloat(), cl_exp_test_wpn_offset_z.GetFloat()); } else { CBaseCombatWeapon *pWeapon = owner->GetActiveWeapon(); if (pWeapon) { ang += pWeapon->GetWpnData().m_expOriOffset; offset = pWeapon->GetWpnData().m_expOffset; } } // get eye direction angles AngleVectors(ang, &forward, &right, &up); // apply the offsets pos += forward * offset.x; pos += right * offset.y; pos += up * offset.z; } #endif[b] Находим строку ViewModel::Spawn и меняем: [b]void CBaseViewModel::Spawn( void ) { Precache( ); SetSize( Vector( -8, -4, -2), Vector(8, 4, 2) ); SetSolid( SOLID_NONE ); #ifdef CLIENT_DLL // cin: 070105 - ironsighted mode changes m_bExpSighted = false; m_expFactor = 0.0f; #endif }_______________________________________________________________________________________________________ _______________________________________________________________________________________________________ Анимируем пушку _______________________________________________________________________________________________________ Ищем строку void CBaseViewModel::CalcViewModelView и заменяем всю функцию. void CBaseViewModel::CalcViewModelView( CBasePlayer *owner, const Vector& eyePosition, const QAngle& eyeAngles ) { // UNDONE: Calc this on the server? Disabled for now as it seems unnecessary to have this info on the server #if defined( CLIENT_DLL ) QAngle vmangoriginal = eyeAngles; QAngle vmangles = eyeAngles; Vector vmorigin = eyePosition; CBaseCombatWeapon *pWeapon = m_hWeapon.Get(); //Allow weapon lagging if ( pWeapon != NULL ) { #if defined( CLIENT_DLL ) if ( !prediction->InPrediction() ) #endif { pWeapon->AddViewmodelBob( this, vmorigin, vmangles ); CalcViewModelLag( vmorigin, vmangles, vmangoriginal ); } } #if defined( CLIENT_DLL ) if ( !prediction->InPrediction() ) { // Let the viewmodel shake at about 10% of the amplitude of the player's view vieweffects->ApplyShake( vmorigin, vmangles, 0.1 ); } #endif // cin: 070105 - ironsighted mode changes // get the wpn offsets CalcExpWpnOffsets(owner, vmorigin, vmangles); // get delta time for 1 sec interpolation and interpolate to/from positional offset float delta(gpGlobals->curtime - gIronsightedTime); m_expFactor = (m_bExpSighted) ? (delta > 1.0f) ? 1.0f : delta : (delta > 1.0f) ? 0.0f : 1.0f - delta; Vector difPos(vmorigin - eyePosition); vmorigin = eyePosition + (difPos * m_expFactor); SetLocalOrigin(vmorigin); SetLocalAngles(vmangles); #endif }_______________________________________________________________________________________________________ baseviewmodel_shared.h _______________________________________________________________________________________________________ Добавляем строки с поправкой //ADDED class CBaseViewModel : public CBaseAnimating { DECLARE_CLASS( CBaseViewModel, CBaseAnimating ); public: bool m_bExpSighted; //ADDED float m_expFactor; //ADDED DECLARE_NETWORKCLASS(); DECLARE_PREDICTABLE(); #if !defined( CLIENT_DLL ) DECLARE_DATADESC(); #endif_______________________________________________________________________________________________________ Всё.Компилируем. Теперь к скриптам.Менять будем weapon_pistol.txt Вписать где-нибудь в скрипт: ExpOffset { "x" "-10" "y" "-5.34" "z" "4.25" // "xori" "-2.9" //Does not work // "yori" "1.1" //Does not work // "zori" "2.0" // Does not work }
_______________________________________________________________________________________________________ Экстра Это не обязательно. Если вы считаете скорость передвижения пистолета слишком медленной, то давай не увеличим её! Ищем эту строку: float gIronsightedTime(0.0f); и дописываем снизу: float gMoveTime(0.1f); //Seconds to use to move the model up to players view Теперь топаем до float delta(gpGlobals->curtime - gIronsightedTime); и меняем на float delta((gpGlobals->curtime - gIronsightedTime) / gMoveTime); _______________________________________________________________________________________________________ Всё готово.Команда ironsight_toggle запускает и отключает(1/0) Ironsight.А изначальная кнопка - [ .
Источник: http://HL2World.com |