Datasets:
Tasks:
Text Generation
Modalities:
Text
Formats:
text
Languages:
Russian
Size:
10K - 100K
Tags:
code
License:
HamSandWich function: | |
PHP Code: | |
Ham_TraceAttack | |
Description: | |
Forward: This function is called when an entity is shot by another player (weapon, not grenade.) | |
Function: This function simulates a weapon attack on an entity. | |
You should use this function when you want to simulate an attack by a weapon from a player (like a gunshot!) | |
Parameters: | |
(ent, attacker, float:damage, Float:direction[3], trace, bits) | |
- ent is the entity that has been shot | |
- attacker is the entity that shoot the victim | |
- damage - this is the damage done by the shot but it does not have the hitgroup multiplication done (that is done before TakeDamage Call) | |
- direction - this parameter has a very important roll, it is a normalized vector that shows the direction of the bullets path | |
- trace - the trace handle that offers lots of useful information | |
- bits - the damage bits | |
Forward usage: | |
PHP Code: | |
#define SHOT_DISTANCE_POSSIBLE 2048.0 | |
// plugin_init() | |
Register_Ham(Ham_TraceAttack, "func_breakable", "fw_traceatt_break") | |
public fw_traceatt_break(ent, attacker, float:damage, Float:direction[3], trace, bits) | |
{ | |
new Float:start[3], end[3], fraction, multi | |
get_tr2(trace, TR_vecEndPos, end) | |
get_tr2(trace, TR_flFraction, fraction) | |
multi = fraction * SHOT_DISTANCE_POSSIBLE | |
xs_vec_mul_scalar(direction, multi, start) | |
// This is how to correctly get the start origin! | |
xs_vec_add(start, end, start) | |
} | |
Function true usage: | |
PHP Code: | |
#define SHOT_DISTANCE_POSSIBLE 2048.0 | |
public Ham_Shoot(attacker, damage, bits, bool:can_penetrate) | |
{ | |
new Float:angles[3], Float:start[3], Float:end[3], Float:direction[3], Float:fakeend[3] | |
// Turn the angles in a true vector | |
pev(attacker, pev_angles, angles) | |
angle_vector(angles, ANGLEVECTOR_FORWARD, direction) | |
// We make this as a normal shot! | |
xs_vec_mul_scalar(direction, SHOT_DISTANCE_POSSIBLE, fakeend) | |
// Start origin | |
pev(attacker, pev_origin, start) | |
pev(attacker, pev_view_ofs, end) | |
xs_vec_add(end, start, start) | |
// Obtain the end shot origin | |
xs_vec_add(start, fakeend, end) | |
// From now this is how these variables will be used | |
// origin - start place (will remain constant!) | |
// end - end place (will remain constant!) | |
// angles - no use | |
// fakeend - dynamic start origin | |
// direction - will be used in the forwards (will remain constant!) | |
new ptr = create_tr2() | |
// Trace to the first entity | |
engfunc(EngFunc_TraceLine, start, end, DONT_IGNORE_MONSTERS, attacker, ptr) | |
new Float:fraction, hit = get_tr2(ptr, TR_pHit) | |
get_tr2(ptr, TR_flFraction, fraction) | |
// Update the fake start origin | |
get_tr2(ptr, TR_vecEndPos, fakeend) | |
// This means that we hited sky! | |
if (fraction != 1.0 && engfunc(EngFunc_PointContents, fakeend) == CONTENTS_SKY && hit == -1) | |
{ | |
// Prepare the trace handle | |
set_tr2(ptr, TR_pHit, 0) | |
// Bullet trace! | |
ExecuteHamB(Ham_TraceAttack, 0, attacker, damage, direction, ptr, DMG_NEVERGIB | DMG_BULLET) | |
free_tr2(ptr) | |
return -1 | |
} | |
if (hit == -1) | |
{ | |
hit = 0 | |
set_tr2(ptr, TR_pHit, hit) | |
} | |
ExecuteHamB(Ham_TraceAttack, hit, attacker, damage, direction, ptr, DMG_NEVERGIB | DMG_BULLET) | |
if (!can_penetrate) | |
{ | |
free_tr2(ptr) | |
return 1 | |
} | |
// Trace to the next entity | |
engfunc(EngFunc_TraceLine, fakeend, end, DONT_IGNORE_MONSTERS, hit, ptr) | |
hit = get_tr2(ptr, TR_pHit) | |
get_tr2(ptr, TR_flFraction, fraction) | |
// Update the fake start origin | |
get_tr2(ptr, TR_vecEndPos, fakeend) | |
if (hit == -1) | |
{ | |
hit = 0 | |
set_tr2(ptr, TR_pHit, hit) | |
} | |
set_tr2(ptr, TR_flFraction, get_distance_f(start, fakeend) / SHOT_DISTANCE_POSSIBLE) | |
ExecuteHamB(Ham_TraceAttack, hit, attacker, damage, direction, ptr, DMG_NEVERGIB | DMG_BULLET) | |
free_tr2(ptr) | |
return 1 | |
} |