forked from enimmy/autist-landfix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlandfix.sp
169 lines (136 loc) · 3.98 KB
/
landfix.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
#pragma newdecls required
#pragma semicolon 1
#include <sdktools>
#include <sdkhooks>
#undef REQUIRE_PLUGIN
#include <shavit/core>
#include <shavit/hud>
public Plugin myinfo =
{
name = "LandFix",
author = "Haze",
description = "",
version = "1.3",
url = ""
}
bool gB_Enabled[MAXPLAYERS+1] = {false, ...};
bool gB_Shavit = false;
int gI_LastGroundEntity[MAXPLAYERS + 1];
public void OnPluginStart()
{
RegConsoleCmd("sm_landfix", Command_LandFix, "Landfix");
RegConsoleCmd("sm_64fix", Command_LandFix, "Landfix");
for(int i = 1; i <= MaxClients; i++)
{
gB_Enabled[i] = false;
}
gB_Shavit = LibraryExists("shavit");
}
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
CreateNative("Landfix_GetLandfixEnabled", Native_GetLandfixEnabled);
RegPluginLibrary("modern-landfix");
return APLRes_Success;
}
int Native_GetLandfixEnabled(Handle handler, int numParams)
{
return gB_Enabled[GetNativeCell(1)];
}
public void OnLibraryAdded(const char[] name)
{
gB_Shavit = LibraryExists("shavit");
}
public void OnLibraryRemoved(const char[] name)
{
gB_Shavit = LibraryExists("shavit");
}
public void OnClientPutInServer(int client)
{
gB_Enabled[client] = false;
}
public Action Command_LandFix(int client, int args)
{
if(client == 0) return Plugin_Handled;
gB_Enabled[client] = !gB_Enabled[client];
if(gB_Shavit)
{
Shavit_PrintToChat(client, "LandFix: %s", gB_Enabled[client] ? "Enabled" : "Disabled");
}
else
{
PrintToChat(client, "LandFix: %s", gB_Enabled[client] ? "Enabled" : "Disabled");
}
return Plugin_Handled;
}
//Thanks MARU for the idea/http://steamcommunity.com/profiles/76561197970936804
float GetGroundUnits(int client)
{
if (!IsPlayerAlive(client)) return 0.0;
if (GetEntityMoveType(client) != MOVETYPE_WALK) return 0.0;
if (GetEntProp(client, Prop_Data, "m_nWaterLevel") > 1) return 0.0;
float origin[3], originBelow[3], landingMins[3], landingMaxs[3];
GetEntPropVector(client, Prop_Data, "m_vecAbsOrigin", origin);
GetEntPropVector(client, Prop_Data, "m_vecMins", landingMins);
GetEntPropVector(client, Prop_Data, "m_vecMaxs", landingMaxs);
originBelow[0] = origin[0];
originBelow[1] = origin[1];
originBelow[2] = origin[2] - 2.0;
TR_TraceHullFilter(origin, originBelow, landingMins, landingMaxs, MASK_PLAYERSOLID, PlayerFilter, client);
if(!TR_DidHit())
{
return 0.0;
}
TR_GetEndPosition(originBelow, null);
float defaultHeight = originBelow[2] - RoundToFloor(originBelow[2]);
if(defaultHeight > 0.03125)
{
defaultHeight = 0.03125;
}
return (origin[2] - originBelow[2] + defaultHeight);
}
public Action Shavit_PreOnKeyHintHUD(int client, int target, char[] keyhint, int keyhintlength, int track, int style, bool &forceUpdate)
{
Format(keyhint, keyhintlength, "Landfix: %s\n\n", gB_Enabled[client] ? "On":"Off");
forceUpdate = true;
return Plugin_Changed;
}
public Action OnPlayerRunCmd(int client, int &buttons)
{
if(IsFakeClient(client))
{
return Plugin_Continue;
}
int iGroundEnt = GetEntPropEnt(client, Prop_Data, "m_hGroundEntity");
if(gB_Enabled[client])
{
if(iGroundEnt != gI_LastGroundEntity[client] && iGroundEnt != -1)
{
if(HasEntProp(iGroundEnt, Prop_Data, "m_currentSound")) //retrowave mega fix
{
return Plugin_Continue;
}
bool bHasVelocityProp = HasEntProp(iGroundEnt, Prop_Data, "m_vecVelocity");
if(bHasVelocityProp)
{
float fVelocity[3];
GetEntPropVector(iGroundEnt, Prop_Data, "m_vecVelocity", fVelocity);
// ground is moving
if(fVelocity[2] != 0.0)
{
return Plugin_Continue;
}
}
//float difference = (gCV_Units.FloatValue - GetGroundUnits(client)), origin[3];
float difference = (1.50 - GetGroundUnits(client)), origin[3];
GetEntPropVector(client, Prop_Data, "m_vecAbsOrigin", origin);
origin[2] += difference;
SetEntPropVector(client, Prop_Data, "m_vecAbsOrigin", origin);
}
}
gI_LastGroundEntity[client] = iGroundEnt;
return Plugin_Continue;
}
public bool PlayerFilter(int entity, int mask)
{
return !(1 <= entity <= MaxClients);
}