-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVelocityInterface.as
More file actions
141 lines (108 loc) · 3.22 KB
/
Copy pathVelocityInterface.as
File metadata and controls
141 lines (108 loc) · 3.22 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// "plugin"
// {
// "name" "VelocityInterface"
// "script" "VelocityInterface"
// }
dictionary player_settings;
void PluginInit() {
g_Module.ScriptInfo.SetAuthor("ProffDea, mrcobalt124");
g_Module.ScriptInfo.SetContactInfo("https://github.com/ProffDea, https://github.com/Menotdan");
g_Hooks.RegisterHook(Hooks::Player::ClientSay, @ClientSay);
g_Hooks.RegisterHook(Hooks::Player::ClientPutInServer, @ClientPutInServer);
}
CClientCommand _vi("vi", "Velocity Interface", @ConsoleCommand);
void ConsoleCommand(const CCommand@ args) {
CBasePlayer@ player = g_ConCommandSystem.GetCurrentPlayer();
parse_args(player, args);
}
HookReturnCode ClientSay(SayParameters@ context) {
CBasePlayer@ player = context.GetPlayer();
const CCommand@ args = context.GetArguments();
bool valid_args = parse_args(player, args);
if (valid_args) {
context.ShouldHide = true;
return HOOK_HANDLED;
}
return HOOK_CONTINUE;
}
HookReturnCode ClientPutInServer(CBasePlayer@ player) {
PlayerSettings@ settings = get_settings(player);
if (settings !is null && settings.show_interface) {
render(EHandle(player));
}
return HOOK_CONTINUE;
}
bool parse_args(CBasePlayer@ player, const CCommand@ args) {
uint arg_len = args.ArgC();
bool has_command = (arg_len >= 1 && args[0] == ".vi");
bool has_subcommand = arg_len >= 2;
if (!has_command) {
return false;
}
if (!has_subcommand) {
help(player);
return true;
}
PlayerSettings@ settings = get_settings(player);
if (settings is null) {
return false;
}
string subcommand = args[1];
if (subcommand == "toggle") {
settings.show_interface = !settings.show_interface;
if (settings.show_interface) {
render(EHandle(player));
}
} else if (subcommand == "y") {
bool has_position = arg_len >= 3;
if (has_position) {
float y = atof(args[2]);
settings.position_y = y;
}
} else {
help(player);
}
return true;
}
void help(CBasePlayer@ player) {
g_PlayerFuncs.SayText(player, "Velocity Interface\n");
g_PlayerFuncs.SayText(player, "\".vi toggle\" Toggle interface on/off\n");
g_PlayerFuncs.SayText(player, "\".vi y 0.9\" Set y position of interface from 0.0 - 1.0\n");
}
void render(EHandle player_ptr) {
CBasePlayer@ player = cast<CBasePlayer@>(player_ptr.GetEntity());
PlayerSettings@ settings = get_settings(player);
if (settings is null) {
return;
}
HUDTextParams context;
context.holdTime = 0.2;
context.fadeinTime = 0.;
context.fadeoutTime = 0.;
context.y = settings.position_y;
Vector velocity = player.pev.velocity;
float magnitude = sqrt(pow(velocity.x, 2) + pow(velocity.y, 2));
string message = "Velocity (u/s): " + magnitude;
g_PlayerFuncs.HudMessage(player, context, message);
if (settings.show_interface) {
g_Scheduler.SetTimeout("render", 0.1f, player_ptr);
}
}
class PlayerSettings {
bool show_interface = true;
float position_y = 0.9;
}
PlayerSettings@ get_settings(CBasePlayer@ player) {
if (player is null || !player.IsConnected()) {
return null;
}
string id = g_EngineFuncs.GetPlayerAuthId(player.edict());
if (id == "STEAM_ID_LAN" || id == "BOT") {
id = player.pev.netname;
}
if (!player_settings.exists(id)) {
PlayerSettings settings;
player_settings[id] = settings;
}
return cast<PlayerSettings@>(player_settings[id]);
}