#include <amxmodx>
#include <fakemeta_util>
#include <hamsandwich>
#include <zombieplague>
#define PLUGIN "[ZP] Extra: CSO Dual Infinity EX2"
#define VERSION "1.0"
#define AUTHOR "KORD_12.7"
#pragma ctrlchar '\'
//**********************************************
//* Weapon Settings. *
//**********************************************
// Main
#define WEAPON_KEY 3028
#define WEAPON_NAME "weapon_mp7a1d_mpzs"
#define WEAPON_REFERANCE "weapon_p228"
#define WEAPON_MAX_CLIP 40
#define WEAPON_DEFAULT_AMMO 200
#define WEAPON_TIME_NEXT_IDLE 2.7
#define WEAPON_TIME_NEXT_ATTACK 0.15
#define WEAPON_TIME_DELAY_DEPLOY 1.5
#define WEAPON_TIME_DELAY_RELOAD 4.0
#define WEAPON_MULTIPLIER_DAMAGE 1.7
#define ZP_ITEM_NAME "Dinf"
#define ZP_ITEM_COST 0
// Models
#define MODEL_WORLD "models/mpzs/wpn/w_dmp7a1.mdl"
#define MODEL_VIEW "models/v_infinityex2.mdl"
#define MODEL_PLAYER "models/mpzs/wpn/p_dmp7a1.mdl"
#define MODEL_SHELL "models/rshell.mdl"
// Sounds
#define SOUND_FIRE "mpzs/wpn/dmp7-1.wav"
// Sprites
#define WEAPON_HUD_TXT "sprites/weapon_mp7a1d_mpzs.txt"
#define WEAPON_HUD_SPR_1 "sprites/mpzs/640hud21.spr"
#define WEAPON_HUD_SPR_2 "sprites/mpzs/640hud7.spr"
// Animation
#define ANIM_EXTENSION "dualpistols"
// Animation sequences
enum
{
ANIM_IDLE,
ANIM_IDLELEFTEMPTY,
ANIM_SHOOT_LEFT,
ANIM_SHOOT_LEFTLAST,
ANIM_SHOOT_RIGHT,
ANIM_SHOOT_RIGHTLAST,
ANIM_SP_SHOOT_LEFT1,
ANIM_SP_SHOOT_LEFT2,
ANIM_SP_SHOOT_RIGHT1,
ANIM_SP_SHOOT_RIGHT2,
ANIM_SP_SHOOT_LEFTLAST,
ANIM_SP_SHOOT_RIGHTLAST,
ANIM_RELOAD,
ANIM_DRAW
};
//**********************************************
//* Some macroses. *
//**********************************************
#define MDLL_Spawn(%0) dllfunc(DLLFunc_Spawn, %0)
#define MDLL_Touch(%0,%1) dllfunc(DLLFunc_Touch, %0, %1)
#define MDLL_USE(%0,%1) dllfunc(DLLFunc_Use, %0, %1)
#define SET_MODEL(%0,%1) engfunc(EngFunc_SetModel, %0, %1)
#define SET_ORIGIN(%0,%1) engfunc(EngFunc_SetOrigin, %0, %1)
#define PRECACHE_MODEL(%0) engfunc(EngFunc_PrecacheModel, %0)
#define PRECACHE_SOUND(%0) engfunc(EngFunc_PrecacheSound, %0)
#define PRECACHE_GENERIC(%0) engfunc(EngFunc_PrecacheGeneric, %0)
#define MESSAGE_BEGIN(%0,%1,%2,%3) engfunc(EngFunc_MessageBegin, %0, %1, %2, %3)
#define MESSAGE_END() message_end()
#define WRITE_ANGLE(%0) engfunc(EngFunc_WriteAngle, %0)
#define WRITE_BYTE(%0) write_byte(%0)
#define WRITE_COORD(%0) engfunc(EngFunc_WriteCoord, %0)
#define WRITE_STRING(%0) write_string(%0)
#define WRITE_SHORT(%0) write_short(%0)
#define INSTANCE(%0) ((%0 == -1) ? 0 : %0)
#define BitSet(%0,%1) (%0 |= (1 << (%1 - 1)))
#define BitClear(%0,%1) (%0 &= ~(1 << (%1 - 1)))
#define BitCheck(%0,%1) (%0 & (1 << (%1 - 1)))
//**********************************************
//* PvData Offsets. *
//**********************************************
// Linux extra offsets
#define extra_offset_weapon 4
#define extra_offset_player 5
new g_bitIsConnected;
#define m_rgpPlayerItems_CWeaponBox 34
// CBasePlayerItem
#define m_pPlayer 41
#define m_pNext 42
#define m_iId 43
// CBasePlayerWeapon
#define m_flNextPrimaryAttack 46
#define m_flNextSecondaryAttack 47
#define m_flTimeWeaponIdle 48
#define m_iPrimaryAmmoType 49
#define m_iClip 51
#define m_fInReload 54
#define m_iChargeReady 55
#define m_flAccuracy 62
#define m_iShotsFired 64
#define m_fWeaponState 74
#define m_iLastZoom 109
// CBaseMonster
#define m_flNextAttack 83
// CBasePlayer
#define m_fResumeZoom 110
#define m_iFOV 363
#define m_rgpPlayerItems_CBasePlayer 367
#define m_pActiveItem 373
#define m_rgAmmo_CBasePlayer 376
#define m_szAnimExtention 492
#define IsValidPev(%0) (pev_valid(%0) == 2)
//**********************************************
//* Let's code our weapon. *
//**********************************************
Weapon_OnPrecache()
{
PRECACHE_MODEL(MODEL_WORLD)
PRECACHE_MODEL(MODEL_VIEW);
PRECACHE_MODEL(MODEL_PLAYER);
PRECACHE_MODEL(MODEL_SHELL);
PRECACHE_SOUND(SOUND_FIRE);
PRECACHE_SOUND("mpzs/wpn/dmp7_draw.wav");
PRECACHE_SOUND("mpzs/wpn/dmp7_drop.wav");
PRECACHE_SOUND("mpzs/wpn/mp7_foley2.wav");
PRECACHE_SOUND("mpzs/wpn/mp7_foley4.wav");
PRECACHE_GENERIC(WEAPON_HUD_TXT);
PRECACHE_GENERIC(WEAPON_HUD_SPR_1);
PRECACHE_GENERIC(WEAPON_HUD_SPR_2);
}
Weapon_OnSpawn(const iItem)
{
// Setting world model.
SET_MODEL(iItem, MODEL_WORLD);
}
Weapon_OnDeploy(const iItem, const iPlayer, const iClip, const iAmmoPrimary)
{
#pragma unused iClip, iAmmoPrimary
static iszViewModel;
if (iszViewModel || (iszViewModel = engfunc(EngFunc_AllocString, MODEL_VIEW)))
{
set_pev_string(iPlayer, pev_viewmodel2, iszViewModel);
}
static iszPlayerModel;
if (iszPlayerModel || (iszPlayerModel = engfunc(EngFunc_AllocString, MODEL_PLAYER)))
{
set_pev_string(iPlayer, pev_weaponmodel2, iszPlayerModel);
}
// Cancel any reload in progress.
set_pdata_int(iItem, m_fInReload, 0, extra_offset_weapon);
set_pdata_int(iItem, m_iChargeReady, 0, extra_offset_weapon);
set_pdata_string(iPlayer, m_szAnimExtention * 4, ANIM_EXTENSION, -1, extra_offset_player * 4);
set_pdata_float(iItem, m_flTimeWeaponIdle, WEAPON_TIME_DELAY_DEPLOY, extra_offset_weapon);
set_pdata_float(iPlayer, m_flNextAttack, WEAPON_TIME_DELAY_DEPLOY, extra_offset_player);
// Deploy with default weapon settings
Weapon_DefaultDeploy(iPlayer, MODEL_VIEW, MODEL_PLAYER, ANIM_DRAW, ANIM_EXTENSION);
}
Weapon_OnHolster(const iItem, const iPlayer, const iClip, const iAmmoPrimary)
{
#pragma unused iPlayer, iClip, iAmmoPrimary
// Cancel any reload in progress.
set_pdata_int(iItem, m_fInReload, 0, extra_offset_weapon);
}
Weapon_OnIdle(const iItem, const iPlayer, const iClip, const iAmmoPrimary)
{
#pragma unused iClip, iAmmoPrimary
ExecuteHamB(Ham_Weapon_ResetEmptySound, iItem);
if (get_pdata_float(iItem, m_flTimeWeaponIdle, extra_offset_weapon) > 0.0)
{
return;
}
set_pdata_float(iItem, m_flTimeWeaponIdle, WEAPON_TIME_NEXT_IDLE, extra_offset_weapon);
Weapon_SendAnim(iPlayer, !iClip ? ANIM_IDLELEFTEMPTY : ANIM_IDLE);
}
Weapon_OnReload(const iItem, const iPlayer, const iClip, const iAmmoPrimary)
{
if (min(WEAPON_MAX_CLIP - iClip, iAmmoPrimary) <= 0)
{
return;
}
set_pdata_int(iItem, m_iClip, 0, extra_offset_weapon);
ExecuteHam(Ham_Weapon_Reload, iItem);
set_pdata_int(iItem, m_iClip, iClip, extra_offset_weapon);
set_pdata_float(iPlayer, m_flNextAttack, WEAPON_TIME_DELAY_RELOAD, extra_offset_player);
set_pdata_float(iItem, m_flTimeWeaponIdle, WEAPON_TIME_DELAY_RELOAD, extra_offset_weapon);
Weapon_SendAnim(iPlayer, ANIM_RELOAD);
}
Weapon_OnPrimaryAttack(const iItem, const iPlayer, const iClip, const iAmmoPrimary)
{
#pragma unused iAmmoPrimary
new iShotsFired = get_pdata_int(iItem, m_iShotsFired, extra_offset_weapon);
if(iShotsFired > 0)
{
return;
}
CallOrigFireBullets3(iItem, iPlayer)
if (iClip <= 0)
{
return;
}
static iFlags, iAnimDesired, iShellModelIndex;
static szAnimation[64];iFlags = pev(iPlayer, pev_flags);
emit_sound(iPlayer, CHAN_WEAPON, SOUND_FIRE, VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
#define WEAPONSTATE_ELITE_LEFT (1 << 3)
if (!iShellModelIndex)
{
iShellModelIndex = PRECACHE_MODEL(MODEL_SHELL);
}
static iWeaponState; iWeaponState = get_pdata_int(iItem, m_fWeaponState, extra_offset_weapon);
if (iWeaponState & WEAPONSTATE_ELITE_LEFT)
{
iWeaponState &= ~ WEAPONSTATE_ELITE_LEFT;
Weapon_SendAnim(iPlayer, iClip == 2 ? ANIM_SHOOT_RIGHTLAST:ANIM_SHOOT_RIGHT);
EjectBrass(iPlayer, iShellModelIndex, 1, .flForwardScale = 9.0);
formatex(szAnimation, charsmax(szAnimation), "ref_shoot_%s", ANIM_EXTENSION);
}
else
{
iWeaponState |= WEAPONSTATE_ELITE_LEFT;
Weapon_SendAnim(iPlayer, iClip == 1 ? ANIM_SHOOT_LEFTLAST:ANIM_SHOOT_LEFT)
EjectBrass(iPlayer, iShellModelIndex, 1, .flForwardScale = 14.0, .flRightScale = -16.0);
formatex(szAnimation, charsmax(szAnimation), "ref_shoot2_%s", ANIM_EXTENSION);
}
formatex(szAnimation, charsmax(szAnimation), iFlags & FL_DUCKING ? "crouch_shoot_%s" : "ref_shoot_%s", ANIM_EXTENSION);
if ((iAnimDesired = lookup_sequence(iPlayer, szAnimation)) == -1)
{
iAnimDesired = 0;
}
set_pev(iPlayer, pev_sequence, iAnimDesired);
PunchAxis(iPlayer, -1.0, 0.3)
set_pdata_float(iItem, m_flAccuracy, 0.8 ,extra_offset_weapon)
set_pdata_float(iItem, m_flNextPrimaryAttack, WEAPON_TIME_NEXT_ATTACK, extra_offset_weapon);
set_pdata_float(iItem, m_flTimeWeaponIdle, WEAPON_TIME_NEXT_ATTACK+2.0, extra_offset_weapon);
set_pdata_int(iItem, m_fWeaponState, iWeaponState, extra_offset_weapon);
set_pdata_int(iItem, m_iClip, iClip-1, extra_offset_weapon);
}
Weapon_OnSecondaryAttack(const iItem, const iPlayer, const iClip)
{
static iButton;iButton = pev(iPlayer, pev_button);
if (get_pdata_float(iItem, m_flNextPrimaryAttack, extra_offset_weapon) > 0.0)
{
return;
}
if (iButton & IN_ATTACK2)
{
if (iClip <= 0)
{
return;
}
CallOrigFireBullets3(iItem, iPlayer)
static iFlags, iAnimDesired, iShellModelIndex;
static szAnimation[64];iFlags = pev(iPlayer, pev_flags);
emit_sound(iPlayer, CHAN_WEAPON, SOUND_FIRE, VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
#define WEAPONSTATE_ELITE_LEFT (1 << 3)
if (!iShellModelIndex)
{
iShellModelIndex = PRECACHE_MODEL(MODEL_SHELL);
}
static iWeaponState; iWeaponState = get_pdata_int(iItem, m_fWeaponState, extra_offset_weapon);
static iWeaponLeft; iWeaponLeft = get_pdata_int(iItem, m_iChargeReady, extra_offset_weapon);
switch (iWeaponLeft)
{
case 0:
{
if (iWeaponState & WEAPONSTATE_ELITE_LEFT)
{
iWeaponState &= ~ WEAPONSTATE_ELITE_LEFT;
Weapon_SendAnim(iPlayer, iClip == 2 ? ANIM_SP_SHOOT_LEFTLAST:ANIM_SP_SHOOT_LEFT1);
EjectBrass(iPlayer, iShellModelIndex, 1, .flForwardScale = 9.0);
formatex(szAnimation, charsmax(szAnimation), "ref_shoot_%s", ANIM_EXTENSION);
}
else
{
iWeaponState |= WEAPONSTATE_ELITE_LEFT;
Weapon_SendAnim(iPlayer, iClip == 1 ? ANIM_SP_SHOOT_RIGHTLAST:ANIM_SP_SHOOT_RIGHT1)
EjectBrass(iPlayer, iShellModelIndex, 1, .flForwardScale = 14.0, .flRightScale = -16.0);
formatex(szAnimation, charsmax(szAnimation), "ref_shoot2_%s", ANIM_EXTENSION);
}
set_pdata_int(iItem, m_iChargeReady, 1, extra_offset_weapon);
}
case 1:
{
if (iWeaponState & WEAPONSTATE_ELITE_LEFT)
{
iWeaponState &= ~ WEAPONSTATE_ELITE_LEFT;
Weapon_SendAnim(iPlayer, iClip == 2 ? ANIM_SP_SHOOT_LEFTLAST:ANIM_SP_SHOOT_LEFT2);
EjectBrass(iPlayer, iShellModelIndex, 1, .flForwardScale = 9.0);
formatex(szAnimation, charsmax(szAnimation), "ref_shoot_%s", ANIM_EXTENSION);
}
else
{
iWeaponState |= WEAPONSTATE_ELITE_LEFT;
Weapon_SendAnim(iPlayer, iClip == 1 ? ANIM_SP_SHOOT_RIGHTLAST:ANIM_SP_SHOOT_RIGHT2)
EjectBrass(iPlayer, iShellModelIndex, 1, .flForwardScale = 14.0, .flRightScale = -16.0);
formatex(szAnimation, charsmax(szAnimation), "ref_shoot2_%s", ANIM_EXTENSION);
}
set_pdata_int(iItem, m_iChargeReady, 0, extra_offset_weapon);
}
}
formatex(szAnimation, charsmax(szAnimation), iFlags & FL_DUCKING ? "crouch_shoot_%s" : "ref_shoot_%s", ANIM_EXTENSION);
if ((iAnimDesired = lookup_sequence(iPlayer, szAnimation)) == -1)
{
iAnimDesired = 0;
}
set_pev(iPlayer, pev_sequence, iAnimDesired);
PunchAxis(iPlayer, -1.0, 0.3)
set_pdata_float(iItem, m_flAccuracy, 0.8 ,extra_offset_weapon)
set_pdata_float(iItem, m_flNextPrimaryAttack, WEAPON_TIME_NEXT_ATTACK, extra_offset_weapon);
set_pdata_float(iItem, m_flTimeWeaponIdle, WEAPON_TIME_NEXT_ATTACK+2.0, extra_offset_weapon);
set_pdata_int(iItem, m_fWeaponState, iWeaponState, extra_offset_weapon);
set_pdata_int(iItem, m_iClip, iClip-1, extra_offset_weapon);
}
}
//*********************************************************************
//* Don't modify the code below this line unless *
//* you know _exactly_ what you are doing!!! *
//*********************************************************************
#define MSGID_WEAPONLIST 78
new g_iItemID;
#define IsCustomItem(%0) (pev(%0, pev_impulse) == WEAPON_KEY)
public plugin_precache()
{
Weapon_OnPrecache();
register_clcmd(WEAPON_NAME, "Cmd_WeaponSelect");
register_message(MSGID_WEAPONLIST, "MsgHook_WeaponList");
}
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR);
register_forward(FM_PlaybackEvent, "FakeMeta_PlaybackEvent", false);
register_forward(FM_SetModel, "FakeMeta_SetModel", false);
register_forward(FM_UpdateClientData, "FakeMeta_UpdateClientData_Post",true);
// Weaponbox
RegisterHam(Ham_Spawn, "weaponbox", "HamHook_Weaponbox_Spawn_Post", true);
// Hook and change damage to entities
RegisterHam(Ham_TraceAttack, "func_breakable", "HamHook_Entity_TraceAttack", false);
RegisterHam(Ham_TraceAttack, "info_target", "HamHook_Entity_TraceAttack", false);
RegisterHam(Ham_TraceAttack, "player", "HamHook_Entity_TraceAttack", false);
// Item (weapon) hooks
RegisterHam(Ham_Item_Deploy, WEAPON_REFERANCE, "HamHook_Item_Deploy_Post", true);
RegisterHam(Ham_Item_Holster, WEAPON_REFERANCE, "HamHook_Item_Holster", false);
RegisterHam(Ham_Item_AddToPlayer, WEAPON_REFERANCE, "HamHook_Item_AddToPlayer", false);
RegisterHam(Ham_Item_PostFrame, WEAPON_REFERANCE, "HamHook_Item_PostFrame", false);
RegisterHam(Ham_Weapon_Reload, WEAPON_REFERANCE, "HamHook_Item_Reload", false);
RegisterHam(Ham_Weapon_WeaponIdle, WEAPON_REFERANCE, "HamHook_Item_WeaponIdle", false);
RegisterHam(Ham_Weapon_PrimaryAttack, WEAPON_REFERANCE, "HamHook_Item_PrimaryAttack", false);
g_iItemID = zp_register_extra_item(ZP_ITEM_NAME, ZP_ITEM_COST, ZP_TEAM_HUMAN);
}
public zp_extra_item_selected(id, itemid)
{
if (itemid == g_iItemID)
{
Weapon_Give(id);
}
}
public plugin_natives()
{
register_native("GetMP7A1Dual", "NativeGiveWeapon", true);
register_native("CheckItemMP7A1Dual", "CheckItem2", true);
}
public NativeGiveWeapon(iPlayer)
{
Weapon_Give(iPlayer);
}
public CheckItem2(iItem, iPlayer)
{
if (!CheckItem(iItem, iPlayer))
{
return 0;
}
return 1;
}
//**********************************************
//* Block client weapon. *
//**********************************************
public FakeMeta_UpdateClientData_Post(const iPlayer, const iSendWeapons, const CD_Handle)
{
static iActiveItem;iActiveItem = get_pdata_cbase(iPlayer, m_pActiveItem, extra_offset_player);
if (!IsValidPev(iActiveItem) || !IsCustomItem(iActiveItem))
{
return FMRES_IGNORED;
}
set_cd(CD_Handle, CD_flNextAttack, get_gametime() + 0.001);
return FMRES_IGNORED;
}
//**********************************************
//* Item (weapon) hooks. *
//**********************************************
#define _call.%0(%1,%2) \
\
Weapon_On%0 \
( \
%1, \
%2, \
\
get_pdata_int(%1, m_iClip, extra_offset_weapon), \
\
GetAmmoInventory(%2, PrimaryAmmoIndex(%1)) \
)
public HamHook_Item_Deploy_Post(const iItem)
{
new iPlayer;
if (!CheckItem(iItem, iPlayer))
{
return HAM_IGNORED;
}
_call.Deploy(iItem, iPlayer);
return HAM_IGNORED;
}
public HamHook_Item_Holster(const iItem)
{
new iPlayer;
if (!CheckItem(iItem, iPlayer))
{
return HAM_IGNORED;
}
set_pev(iPlayer, pev_viewmodel, 0);
set_pev(iPlayer, pev_weaponmodel, 0);
_call.Holster(iItem, iPlayer);
return HAM_SUPERCEDE;
}
public HamHook_Item_WeaponIdle(const iItem)
{
static iPlayer;
if (!CheckItem(iItem, iPlayer))
{
return HAM_IGNORED;
}
_call.Idle(iItem, iPlayer);
return HAM_SUPERCEDE;
}
public HamHook_Item_Reload(const iItem)
{
static iPlayer;
if (!CheckItem(iItem, iPlayer))
{
return HAM_IGNORED;
}
_call.Reload(iItem, iPlayer);
return HAM_SUPERCEDE;
}
public HamHook_Item_PrimaryAttack(const iItem)
{
static iPlayer;
if (!CheckItem(iItem, iPlayer))
{
return HAM_IGNORED;
}
_call.PrimaryAttack(iItem, iPlayer);
return HAM_SUPERCEDE;
}
public HamHook_Item_PostFrame(const iItem)
{
static iPlayer;
if (!CheckItem(iItem, iPlayer))
{
return HAM_IGNORED;
}
new iClip = get_pdata_int(iItem, m_iClip, extra_offset_weapon);
// Complete reload
if (get_pdata_int(iItem, m_fInReload, extra_offset_weapon))
{
new iClip = get_pdata_int(iItem, m_iClip, extra_offset_weapon);
new iPrimaryAmmoIndex = PrimaryAmmoIndex(iItem);
new iAmmoPrimary = GetAmmoInventory(iPlayer, iPrimaryAmmoIndex);
new iAmount = min(WEAPON_MAX_CLIP - iClip, iAmmoPrimary);
set_pdata_int(iItem, m_iClip, iClip + iAmount, extra_offset_weapon);
set_pdata_int(iItem, m_fInReload, false, extra_offset_weapon);
SetAmmoInventory(iPlayer, iPrimaryAmmoIndex, iAmmoPrimary - iAmount);
}
Weapon_OnSecondaryAttack(iItem, iPlayer, iClip);
return HAM_IGNORED;
}
//**********************************************
//* Fire Bullets. *
//**********************************************
CallOrigFireBullets3(const iItem, const iPlayer)
{
static fm_hooktrace;fm_hooktrace=register_forward(FM_TraceLine,"FakeMeta_TraceLine",true)
state FireBullets: Enabled;
static Float: vecPuncheAngle[3];
pev(iPlayer, pev_punchangle, vecPuncheAngle);
ExecuteHam(Ham_Weapon_PrimaryAttack, iItem);
set_pev(iPlayer, pev_punchangle, vecPuncheAngle);
state FireBullets: Disabled;
unregister_forward(FM_TraceLine,fm_hooktrace,true)
}
public FakeMeta_PlaybackEvent() <FireBullets: Enabled>
{
return FMRES_SUPERCEDE;
}
public FakeMeta_TraceLine(Float:Tr_Start[3], Float:Tr_End[3], Tr_Flag, Tr_Ignore, iTrase)
{
if(Tr_Flag&IGNORE_MONSTERS)
{
return FMRES_IGNORED;
}
static Float:vecEnd[3];
static iHit;
static Decal;
static glassdecal;
if(!glassdecal)
{
glassdecal=engfunc( EngFunc_DecalIndex, "{bproof1" )
}
iHit=get_tr2(iTrase,TR_pHit)
if(iHit>0 && pev_valid(iHit))
if(pev(iHit,pev_solid)!=SOLID_BSP)return FMRES_IGNORED
else if(pev(iHit,pev_rendermode)!=0)Decal=glassdecal
else Decal=random_num(41,45)
else Decal=random_num(41,45)
get_tr2(iTrase, TR_vecEndPos, vecEnd)
engfunc(EngFunc_MessageBegin, MSG_PAS, SVC_TEMPENTITY, vecEnd, 0)
write_byte(TE_GUNSHOTDECAL)
WRITE_COORD(vecEnd[0])
WRITE_COORD(vecEnd[1])
WRITE_COORD(vecEnd[2])
write_short(iHit > 0 ? iHit : 0)
write_byte(Decal)
message_end()
return FMRES_IGNORED
}
public HamHook_Entity_TraceAttack(const iEntity, const iAttacker, const Float: flDamage) <FireBullets: Enabled>
{
SetHamParamFloat(3, flDamage * WEAPON_MULTIPLIER_DAMAGE);
}
public MsgHook_Death() </* Empty statement */> { /* Fallback */ }
public MsgHook_Death() <FireBullets: Disabled> { /* Do notning */ }
public FakeMeta_PlaybackEvent() </* Empty statement */> { return FMRES_IGNORED; }
public FakeMeta_PlaybackEvent() <FireBullets: Disabled> { return FMRES_IGNORED; }
public HamHook_Entity_TraceAttack() </* Empty statement */> { /* Fallback */ }
public HamHook_Entity_TraceAttack() <FireBullets: Disabled> { /* Do notning */ }
EjectBrass(const iPlayer, const iModelIndex, const iBounce, const Float:flUpScale = -9.0, const Float: flForwardScale = 16.0, const Float: flRightScale = 0.0)
{
static i, msgBrass;
static Float: vecUp[3];
static Float: vecRight[3];
static Float: vecForward[3];
static Float: vecAngle[3];
static Float: vecOrigin[3];
static Float: vecViewOfs[3];
static Float: vecVelocity[3];
pev(iPlayer, pev_v_angle, vecAngle);
pev(iPlayer, pev_punchangle, vecOrigin);
xs_vec_add(vecAngle, vecOrigin, vecOrigin);
engfunc(EngFunc_MakeVectors, vecOrigin);
pev(iPlayer, pev_origin, vecOrigin);
pev(iPlayer, pev_view_ofs, vecViewOfs);
pev(iPlayer, pev_velocity, vecVelocity);
global_get(glb_v_up, vecUp);
global_get(glb_v_right, vecRight);
global_get(glb_v_forward, vecForward);
for (i = 0; i < 3; i++)
{
vecOrigin[i] = vecOrigin[i] + vecViewOfs[i] + vecForward[i] * flForwardScale + vecUp[i] * flUpScale + vecRight[i] * flRightScale;
vecVelocity[i] = vecVelocity[i] + vecForward[i] * 25.0 + vecUp[i] * random_float(100.0, 150.0) + vecRight[i] * random_float(50.0, 70.0);
}
if (msgBrass || (msgBrass = get_user_msgid("Brass")))
{
MESSAGE_BEGIN(MSG_PVS, msgBrass, vecOrigin, 0);
WRITE_BYTE(0 /* dummy */);
WRITE_COORD(vecOrigin[0]);
WRITE_COORD(vecOrigin[1]);
WRITE_COORD(vecOrigin[2]);
WRITE_COORD(0.0 /* dummy */);
WRITE_COORD(0.0 /* dummy */);
WRITE_COORD(0.0 /* dummy */);
WRITE_COORD(vecVelocity[0]);
WRITE_COORD(vecVelocity[1]);
WRITE_COORD(vecVelocity[2]);
WRITE_ANGLE(vecAngle[1]);
WRITE_SHORT(iModelIndex);
WRITE_BYTE(iBounce);
WRITE_BYTE(0 /* dummy */);
WRITE_BYTE(iPlayer);
MESSAGE_END();
}
}
Weapon_Create(const Float: vecOrigin[3] = {0.0, 0.0, 0.0}, const Float: vecAngles[3] = {0.0, 0.0, 0.0})
{
new iWeapon;
static iszAllocStringCached;
if (iszAllocStringCached || (iszAllocStringCached = engfunc(EngFunc_AllocString, WEAPON_REFERANCE)))
{
iWeapon = engfunc(EngFunc_CreateNamedEntity, iszAllocStringCached);
}
if (!IsValidPev(iWeapon))
{
return FM_NULLENT;
}
MDLL_Spawn(iWeapon);
SET_ORIGIN(iWeapon, vecOrigin);
set_pdata_int(iWeapon, m_iClip, WEAPON_MAX_CLIP, extra_offset_weapon);
set_pev(iWeapon, pev_impulse, WEAPON_KEY);
set_pev(iWeapon, pev_angles, vecAngles);
Weapon_OnSpawn(iWeapon);
return iWeapon;
}
Weapon_Give(const iPlayer)
{
if (!IsValidPev(iPlayer))
{
return FM_NULLENT;
}
new iWeapon, Float: vecOrigin[3];
pev(iPlayer, pev_origin, vecOrigin);
if ((iWeapon = Weapon_Create(vecOrigin)) != FM_NULLENT)
{
Player_DropWeapons(iPlayer, ExecuteHamB(Ham_Item_ItemSlot, iWeapon));
set_pev(iWeapon, pev_spawnflags, pev(iWeapon, pev_spawnflags) | SF_NORESPAWN);
MDLL_Touch(iWeapon, iPlayer);
SetAmmoInventory(iPlayer, PrimaryAmmoIndex(iWeapon), WEAPON_DEFAULT_AMMO);
return iWeapon;
}
return FM_NULLENT;
}
Player_DropWeapons(const iPlayer, const iSlot)
{
new szWeaponName[32], iItem = get_pdata_cbase(iPlayer, m_rgpPlayerItems_CBasePlayer + iSlot, extra_offset_player);
while (IsValidPev(iItem))
{
pev(iItem, pev_classname, szWeaponName, charsmax(szWeaponName));
engclient_cmd(iPlayer, "drop", szWeaponName);
iItem = get_pdata_cbase(iItem, m_pNext, extra_offset_weapon);
}
}
Weapon_SendAnim(const iPlayer, const iAnim)
{
set_pev(iPlayer, pev_weaponanim, iAnim);
MESSAGE_BEGIN(MSG_ONE_UNRELIABLE, SVC_WEAPONANIM, {0.0, 0.0, 0.0}, iPlayer);
WRITE_BYTE(iAnim);
WRITE_BYTE(0);
MESSAGE_END();
}
stock Weapon_DefaultDeploy(const iPlayer, const szViewModel[], const szWeaponModel[], const iAnim, const szAnimExt[])
{
set_pev(iPlayer, pev_viewmodel2, szViewModel);
set_pev(iPlayer, pev_weaponmodel2, szWeaponModel);
set_pev(iPlayer, pev_fov, 90.0);
set_pdata_int(iPlayer, m_iFOV, 90, extra_offset_player);
set_pdata_int(iPlayer, m_fResumeZoom, 0, extra_offset_player);
set_pdata_int(iPlayer, m_iLastZoom, 90, extra_offset_player);
set_pdata_string(iPlayer, m_szAnimExtention * 4, szAnimExt, -1, extra_offset_player * 4);
Weapon_SendAnim(iPlayer, iAnim);
}
stock PunchAxis(id, Float:x, Float:y, Float:x_min = -100.0, Float:y_min = -100.0)
{
new Float:vec[3];pev(id, pev_punchangle, vec);vec[0] += x;vec[1] += y;
vec[0] = vec[0] < x_min ? x_min : vec[0];vec[0] = vec[0] > -x_min ? -x_min : vec[0];
vec[1] = vec[1] < y_min ? y_min : vec[1];vec[1] = vec[1] > -y_min ? -y_min : vec[1];
set_pev(id, pev_punchangle, vec);
}
stock StripWeapon(iPlayer, iSlot)
{
static iEntity; iEntity = get_pdata_cbase(iPlayer, m_rgpPlayerItems_CBasePlayer + iSlot, 5);
if (iEntity > 0)
{
static iNext, iId;
do
{
iNext = get_pdata_cbase(iEntity, m_pNext, 4);
iId = get_pdata_int(iEntity, m_iId, 4);
if (get_user_weapon(iPlayer) == iId) ExecuteHamB(Ham_Weapon_RetireWeapon, iEntity);
ExecuteHamB(Ham_RemovePlayerItem, iPlayer, iEntity);
ExecuteHamB(Ham_Item_Kill, iEntity);
set_pev(iPlayer, pev_weapons, pev(iPlayer, pev_weapons) & ~(1<<iId));
}
while(( iEntity = iNext) > 0);
}
}
#define BitSet(%0,%1) (%0 |= (1 << (%1 - 1)))
#define BitClear(%0,%1) (%0 &= ~(1 << (%1 - 1)))
#define BitCheck(%0,%1) (%0 & (1 << (%1 - 1)))
public client_putinserver(id)
{
BitSet(g_bitIsConnected, id);
}
public client_disconnected(id)
{
BitClear(g_bitIsConnected, id);
}
bool: CheckItem(const iItem, &iPlayer)
{
if (!IsValidPev(iItem) || !IsCustomItem(iItem))
{
return false;
}
iPlayer = get_pdata_cbase(iItem, m_pPlayer, extra_offset_weapon);
if (!IsValidPev(iPlayer) || !BitCheck(g_bitIsConnected, iPlayer))
{
return false;
}
return true;
}
//**********************************************
//* Weapon list update. *
//**********************************************
public Cmd_WeaponSelect(const iPlayer)
{
engclient_cmd(iPlayer, WEAPON_REFERANCE);
return PLUGIN_HANDLED;
}
public HamHook_Item_AddToPlayer(const iItem, const iPlayer)
{
switch(pev(iItem, pev_impulse))
{
case 0: MsgHook_WeaponList(MSGID_WEAPONLIST, iItem, iPlayer);
case WEAPON_KEY:
{
MsgHook_WeaponList(MSGID_WEAPONLIST, iItem, iPlayer);
SetAmmoInventory(iPlayer, PrimaryAmmoIndex(iItem), pev(iItem, pev_iuser2));
}
}
return HAM_IGNORED;
}
public MsgHook_WeaponList(const iMsgID, const iMsgDest, const iMsgEntity)
{
static arrWeaponListData[8];
if (!iMsgEntity)
{
new szWeaponName[32];
get_msg_arg_string(1, szWeaponName, charsmax(szWeaponName));
if (!strcmp(szWeaponName, WEAPON_REFERANCE))
{
for (new i, a = sizeof arrWeaponListData; i < a; i++)
{
arrWeaponListData[i] = get_msg_arg_int(i + 2);
}
}
}
else
{
if (!IsCustomItem(iMsgDest) && pev(iMsgDest, pev_impulse))
{
return;
}
MESSAGE_BEGIN(MSG_ONE, iMsgID, {0.0, 0.0, 0.0}, iMsgEntity);
WRITE_STRING(IsCustomItem(iMsgDest) ? WEAPON_NAME : WEAPON_REFERANCE);
for (new i, a = sizeof arrWeaponListData; i < a; i++)
{
WRITE_BYTE(arrWeaponListData[i]);
}
MESSAGE_END();
}
}
//**********************************************
//* Weaponbox world model. *
//**********************************************
public HamHook_Weaponbox_Spawn_Post(const iWeaponBox)
{
if (IsValidPev(iWeaponBox))
{
state (IsValidPev(pev(iWeaponBox, pev_owner))) WeaponBox: Enabled;
}
return HAM_IGNORED;
}
public FakeMeta_SetModel(const iEntity) <WeaponBox: Enabled>
{
state WeaponBox: Disabled;
if (!IsValidPev(iEntity))
{
return FMRES_IGNORED;
}
#define MAX_ITEM_TYPES 6
for (new i, iItem; i < MAX_ITEM_TYPES; i++)
{
iItem = get_pdata_cbase(iEntity, m_rgpPlayerItems_CWeaponBox + i, extra_offset_weapon);
if (IsValidPev(iItem) && IsCustomItem(iItem))
{
SET_MODEL(iEntity, MODEL_WORLD);
set_pev(iItem, pev_iuser2, GetAmmoInventory(pev(iEntity,pev_owner), PrimaryAmmoIndex(iItem)))
return FMRES_SUPERCEDE;
}
}
return FMRES_IGNORED;
}
public FakeMeta_SetModel() </* Empty statement */> { /* Fallback */ return FMRES_IGNORED; }
public FakeMeta_SetModel() < WeaponBox: Disabled > { /* Do nothing */ return FMRES_IGNORED; }
//**********************************************
//* Ammo Inventory. *
//**********************************************
PrimaryAmmoIndex(const iItem)
{
return get_pdata_int(iItem, m_iPrimaryAmmoType, extra_offset_weapon);
}
GetAmmoInventory(const iPlayer, const iAmmoIndex)
{
if (iAmmoIndex == -1)
{
return -1;
}
return get_pdata_int(iPlayer, m_rgAmmo_CBasePlayer + iAmmoIndex, extra_offset_player);
}
SetAmmoInventory(const iPlayer, const iAmmoIndex, const iAmount)
{
if (iAmmoIndex == -1)
{
return 0;
}
set_pdata_int(iPlayer, m_rgAmmo_CBasePlayer + iAmmoIndex, iAmount, extra_offset_player);
return 1;
}