PDA

View Full Version : Damage control


Dr.G
03-23-2009, 05:04 PM
Iam a bit in doubt if these tuts are for any use around here since the activity seems lower and lower and the developer staff is down to 2 or so... But what i will show is how you can control diffrent damage types. The damage types can be found in $moddir\addons\amxmodx\scripting\include\hlsdk_con st.inc

This is a quick example how to control fire damage done to a player, and a simple way to adjust it in percent:


/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>

#define PLUGIN "Damage Control"
#define VERSION "1.0"
#define AUTHOR "Dr.G"

new p_percent

public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)

/* Ham_TakeDamage */
RegisterHam(Ham_TakeDamage, "player", "func_TakeDamage")
/* *1 *2 *3

*1 - Register an entity take damage = Ham_TakeDamage
*2 - Entity named: player
*3 - Function to forward to: func_TakeDamage */

/*
this cvar we can use for controling the amout of damage in PERCENT. So 50 will be half
damage. 100 will be normal etc...
*/
p_percent = register_cvar("test_dmgc", "50")
}

public func_TakeDamage(id, idinflictor, idattacker, Float:damage, damagebits)
{
if( is_user_alive(id) && get_user_team(id) && (damagebits & DMG_BURN)) /* note its the damage type that matters! */
{
damage = float(floatround(get_pcvar_float(p_percent) / 100 * damage))

SetHamParamFloat(4,damage)

client_print(id,3,"fire dmg??")
return HAM_HANDLED
}
return HAM_IGNORED
}

Download the source file and take a look in it, it might give you a better view on this. Also check the notes in the code...

Another example where it can be very use full is DMG_FALL. Ive made a plugin to control it on my own server it goes like this:

////////////////////////////////////////////////////////////////////////////////////////////////////
/*
info:

this plugin allows you to control fall damage. note that this plugin by default is set to reduce the
amount of damage. damage is set in % so 100 is normal, and 50 % is half of normal damage. its is also
possible to effect players stamina and give them a red screen flash effect, when they are hurt from
falling, check the cvars below...


cvars and default settings:

- plugin on/off - 1 = on | 0 = off
dod_fdc 1

- red screen effect? - 1 = on | 0 = off
dod_fdc_sf 1

- fall damage in % - 100 is normal its can also be set above 100 if you wanna upper the damage...
dod_fdc_percent 50

- should fall damage affect players stamina? - 1 = on | 0 = off
dod_fdc_stamina 1

- if stamina is affected, how low should it be set?
dod_fdc_set_stamina 10

- fall damage below this value does not affect players stamina
dod_fdc_min_dmg 20


changelog:

*/
////////////////////////////////////////////////////////////////////////////////////////////////////
#include <amxmodx>
#include <dodfun>
#include <fakemeta>
#include <hamsandwich>
////////////////////////////////////////////////////////////////////////////////////////////////////
#define PLUGIN "DoD Fall Damage Control"
#define VERSION "1.0 by Dr.G - www.clan-go.net"
#define AUTHOR "Dr.G"
////////////////////////////////////////////////////////////////////////////////////////////////////
#define DEBUG 0
////////////////////////////////////////////////////////////////////////////////////////////////////
new s_f, p_on, p_s_effect, p_amount, p_stamina, p_min_dmg, p_set_stamina
////////////////////////////////////////////////////////////////////////////////////////////////////
public plugin_init()
{
/* reg plugin */
register_plugin(PLUGIN, VERSION, AUTHOR)
register_cvar("dod_fdc_stats",VERSION,FCVAR_SERVER|FCVAR_SPONLY)

/* Ham <3 */
RegisterHam(Ham_TakeDamage, "player", "func_TakeDamage")

/* more ham - spawn */
RegisterHam(Ham_Spawn,"player","func_HamSpawn")

/* plugin on/off */
p_on = register_cvar("dod_fdc", "1")

/* red screen effect on/off */
p_s_effect = register_cvar("dod_fdc_sf","1")

/* fall damage in % */
p_amount = register_cvar("dod_fdc_percent","50")

/* should fall damage affect players stamina? - on/off */
p_stamina = register_cvar("dod_fdc_stamina","1")

/* if stamina is affected, how low should it be set? */
p_set_stamina = register_cvar("dod_fdc_set_stamina","30")

/* fall damage below this value does not affect players stamina */
p_min_dmg = register_cvar("dod_fdc_min_dmg", "20")

/* s fade */
s_f = get_user_msgid("ScreenFade")
}
////////////////////////////////////////////////////////////////////////////////////////////////////
public func_HamSpawn(id)
{
if(get_pcvar_num(p_on) && is_user_alive(id) && is_user_connected(id) && get_user_team(id))
set_task(1.0,"btn",id)
}
////////////////////////////////////////////////////////////////////////////////////////////////////
public func_TakeDamage(id, idinflictor, idattacker, Float:damage, damagebits)
{
if(get_pcvar_num(p_on) && is_user_alive(id) && (damagebits & DMG_FALL))
{

if(damage <= get_pcvar_float(p_min_dmg))
{
dmg_effect(id,get_pcvar_num(p_s_effect), 3, 0)

damage = float(floatround(get_pcvar_float(p_amount) / 100 * damage))

SetHamParamFloat(4,damage)

#if DEBUG
client_print(id,3,"fall dmg??")
#endif
return HAM_HANDLED
}
dmg_effect(id,get_pcvar_num(p_s_effect), 8, get_pcvar_num(p_stamina))

damage = float(floatround(get_pcvar_float(p_amount) / 100 * damage))

SetHamParamFloat(4,damage)

#if DEBUG
client_print(id,3,"fall dmg over %d??", get_pcvar_num(p_min_dmg))
#endif
return HAM_HANDLED
}
return HAM_HANDLED
}
////////////////////////////////////////////////////////////////////////////////////////////////////
stock dmg_effect(id, const sf_effect, const length, const sta_effect)
{
if(sf_effect)
{
message_begin(MSG_ONE_UNRELIABLE, s_f, _, id)
write_short(length * 1000)
write_short(length * 1000)
write_short(1<<1)
write_byte(215)
write_byte(50)
write_byte(50)
write_byte(250)
message_end()
}
if(!sta_effect)
return PLUGIN_HANDLED

dod_set_stamina(id, STAMINA_SET,_,get_pcvar_num(p_set_stamina))
set_task(1.0,"btn",id)
return PLUGIN_HANDLED
}
////////////////////////////////////////////////////////////////////////////////////////////////////
public btn(id)
{
if(is_user_alive(id))
dod_set_stamina(id, STAMINA_RESET)
}
////////////////////////////////////////////////////////////////////////////////////////////////////

Simple and usefull imo.

- cheers

ghzero
04-03-2009, 04:55 PM
question : for what stand the parameter ,,inflictor,, ?! (weaponid?)

diamond-optic
04-03-2009, 06:52 PM
from the ham_const.inc file:

/**
* Description: Usually called whenever an entity takes any kind of damage.
* Inflictor is the entity that caused the damage (such as a gun).
* Attacker is the entity that tirggered the damage (such as the gun's owner).
* Forward params: function(this, idinflictor, idattacker, Float:damage, damagebits);
* Return type: Integer.
* Execute params: ExecuteHam(Ham_TakeDamage, this, idinflictor, idattacker, Float:damage, damagebits);
*/
Ham_TakeDamage,

ghzero
04-03-2009, 08:56 PM
allright, thanx ...inflictor == entity of infliction like grenade-entity-id.