Datasets:
Tasks:
Text Generation
Modalities:
Text
Formats:
text
Languages:
Russian
Size:
10K - 100K
Tags:
code
License:
HamSandWich function: | |
PHP Code: | |
Ham_TakeDamage | |
Description: | |
This function gives us info about the moment a player takes damage, when we use it as a forward. The return of the forward is a boolean, if it is set to 1 then the damage will be done if set to 0 then it will not be done! | |
It also can be used to give damage. | |
Here I will present how to correctly use this function! | |
You should use this function when you want to simulate an attack by a entity! | |
Usage: | |
PHP Code: | |
#define OFFSET_LAST_HIT_GROUP 75 | |
#define EXTRAOFFSET_PL_LINUX 5 | |
// plugin_init() | |
RegisterHam(Ham_TakeDamage, "player", "fw_takedamage") | |
public fw_takedamage(victim, inflictor, attacker, Float:damage, bits) | |
{ | |
// Victim is the entity that has been taken damage | |
// Inflictor is the entity that directly gived damage | |
// Attacker is the owner of the inflictor | |
// If Attacker == Inflictor that means that the damage was inflicted by a player (such as gun shot/knife stab) | |
// Damage the damage | |
// Bits the type of damage represented in Bitsums | |
// For grenade damage (In CS) the bits is equal to (1<<24) | |
// Basically for hooking the he grenade damage is to put this condition | |
// if (bits & (1<<24)) | |
// For bullet/knife damage (In CS) the bits are equal to (DMG_BULLET | DMG_NEVERGIB) | |
// Basically for hooking the shot damage is to put this condition | |
// if (bits & (DMG_BULLET | DMG_NEVERGIB)) | |
// Now the most subtile element is that we can get the last hitgroup where the damage was dealt | |
new hitgroup = get_pdata_int(victim, OFFSET_LAST_HIT_GROUP, EXTRAOFFSET_PL_LINUX) | |
} | |
How to properly execute damage? This is the way to do it! | |
PHP Code: | |
#define OFFSET_LAST_HIT_GROUP 75 | |
#define EXTRAOFFSET_PL_LINUX 5 | |
new const Float:hitgroup_multi[] = | |
{ | |
1.0, // HIT_GENERIC | |
4.0, // HIT_HEAD | |
1.0, // HIT_CHEST | |
1.25, // HIT_STOMACH | |
1.0, // HIT_LEFTARM | |
1.0, // HIT_RIGHTARM | |
0.75, // HIT_LEFTLEG | |
0.75 // HIT_RIGHTLEG | |
0.0 // HIT_SHIELD | |
} | |
stock Ham_ExecDamage(victim, inflictor, attacker, damage, hitgroup, bits) | |
{ | |
set_pdata_int(victim, OFFSET_LAST_HIT_GROUP, hitgroup, EXTRAOFFSET_PL_LINUX) | |
ExecuteHam(Ham_TakeDamage, victim, inflictor, attacker, damage*hitgroup_multi[hitgroup], bits) | |
} | |
stock Ham_ExecDamageB(victim, inflictor, attacker, damage, hitgroup, bits) | |
{ | |
set_pdata_int(victim, OFFSET_LAST_HIT_GROUP, hitgroup, EXTRAOFFSET_PL_LINUX) | |
ExecuteHamB(Ham_TakeDamage, victim, inflictor, attacker, damage*hitgroup_multi[hitgroup], bits) | |
} | |
stock HamRadiusDamage(ent, Float:radius, Float:damage, bits) | |
{ | |
new target = -1, Float:origin[3] | |
pev(ent, pev_origin, origin) | |
while(( target = find_ent_in_sphere(target, origin, radius) )) | |
{ | |
static Float:o[3] | |
pev(target, pev_origin, o) | |
xs_vec_sub(origin, o, o) | |
// Recheck if the entity is in radius | |
if (xs_vec_len(o) > radius) | |
continue | |
Ham_ExecDamageB(target, ent, pev(ent, pev_owner), damage * (xs_vec_len(o) / radius), HIT_GENERIC, bits) | |
} | |
} |