Datasets:
Tasks:
Text Generation
Modalities:
Text
Formats:
text
Languages:
Russian
Size:
10K - 100K
Tags:
code
License:
Upload 2 files
Browse files- Ham_TakeDamage.txt +88 -0
- Ham_TraceAttack.txt +129 -0
Ham_TakeDamage.txt
ADDED
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
HamSandWich function:
|
2 |
+
PHP Code:
|
3 |
+
Ham_TakeDamage
|
4 |
+
Description:
|
5 |
+
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!
|
6 |
+
It also can be used to give damage.
|
7 |
+
Here I will present how to correctly use this function!
|
8 |
+
You should use this function when you want to simulate an attack by a entity!
|
9 |
+
|
10 |
+
|
11 |
+
Usage:
|
12 |
+
PHP Code:
|
13 |
+
#define OFFSET_LAST_HIT_GROUP 75
|
14 |
+
#define EXTRAOFFSET_PL_LINUX 5
|
15 |
+
|
16 |
+
// plugin_init()
|
17 |
+
RegisterHam(Ham_TakeDamage, "player", "fw_takedamage")
|
18 |
+
|
19 |
+
public fw_takedamage(victim, inflictor, attacker, Float:damage, bits)
|
20 |
+
{
|
21 |
+
// Victim is the entity that has been taken damage
|
22 |
+
// Inflictor is the entity that directly gived damage
|
23 |
+
// Attacker is the owner of the inflictor
|
24 |
+
// If Attacker == Inflictor that means that the damage was inflicted by a player (such as gun shot/knife stab)
|
25 |
+
// Damage the damage
|
26 |
+
// Bits the type of damage represented in Bitsums
|
27 |
+
|
28 |
+
// For grenade damage (In CS) the bits is equal to (1<<24)
|
29 |
+
// Basically for hooking the he grenade damage is to put this condition
|
30 |
+
// if (bits & (1<<24))
|
31 |
+
|
32 |
+
// For bullet/knife damage (In CS) the bits are equal to (DMG_BULLET | DMG_NEVERGIB)
|
33 |
+
// Basically for hooking the shot damage is to put this condition
|
34 |
+
// if (bits & (DMG_BULLET | DMG_NEVERGIB))
|
35 |
+
|
36 |
+
// Now the most subtile element is that we can get the last hitgroup where the damage was dealt
|
37 |
+
|
38 |
+
new hitgroup = get_pdata_int(victim, OFFSET_LAST_HIT_GROUP, EXTRAOFFSET_PL_LINUX)
|
39 |
+
}
|
40 |
+
How to properly execute damage? This is the way to do it!
|
41 |
+
PHP Code:
|
42 |
+
#define OFFSET_LAST_HIT_GROUP 75
|
43 |
+
#define EXTRAOFFSET_PL_LINUX 5
|
44 |
+
|
45 |
+
new const Float:hitgroup_multi[] =
|
46 |
+
{
|
47 |
+
1.0, // HIT_GENERIC
|
48 |
+
4.0, // HIT_HEAD
|
49 |
+
1.0, // HIT_CHEST
|
50 |
+
1.25, // HIT_STOMACH
|
51 |
+
1.0, // HIT_LEFTARM
|
52 |
+
1.0, // HIT_RIGHTARM
|
53 |
+
0.75, // HIT_LEFTLEG
|
54 |
+
0.75 // HIT_RIGHTLEG
|
55 |
+
0.0 // HIT_SHIELD
|
56 |
+
}
|
57 |
+
|
58 |
+
stock Ham_ExecDamage(victim, inflictor, attacker, damage, hitgroup, bits)
|
59 |
+
{
|
60 |
+
set_pdata_int(victim, OFFSET_LAST_HIT_GROUP, hitgroup, EXTRAOFFSET_PL_LINUX)
|
61 |
+
ExecuteHam(Ham_TakeDamage, victim, inflictor, attacker, damage*hitgroup_multi[hitgroup], bits)
|
62 |
+
}
|
63 |
+
|
64 |
+
stock Ham_ExecDamageB(victim, inflictor, attacker, damage, hitgroup, bits)
|
65 |
+
{
|
66 |
+
set_pdata_int(victim, OFFSET_LAST_HIT_GROUP, hitgroup, EXTRAOFFSET_PL_LINUX)
|
67 |
+
ExecuteHamB(Ham_TakeDamage, victim, inflictor, attacker, damage*hitgroup_multi[hitgroup], bits)
|
68 |
+
}
|
69 |
+
|
70 |
+
stock HamRadiusDamage(ent, Float:radius, Float:damage, bits)
|
71 |
+
{
|
72 |
+
new target = -1, Float:origin[3]
|
73 |
+
pev(ent, pev_origin, origin)
|
74 |
+
|
75 |
+
while(( target = find_ent_in_sphere(target, origin, radius) ))
|
76 |
+
{
|
77 |
+
static Float:o[3]
|
78 |
+
pev(target, pev_origin, o)
|
79 |
+
|
80 |
+
xs_vec_sub(origin, o, o)
|
81 |
+
|
82 |
+
// Recheck if the entity is in radius
|
83 |
+
if (xs_vec_len(o) > radius)
|
84 |
+
continue
|
85 |
+
|
86 |
+
Ham_ExecDamageB(target, ent, pev(ent, pev_owner), damage * (xs_vec_len(o) / radius), HIT_GENERIC, bits)
|
87 |
+
}
|
88 |
+
}
|
Ham_TraceAttack.txt
ADDED
@@ -0,0 +1,129 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
HamSandWich function:
|
2 |
+
PHP Code:
|
3 |
+
Ham_TraceAttack
|
4 |
+
Description:
|
5 |
+
Forward: This function is called when an entity is shot by another player (weapon, not grenade.)
|
6 |
+
Function: This function simulates a weapon attack on an entity.
|
7 |
+
You should use this function when you want to simulate an attack by a weapon from a player (like a gunshot!)
|
8 |
+
|
9 |
+
Parameters:
|
10 |
+
(ent, attacker, float:damage, Float:direction[3], trace, bits)
|
11 |
+
- ent is the entity that has been shot
|
12 |
+
- attacker is the entity that shoot the victim
|
13 |
+
- damage - this is the damage done by the shot but it does not have the hitgroup multiplication done (that is done before TakeDamage Call)
|
14 |
+
- direction - this parameter has a very important roll, it is a normalized vector that shows the direction of the bullets path
|
15 |
+
- trace - the trace handle that offers lots of useful information
|
16 |
+
- bits - the damage bits
|
17 |
+
|
18 |
+
Forward usage:
|
19 |
+
PHP Code:
|
20 |
+
#define SHOT_DISTANCE_POSSIBLE 2048.0
|
21 |
+
|
22 |
+
// plugin_init()
|
23 |
+
Register_Ham(Ham_TraceAttack, "func_breakable", "fw_traceatt_break")
|
24 |
+
|
25 |
+
public fw_traceatt_break(ent, attacker, float:damage, Float:direction[3], trace, bits)
|
26 |
+
{
|
27 |
+
new Float:start[3], end[3], fraction, multi
|
28 |
+
get_tr2(trace, TR_vecEndPos, end)
|
29 |
+
get_tr2(trace, TR_flFraction, fraction)
|
30 |
+
|
31 |
+
multi = fraction * SHOT_DISTANCE_POSSIBLE
|
32 |
+
|
33 |
+
xs_vec_mul_scalar(direction, multi, start)
|
34 |
+
|
35 |
+
// This is how to correctly get the start origin!
|
36 |
+
xs_vec_add(start, end, start)
|
37 |
+
|
38 |
+
}
|
39 |
+
Function true usage:
|
40 |
+
PHP Code:
|
41 |
+
#define SHOT_DISTANCE_POSSIBLE 2048.0
|
42 |
+
|
43 |
+
public Ham_Shoot(attacker, damage, bits, bool:can_penetrate)
|
44 |
+
{
|
45 |
+
new Float:angles[3], Float:start[3], Float:end[3], Float:direction[3], Float:fakeend[3]
|
46 |
+
|
47 |
+
// Turn the angles in a true vector
|
48 |
+
pev(attacker, pev_angles, angles)
|
49 |
+
angle_vector(angles, ANGLEVECTOR_FORWARD, direction)
|
50 |
+
|
51 |
+
// We make this as a normal shot!
|
52 |
+
xs_vec_mul_scalar(direction, SHOT_DISTANCE_POSSIBLE, fakeend)
|
53 |
+
|
54 |
+
// Start origin
|
55 |
+
pev(attacker, pev_origin, start)
|
56 |
+
pev(attacker, pev_view_ofs, end)
|
57 |
+
xs_vec_add(end, start, start)
|
58 |
+
|
59 |
+
// Obtain the end shot origin
|
60 |
+
xs_vec_add(start, fakeend, end)
|
61 |
+
|
62 |
+
// From now this is how these variables will be used
|
63 |
+
// origin - start place (will remain constant!)
|
64 |
+
// end - end place (will remain constant!)
|
65 |
+
// angles - no use
|
66 |
+
// fakeend - dynamic start origin
|
67 |
+
// direction - will be used in the forwards (will remain constant!)
|
68 |
+
|
69 |
+
new ptr = create_tr2()
|
70 |
+
|
71 |
+
// Trace to the first entity
|
72 |
+
engfunc(EngFunc_TraceLine, start, end, DONT_IGNORE_MONSTERS, attacker, ptr)
|
73 |
+
|
74 |
+
new Float:fraction, hit = get_tr2(ptr, TR_pHit)
|
75 |
+
get_tr2(ptr, TR_flFraction, fraction)
|
76 |
+
|
77 |
+
// Update the fake start origin
|
78 |
+
get_tr2(ptr, TR_vecEndPos, fakeend)
|
79 |
+
|
80 |
+
// This means that we hited sky!
|
81 |
+
if (fraction != 1.0 && engfunc(EngFunc_PointContents, fakeend) == CONTENTS_SKY && hit == -1)
|
82 |
+
{
|
83 |
+
// Prepare the trace handle
|
84 |
+
set_tr2(ptr, TR_pHit, 0)
|
85 |
+
|
86 |
+
// Bullet trace!
|
87 |
+
ExecuteHamB(Ham_TraceAttack, 0, attacker, damage, direction, ptr, DMG_NEVERGIB | DMG_BULLET)
|
88 |
+
|
89 |
+
free_tr2(ptr)
|
90 |
+
return -1
|
91 |
+
}
|
92 |
+
|
93 |
+
if (hit == -1)
|
94 |
+
{
|
95 |
+
hit = 0
|
96 |
+
set_tr2(ptr, TR_pHit, hit)
|
97 |
+
}
|
98 |
+
|
99 |
+
ExecuteHamB(Ham_TraceAttack, hit, attacker, damage, direction, ptr, DMG_NEVERGIB | DMG_BULLET)
|
100 |
+
|
101 |
+
if (!can_penetrate)
|
102 |
+
{
|
103 |
+
free_tr2(ptr)
|
104 |
+
return 1
|
105 |
+
}
|
106 |
+
|
107 |
+
// Trace to the next entity
|
108 |
+
engfunc(EngFunc_TraceLine, fakeend, end, DONT_IGNORE_MONSTERS, hit, ptr)
|
109 |
+
|
110 |
+
hit = get_tr2(ptr, TR_pHit)
|
111 |
+
get_tr2(ptr, TR_flFraction, fraction)
|
112 |
+
|
113 |
+
// Update the fake start origin
|
114 |
+
get_tr2(ptr, TR_vecEndPos, fakeend)
|
115 |
+
|
116 |
+
if (hit == -1)
|
117 |
+
{
|
118 |
+
hit = 0
|
119 |
+
set_tr2(ptr, TR_pHit, hit)
|
120 |
+
}
|
121 |
+
|
122 |
+
set_tr2(ptr, TR_flFraction, get_distance_f(start, fakeend) / SHOT_DISTANCE_POSSIBLE)
|
123 |
+
|
124 |
+
ExecuteHamB(Ham_TraceAttack, hit, attacker, damage, direction, ptr, DMG_NEVERGIB | DMG_BULLET)
|
125 |
+
|
126 |
+
|
127 |
+
free_tr2(ptr)
|
128 |
+
return 1
|
129 |
+
}
|