Set Damage for Different Distance and Weapons
The goal is to set different damage for different weapons for different distances of attacker and victim.
PHP Code:
#include < amxmodx >
#include < hamsandwich >
#define SHORT_RANGE 150
#define MEDIUM_RANGE 1000
#define LONG_RANGE 2000
#define IsPlayer(%1) (1 <= %1 <= g_iMaxPlayers)
new g_iMaxPlayers
new g_s_AKdmg
public plugin_init()
{
register_plugin( "", "", "" )
RegisterHam( Ham_TakeDamage, "player", "ham_TakeDamage" )
g_s_AKdmg = register_cvar( "amx_aksdmg", "250" )
g_iMaxPlayers = get_maxplayers()
}
public ham_TakeDamage( victim, inflictor, attacker, Float:damage, damagebits )
{
if( !is_user_alive( victim ) || !is_user_connected( attacker ) || !IsPlayer( attacker ) )
return HAM_SUPERCEDE;
static iVOrigin[ 3 ], iAOrigin[ 3 ]
static iDistance
new iGun = get_user_weapon( attacker )
get_user_origin( victim, iVOrigin )
get_user_origin( attacker, iAOrigin )
iDistance = get_distance( iVOrigin, iAOrigin )
if( iDistance <= SHORT_RANGE )
{
switch( iGun )
{
case CSW_AK47:
{
damage = get_pcvar_float( g_s_AKdmg )
SetHamParamFloat( 4, damage )
}
// Do the same for other weapons
}
}
// Do the same for the other ranges..
return HAM_HANDLED;
}
Is there a better way to do it ?
|