-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHook.sma
102 lines (81 loc) · 2.85 KB
/
Hook.sma
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/* Plugin generated by AMXX-Studio */
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <hamsandwich>
#include <engine>
#define PLUGIN "Hook"
#define VERSION "1.0"
#define AUTHOR "Yan"
new beampoint
public plugin_init() {
register_plugin(PLUGIN, VERSION, PLUGIN);
RegisterHam(Ham_Weapon_PrimaryAttack,"weapon_usp", "PlayerAttack");
return PLUGIN_CONTINUE;
}
public plugin_precache()
{
beampoint = precache_model("sprites/laserbeam.spr")
}
public PlayerAttack(this, idcaller, idactivator, use_type, Float:value)
{
console_print(0,"Shooting lasers %d %d",idcaller, idactivator);
shoot_laser(idcaller);
}
public shoot_laser(ent)
{
// We get the origin of the entity.
new Float:origin[3]
pev(ent, pev_origin, origin)
// We want to trace down to the floor, if it's there.
new Float:traceto[3]
traceto[0] = origin[0]
traceto[1] = origin[1]
traceto[2] = origin[2] - 10.0
new trace = 0
// Draw the traceline. We're assuming the object is resting on the floor.
engfunc(EngFunc_TraceLine, origin, traceto, IGNORE_MONSTERS, ent, trace)
new Float:fraction
get_tr2(trace, TR_flFraction, fraction)
// If we didn't hit anything, then we won't get a valid TR_vecPlaneNormal.
if (fraction == 1.0) return
new Float:normal[3]
get_tr2(trace, TR_vecPlaneNormal, normal)
// We'll multiply the the normal vector by a scalar to make it longer.
normal[0] *= 400.0 // Mathematically, we multiplied the length of the vector by 400*(3)^(1/2),
normal[1] *= 400.0 // or, in words, four hundred times root three.
normal[2] *= 400.0
// To get the endpoint, we add the normal vector and the origin.
new Float:endpoint[3]
endpoint[0] = origin[0] + normal[0]
endpoint[1] = origin[1] + normal[1]
endpoint[2] = origin[2] + normal[2]
// Finally, we draw from the laser!
draw_laser(origin, endpoint, 100) // Make it stay for 10 seconds. Not a typo; staytime is in 10ths of a second.
}
public draw_laser(Float:start[3], Float:end[3], staytime)
{
message_begin(MSG_ALL, SVC_TEMPENTITY)
write_byte(TE_BEAMPOINTS)
engfunc(EngFunc_WriteCoord, start[0])
engfunc(EngFunc_WriteCoord, start[1])
engfunc(EngFunc_WriteCoord, start[2])
engfunc(EngFunc_WriteCoord, end[0])
engfunc(EngFunc_WriteCoord, end[1])
engfunc(EngFunc_WriteCoord, end[2])
write_short(beampoint)
write_byte(0)
write_byte(0)
write_byte(staytime) // In tenths of a second.
write_byte(10)
write_byte(1)
write_byte(255) // Red
write_byte(0) // Green
write_byte(0) // Blue
write_byte(127)
write_byte(1)
message_end()
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ ansicpg1252\\ deff0\\ deflang1033{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ f0\\ fs16 \n\\ par }
*/