-
Notifications
You must be signed in to change notification settings - Fork 2
/
kztimer.cpp
161 lines (138 loc) · 4.16 KB
/
kztimer.cpp
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
#define PS_VELMOD_MAX 1.104 // Calculated 276/250
#define PS_INCREMENT (0.0009f * 128.0f)
#define PS_INCREMENT_FAST (0.001f * 128.0f)
#define PS_DECREMENT (0.007f * 128.0f)
#define PS_DECREMENT_FAST (0.04f * 128.0f)
#define PS_MAX_COUNT (75.0f / 128.0f)
#include "mathlib/vector.h"
f32 GetClientMovingDirection(CCSPlayer_MovementServices* ms, CMoveData* mv)
{
Vector fVelocity = mv->m_vecVelocity;
QAngle fEyeAngles = mv->m_vecViewAngles;
if (fEyeAngles.x > 70.0) fEyeAngles.x = 70.0;
if (fEyeAngles.x < -70.0) fEyeAngles.x = -70.0;
Vector viewDirection;
if (ms->pawn->m_MoveType == MOVETYPE_LADDER)
{
viewDirection = ms->m_vecLadderNormal;
}
else
{
AngleVectors(mv->m_vecViewAngles, &viewDirection);
}
VectorNormalize(fVelocity);
VectorNormalize(viewDirection);
f32 direction = DotProduct(fVelocity, viewDirection);
if (ms->pawn->m_MoveType == MOVETYPE_LADDER)
direction = direction * -1;
return direction;
}
f32 GetClientMovingDirection(CCSPlayer_MovementServices *ms, CMoveData *mv, bool ladder)
{
QAngle angles = mv->m_vecViewAngles;
angles[0] = CLAMP(-70.0f, angles[0], 70.0f);
Vector viewNormal;
if (ladder)
{
viewNormal = ms->m_vecLadderNormal;
}
else
{
AngleVectors(mv->m_vecViewAngles, &viewNormal, NULL, NULL);
}
Vector velocity = mv->m_vecVelocity.Normalized();
f32 direction = velocity.Dot(viewNormal);
if (ladder)
{
direction *= -1;
}
return direction;
}
f32 CalcPrestrafeVelMod(PlayerData *pd, CCSPlayer_MovementServices *ms, CMoveData *mv)
{
if (!(ms->pawn->m_fFlags & FL_ONGROUND))
{
return pd->preVelMod;
}
float speed = mv->m_vecVelocity.Length2D();
if (!pd->turning)
{
if (gpGlobals->curtime - pd->preVelModLastChange > 0.2f)
{
pd->preVelMod = 1.0f;
pd->preVelModLastChange = gpGlobals->curtime;
}
else if (pd->preVelMod > PS_VELMOD_MAX + 0.007f)
{
return PS_VELMOD_MAX - 0.001f; // Returning without setting the variable is intentional
}
}
else if ((IsButtonDown(ms->m_nButtons, IN_MOVERIGHT) || IsButtonDown(ms->m_nButtons, IN_MOVELEFT)) && speed > 248.9)
{
float increment = PS_INCREMENT * gpGlobals->interval_per_tick;
if (pd->preVelMod > 1.04f)
{
increment = PS_INCREMENT_FAST * gpGlobals->interval_per_tick;;
}
bool forwards = GetClientMovingDirection(ms, mv, false) > 0.0f;
if ((IsButtonDown(ms->m_nButtons, IN_MOVERIGHT) && pd->turning == TURN_RIGHT || pd->turning == TURN_LEFT && !forwards)
|| (IsButtonDown(ms->m_nButtons, IN_MOVELEFT) && pd->turning == TURN_LEFT || pd->turning == TURN_RIGHT && !forwards))
{
pd->preCounter += gpGlobals->interval_per_tick;
if (pd->preCounter < PS_MAX_COUNT)
{
pd->preVelMod += increment;
if (pd->preVelMod > PS_VELMOD_MAX)
{
if (pd->preVelMod > PS_VELMOD_MAX + 0.007f)
{
pd->preVelMod = PS_VELMOD_MAX - 0.001f;
}
else
{
pd->preVelMod -= PS_DECREMENT * gpGlobals->interval_per_tick;
}
}
pd->preVelMod += increment;
}
else
{
pd->preVelMod -= PS_DECREMENT * 0.5f * gpGlobals->interval_per_tick;
pd->preCounter -= gpGlobals->interval_per_tick * 2.0f;
if (pd->preVelMod < 1.0)
{
pd->preVelMod = 1.0;
pd->preCounter = 0;
}
}
}
else
{
pd->preVelMod -= PS_DECREMENT_FAST * gpGlobals->interval_per_tick;
if (pd->preVelMod < 1.0)
{
pd->preVelMod = 1.0;
}
}
pd->preVelModLastChange = gpGlobals->curtime;
}
else
{
pd->preCounter = 0;
return 1.0; // Returning without setting the variable is intentional
}
return pd->preVelMod;
}
void SetupKZTimerConvars()
{
engine->ServerCommand("sv_accelerate 6.5");
engine->ServerCommand("sv_accelerate_use_weapon_speed 0");
engine->ServerCommand("sv_airaccelerate 100");
engine->ServerCommand("sv_enablebunnyhopping 1");
engine->ServerCommand("sv_friction 5");
engine->ServerCommand("sv_ladder_scale_speed 1");
engine->ServerCommand("sv_maxvelocity 2000");
engine->ServerCommand("sv_staminamax 0");
engine->ServerCommand("sv_wateraccelerate 10");
engine->ServerCommand("sv_jump_spam_penalty_time 0.0078125");
}