#include <amxmodx>
#include <engine>
#include <fakemeta>
#include <hamsandwich>
#define PLUGIN "Prize Knife"
#define VERSION "0.1"
#define AUTHOR "Safety1st"
/*---------------EDIT ME------------------*/
#define ACCESS_FLAG ADMIN_LEVEL_H // flag 't' by default
#define CUSTOM_DMG 2.0 // custom knife damage; fractional part of a number is mandatory
new const gszKnifeModelV[] = "models/s18/v_knife.mdl" // 1st person view model
new const gszKnifeModelP[] = "models/s18/p_knife.mdl" // 3rd person view model
/*----------------------------------------*/
new giszKnifeModelV, giszKnifeModelP
// macro; %1 - variable being modified, %2 - player id
#define CheckFlag(%1,%2) (%1 & (1 << (%2 & 31)))
#define SetFlag(%1,%2) (%1 |= (1 << (%2 & 31)))
#define ClearFlag(%1,%2) (%1 &= ~(1 << (%2 & 31)))
new gbCustomKnfDamage
#define IsPlayer(%0) ( 1 <= (%0) <= giMaxPlayers )
new giMaxPlayers
public plugin_init() {
register_plugin( PLUGIN, VERSION, AUTHOR )
RegisterHam( Ham_Item_Deploy, "weapon_knife" , "Fwd_ItemDeploy_Knife_Post", .Post = 1 )
RegisterHam( Ham_TakeDamage, "player", "Fwd_TakeDamage" )
giszKnifeModelV = engfunc( EngFunc_AllocString, gszKnifeModelV )
giszKnifeModelP = engfunc( EngFunc_AllocString, gszKnifeModelP )
giMaxPlayers = get_maxplayers()
}
public plugin_precache() {
precache_model( gszKnifeModelV )
precache_model( gszKnifeModelP )
}
public client_putinserver(id) {
get_user_flags(id) & ACCESS_FLAG ? SetFlag( gbCustomKnfDamage, id ) : ClearFlag( gbCustomKnfDamage, id )
}
public Fwd_ItemDeploy_Knife_Post( ent ) {
const XO_WEAPON = 4 // 'XO' means extraoffset
const m_pPlayer = 41
new iPlayer = get_pdata_cbase( ent, m_pPlayer, XO_WEAPON )
if( CheckFlag( gbCustomKnfDamage, iPlayer ) ) {
set_pev_string( iPlayer, pev_viewmodel2, giszKnifeModelV )
set_pev_string( iPlayer, pev_weaponmodel2, giszKnifeModelP )
}
}
public Fwd_TakeDamage( victim, inflictor, attacker, Float:damage, damagebits ) {
if( IsPlayer(attacker) && attacker == inflictor /* it is mandatory be4 checking current weapon (it could not be the same as one inflicting damage now) */
&& CheckFlag( gbCustomKnfDamage, attacker ) && get_user_weapon(attacker) == CSW_KNIFE ) {
SetHamParamFloat( 4, damage * CUSTOM_DMG )
return HAM_HANDLED
}
return HAM_IGNORED
}