-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathangle-tas.sp
195 lines (165 loc) · 5.44 KB
/
angle-tas.sp
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#define MAX_ANGLES 8
char g_angleNames[MAX_ANGLES][32] =
{
"Forwards",
"Backwards",
"Sideways 1",
"Sideways 2",
"Half-sideways 1",
"Half-sideways 2",
"Backwards Half-sideways 1",
"Backwards Half-sideways 2"
};
int g_angleTypes[MAX_ANGLES] =
{
0, // Forwards
180, // Backwards
90, // Sideways 1
270, // Sideways 2
45, // Half-sideways 1
315, // Half-sideways 2
135, // Backwards Half-sideways 1
225 // Backwards Half-sideways 2
};
float g_fakeAngles[MAXPLAYERS + 1][3];
int g_currentAngle[MAXPLAYERS + 1];
public void OnPluginStart()
{
RegConsoleCmd("sm_surfangle", Command_SurfAngle, "Changes the player's surfing angle");
}
public void OnClientPutInServer(int client)
{
g_fakeAngles[client][0] = 0.0;
g_fakeAngles[client][1] = 0.0;
g_fakeAngles[client][2] = 0.0;
g_currentAngle[client] = -1;
SDKHook(client, SDKHook_ProcessUsercmds, Hook_ProcessUsercmds);
}
public void OnClientDisconnect(int client)
{
g_fakeAngles[client][0] = 0.0;
g_fakeAngles[client][1] = 0.0;
g_fakeAngles[client][2] = 0.0;
g_currentAngle[client] = -1;
SDKUnhook(client, SDKHook_ProcessUsercmds, Hook_ProcessUsercmds);
}
public void OnPlayerTeam(Event event, const char[] name, bool dontBroadcast)
{
int client = GetClientOfUserId(event.GetInt("userid"));
if (client > 0)
{
g_fakeAngles[client][0] = 0.0;
g_fakeAngles[client][1] = 0.0;
g_fakeAngles[client][2] = 0.0;
g_currentAngle[client] = -1;
}
}
public Action Command_SurfAngle(int client, int args)
{
if (args < 1)
{
PrintToConsole(client, "Usage: sm_surfangle <angle>");
PrintToConsole(client, "Available angles:");
for (int i = 0; i < MAX_ANGLES; i++)
{
PrintToConsole(client, "%d. %s", i + 1, g_angleNames[i]);
}
return Plugin_Handled;
}
char arg[32];
GetCmdArg(1, arg, sizeof(arg));
int angle = StringToInt(arg) - 1;
if (angle < 0 || angle >= MAX_ANGLES)
{
PrintToConsole(client, "Invalid angle. Please enter a value between 1 and %d.", MAX_ANGLES);
return Plugin_Handled;
}
g_currentAngle[client] = angle;
PrintHintText(client, "Surfing angle changed to: %s", g_angleNames[angle]);
return Plugin_Handled;
}
public Action Hook_ProcessUsercmds(int client, int buttons, int impulse, const float vel[3], const float angles[3], int weapon, int subtype, int cmdnum, int tickcount, int seed, const int mouse[2])
{
if (client <= 0 || client > MaxClients || !IsClientInGame(client) || !IsPlayerAlive(client))
return Plugin_Continue;
if (g_currentAngle[client] == -1)
return Plugin_Continue;
float clientAngles[3] = {0.0, 0.0, 0.0};
switch (g_angleTypes[g_currentAngle[client]])
{
case 0: // Forwards
// break;
case 180: // Backwards
clientAngles[1] = angles[1] + 180.0;
SwapButtons(client, IN_FORWARD, IN_BACK);
SwapButtons(client, IN_MOVELEFT, IN_MOVERIGHT);
// break;
case 90: // Sideways 1
clientAngles[1] = angles[1] + 90.0;
SwapButtons(client, IN_FORWARD, IN_MOVERIGHT);
SwapButtons(client, IN_BACK, IN_MOVELEFT);
// break;
case 270: // Sideways 2
clientAngles[1] = angles[1] + 270.0;
SwapButtons(client, IN_FORWARD, IN_MOVELEFT);
SwapButtons(client, IN_BACK, IN_MOVERIGHT);
break;
case 45: // Half-sideways 1
clientAngles[1] = angles[1] + 45.0;
CombineButtons(client, IN_FORWARD, IN_MOVERIGHT);
CombineButtons(client, IN_BACK, IN_MOVELEFT);
// break;
case 315: // Half-sideways 2
clientAngles[1] = angles[1] + 315.0;
CombineButtons(client, IN_FORWARD, IN_MOVELEFT);
CombineButtons(client, IN_BACK, IN_MOVERIGHT);
// break;
case 135: // Backwards Half-sideways 1
clientAngles[1] = angles[1] + 135.0;
CombineButtons(client, IN_BACK, IN_MOVERIGHT);
CombineButtons(client, IN_FORWARD, IN_MOVELEFT);
// break;
case 225: // Backwards Half-sideways 2
clientAngles[1] = angles[1] + 225.0;
CombineButtons(client, IN_BACK, IN_MOVELEFT);
CombineButtons(client, IN_FORWARD, IN_MOVERIGHT);
// break;
}
NormalizeAngles(clientAngles);
SetEntPropVector(client, Prop_Send, "m_vecViewOffset[1]", clientAngles);
return Plugin_Changed;
}
void SwapButtons(int client, int button1, int button2)
{
int buttons = GetEntProp(client, Prop_Data, "m_nButtons");
bool hasButton1 = (buttons & button1) != 0;
bool hasButton2 = (buttons & button2) != 0;
if (hasButton1)
buttons |= button2;
else
buttons &= ~button2;
if (hasButton2)
buttons |= button1;
else
buttons &= ~button1;
SetEntProp(client, Prop_Data, "m_nButtons", buttons);
}
void CombineButtons(int client, int button1, int button2)
{
int buttons = GetEntProp(client, Prop_Data, "m_nButtons");
if (buttons & button1)
buttons |= button2;
else
buttons &= ~button2;
SetEntProp(client, Prop_Data, "m_nButtons", buttons);
}
void NormalizeAngles(float angles[3])
{
while (angles[1] > 180.0)
angles[1] -= 360.0;
while (angles[1] < -180.0)
angles[1] += 360.0;
}