Skip to content

Instantly share code, notes, and snippets.

@rsKliPPy
Last active August 29, 2015 14:18
Show Gist options
  • Save rsKliPPy/6a51886bece3e52c52d5 to your computer and use it in GitHub Desktop.
Save rsKliPPy/6a51886bece3e52c52d5 to your computer and use it in GitHub Desktop.
The code of my Death From Above plugin. Allows a player to kill (or at least damage) another player by falling on him.
#include <amxmodx>
#include <csx>
#include <hamsandwich>
#include <fakemeta>
#define PLUGIN "Death From Above"
#define VERSION "v1.1.0"
#define AUTHOR "KliPPy"
/*
Death ent's purpose is to change the death message in console, i.e:
PlayerName killed VictimName with worldspawn.
And print this instead:
PlayerName killed VictimName with falling.
This name is also going to be displayed in StatsX.
*/
new const DEATH_ENT_NAME[] = "falling";
new g_iDeathEnt = FM_NULLENT;
new g_pDamageDealt, g_pDamageTaken;
new g_iStatsWeapon;
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR);
g_pDamageDealt = register_cvar("dfa_damage_dealt", "2.0");
g_pDamageTaken = register_cvar("dfa_damage_taken", "1.0");
g_iStatsWeapon = custom_weapon_add(DEATH_ENT_NAME, true, DEATH_ENT_NAME);
RegisterHam(Ham_TakeDamage, "player", "CBasePlayer_TakeDamage", false);
g_iDeathEnt = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"));
if(!pev_valid(g_iDeathEnt))
{
pause("ad");
log_amx("The plugin has been paused because death entity couldn't be created.");
}
set_pev(g_iDeathEnt, pev_classname, DEATH_ENT_NAME);
}
public CBasePlayer_TakeDamage(iThis, iInflictor, iAttacker, Float: fDamage, bitsDamage)
{
if(!is_user_connected(iThis))
return HAM_IGNORED;
if(bitsDamage & DMG_FALL)
{
new iGroundEnt = pev(iThis, pev_groundentity);
if(is_user_alive(iGroundEnt) && get_user_team(iThis) != get_user_team(iGroundEnt))
{
fDamage *= get_pcvar_float(g_pDamageDealt);
ExecuteHamB(Ham_TakeDamage, iGroundEnt, g_iDeathEnt, iThis, fDamage, DMG_CRUSH);
custom_weapon_dmg(g_iStatsWeapon, iThis, iGroundEnt, floatround(fDamage), HIT_GENERIC);
custom_weapon_shot(g_iStatsWeapon, iThis);
SetHamParamFloat(4, fDamage * get_pcvar_float(g_pDamageTaken));
return HAM_HANDLED;
}
}
return HAM_IGNORED;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment