Skip to content

Commit 354c244

Browse files
Awesomerlyrtldg
andauthored
Startzone speed limit flexibility (#1219)
* Add config flag for MaxPrestrafe override * Allow zoners to edit startzone data * Use start zone data field for prestrafe limit * Add prespeed type 6 that behaves like 5 and prevents prehopping * Fix formatting * Bodged up code for 1 second prehop cooldown on prestrafe mode 6 * Make anti prespeed a little bit better (maybe????) * Tiredly twiddle with prespeed style 6 impl * Add description to maxprestrafe style-setting * nitpicky styling things * Use GetGameTickCount instead of GetSysTickCount * ; --------- Co-authored-by: rtldg <[email protected]> Co-authored-by: rtldg <[email protected]>
1 parent f883397 commit 354c244

File tree

6 files changed

+115
-8
lines changed

6 files changed

+115
-8
lines changed

addons/sourcemod/configs/shavit-styles.cfg

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
// Physics
3636
"airaccelerate" "1000.0" // sv_airaccelerate value for the style.
3737
"runspeed" "260.00" // Running speed. Requires DHooks, shavit-misc and shavit_misc_staticprestrafe set to 1.
38+
"maxprestrafe" "0.0" // The max prestrafe that still allows your timer to start/restart. You generally do *not* need or want to change this unless for surf things (combined with style-setting "prespeed_type" "6" or cvar "shavit_misc_prespeed 6"). Default is 0.0 (disabled).
3839
"gravity" "1.0" // Gravity setting, 1.0 for default. Standard for low gravity styles is 0.6.
3940
"speed" "1.0" // Speed multiplier, 1.0 for default. Standard for slowmo styles is 0.5. This a multiplier for m_flLaggedMovementValue.
4041
"timescale" "1.0" // Timing will scale with this setting. This is a multiplier for m_flLaggedMovementValue but also affects the timer increase speed.

addons/sourcemod/scripting/include/shavit/style-settings.sp

+1
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ public SMCResult OnStyleEnterSection(SMCParser smc, const char[] name, bool opt_
164164

165165
SetStyleSettingFloat(gI_CurrentParserIndex, "airaccelerate", 1000.0);
166166
SetStyleSettingFloat(gI_CurrentParserIndex, "runspeed", 260.00);
167+
SetStyleSettingFloat(gI_CurrentParserIndex, "maxprestrafe", 0.0);
167168
SetStyleSettingFloat(gI_CurrentParserIndex, "gravity", 1.0);
168169
SetStyleSettingFloat(gI_CurrentParserIndex, "speed", 1.0);
169170
SetStyleSettingInt (gI_CurrentParserIndex, "halftime", 0);

addons/sourcemod/scripting/shavit-core.sp

+24-3
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ char gS_Verification[MAXPLAYERS+1][8];
172172
bool gB_CookiesRetrieved[MAXPLAYERS+1];
173173
float gF_ZoneAiraccelerate[MAXPLAYERS+1];
174174
float gF_ZoneSpeedLimit[MAXPLAYERS+1];
175+
float gF_ZoneStartSpeedLimit[MAXPLAYERS+1];
175176
int gI_LastPrintedSteamID[MAXPLAYERS+1];
176177

177178
// kz support
@@ -2521,7 +2522,23 @@ bool CanStartTimer(int client, int track, bool skipGroundCheck)
25212522
if (curVel <= 50.0)
25222523
return true;
25232524

2524-
float prestrafe = StyleMaxPrestrafe(style);
2525+
float cfgMax = GetStyleSettingFloat(style, "maxprestrafe");
2526+
float zoneMax = gF_ZoneStartSpeedLimit[client];
2527+
float prestrafe;
2528+
2529+
if (zoneMax > 0.0)
2530+
{
2531+
prestrafe = zoneMax;
2532+
}
2533+
else if (cfgMax > 0.0)
2534+
{
2535+
prestrafe = cfgMax;
2536+
}
2537+
else
2538+
{
2539+
prestrafe = StyleMaxPrestrafe(style);
2540+
}
2541+
25252542
if (curVel > prestrafe)
25262543
return false;
25272544

@@ -2909,7 +2926,11 @@ void SQL_DBConnect()
29092926

29102927
public void Shavit_OnEnterZone(int client, int type, int track, int id, int entity, int data)
29112928
{
2912-
if (type == Zone_Airaccelerate && track == gA_Timers[client].iTimerTrack)
2929+
if (type == Zone_Start && track == gA_Timers[client].iTimerTrack)
2930+
{
2931+
gF_ZoneStartSpeedLimit[client] = float(data);
2932+
}
2933+
else if (type == Zone_Airaccelerate && track == gA_Timers[client].iTimerTrack)
29132934
{
29142935
gF_ZoneAiraccelerate[client] = float(data);
29152936
}
@@ -2931,7 +2952,7 @@ public void Shavit_OnLeaveZone(int client, int type, int track, int id, int enti
29312952
// Probably so very niche that it doesn't matter.
29322953
if (track != gA_Timers[client].iTimerTrack)
29332954
return;
2934-
if (type != Zone_Airaccelerate && type != Zone_CustomSpeedLimit && type != Zone_Autobhop)
2955+
if (type != Zone_Airaccelerate && type != Zone_CustomSpeedLimit && type != Zone_Autobhop && type != Zone_Start)
29352956
return;
29362957

29372958
UpdateStyleSettings(client);

addons/sourcemod/scripting/shavit-misc.sp

+70-4
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ Function gH_AfterWarningMenu[MAXPLAYERS+1];
7474
int gI_LastWeaponTick[MAXPLAYERS+1];
7575
int gI_LastNoclipTick[MAXPLAYERS+1];
7676
int gI_LastStopInfo[MAXPLAYERS+1];
77+
int gI_LastGroundLandTick[MAXPLAYERS+1];
78+
float gF_ZoneStartSpeedLimit[MAXPLAYERS+1];
7779

7880
// cookies
7981
Handle gH_HideCookie = null;
@@ -266,7 +268,7 @@ public void OnPluginStart()
266268

267269
// cvars and stuff
268270
gCV_GodMode = new Convar("shavit_misc_godmode", "3", "Enable godmode for players?\n0 - Disabled\n1 - Only prevent fall/world damage.\n2 - Only prevent damage from other players.\n3 - Full godmode.\n4 - Prevent fall/world/entity damage (all except damage from other players).", 0, true, 0.0, true, 4.0);
269-
gCV_PreSpeed = new Convar("shavit_misc_prespeed", "2", "Stop prespeeding in the start zone?\n0 - Disabled, fully allow prespeeding.\n1 - Limit relatively to prestrafelimit.\n2 - Block bunnyhopping in startzone.\n3 - Limit to prestrafelimit and block bunnyhopping.\n4 - Limit to prestrafelimit but allow prespeeding. Combine with shavit_core_nozaxisspeed 1 for SourceCode timer's behavior.\n5 - Limit horizontal speed to prestrafe but allow prespeeding.", 0, true, 0.0, true, 5.0);
271+
gCV_PreSpeed = new Convar("shavit_misc_prespeed", "2", "Stop prespeeding in the start zone?\n0 - Disabled, fully allow prespeeding.\n1 - Limit relatively to prestrafelimit.\n2 - Block bunnyhopping in startzone.\n3 - Limit to prestrafelimit and block bunnyhopping.\n4 - Limit to prestrafelimit but allow prespeeding. Combine with shavit_core_nozaxisspeed 1 for SourceCode timer's behavior.\n5 - Limit horizontal speed to prestrafe but allow prespeeding. \n6 - Limit horizontal speed to prestrafe and block bunnyhopping.", 0, true, 0.0, true, 5.0);
270272
gCV_HideTeamChanges = new Convar("shavit_misc_hideteamchanges", "1", "Hide team changes in chat?\n0 - Disabled\n1 - Enabled", 0, true, 0.0, true, 1.0);
271273
gCV_RespawnOnTeam = new Convar("shavit_misc_respawnonteam", "1", "Respawn whenever a player joins a team?\n0 - Disabled\n1 - Enabled", 0, true, 0.0, true, 1.0);
272274
gCV_RespawnOnRestart = new Convar("shavit_misc_respawnonrestart", "1", "Respawn a dead player if they use the timer restart command?\n0 - Disabled\n1 - Enabled", 0, true, 0.0, true, 1.0);
@@ -1349,7 +1351,14 @@ public Action Shavit_OnUserCmdPre(int client, int &buttons, int &impulse, float
13491351
prespeed_type = gCV_PreSpeed.IntValue;
13501352
}
13511353

1354+
int tickCount = GetGameTickCount();
13521355
int iPrevGroundEntity = (gI_GroundEntity[client] != -1) ? EntRefToEntIndex(gI_GroundEntity[client]) : -1;
1356+
1357+
if (iPrevGroundEntity == -1 && iGroundEntity != -1)
1358+
{
1359+
gI_LastGroundLandTick[client] = tickCount;
1360+
}
1361+
13531362
if ((prespeed_type == 2 || prespeed_type == 3) && iPrevGroundEntity == -1 && iGroundEntity != -1 && (buttons & IN_JUMP) > 0)
13541363
{
13551364
DumbSetVelocity(client, view_as<float>({0.0, 0.0, 0.0}));
@@ -1360,6 +1369,22 @@ public Action Shavit_OnUserCmdPre(int client, int &buttons, int &impulse, float
13601369
GetEntPropVector(client, Prop_Data, "m_vecAbsVelocity", fSpeed);
13611370

13621371
float fLimit = (Shavit_GetStyleSettingFloat(gI_Style[client], "runspeed") + gCV_PrestrafeLimit.FloatValue);
1372+
float cfgLimit = Shavit_GetStyleSettingFloat(gI_Style[client], "maxprestrafe");
1373+
float zoneLimit = gF_ZoneStartSpeedLimit[client];
1374+
float maxPrestrafe = StyleMaxPrestrafe(gI_Style[client]);
1375+
1376+
if (zoneLimit > 0.0)
1377+
{
1378+
fLimit = zoneLimit;
1379+
}
1380+
else if (cfgLimit > 0.0)
1381+
{
1382+
fLimit = cfgLimit;
1383+
}
1384+
else if (fLimit > maxPrestrafe)
1385+
{
1386+
fLimit = maxPrestrafe;
1387+
}
13631388

13641389
// if trying to jump, add a very low limit to stop prespeeding in an elegant way
13651390
// otherwise, make sure nothing weird is happening (such as sliding at ridiculous speeds, at zone enter)
@@ -1368,12 +1393,30 @@ public Action Shavit_OnUserCmdPre(int client, int &buttons, int &impulse, float
13681393
fLimit /= 3.0;
13691394
}
13701395

1396+
int iOldButtons = GetEntProp(client, Prop_Data, "m_nOldButtons");
1397+
// TODO: somehow incorporate the autobhop style thingy or figure out a better way to do all of this lmao
1398+
int iAutoBhop = Shavit_GetStyleSettingBool(Shavit_GetBhopStyle(client), "autobhop");
1399+
bool isJumping = (buttons & IN_JUMP) > 0;
1400+
if (!iAutoBhop)
1401+
{
1402+
isJumping = isJumping && (iOldButtons & IN_JUMP) == 0;
1403+
}
1404+
if (
1405+
prespeed_type == 6
1406+
&& iGroundEntity != -1
1407+
&& tickCount - gI_LastGroundLandTick[client] <= 150
1408+
&& isJumping
1409+
)
1410+
{
1411+
fLimit /= 3.0;
1412+
}
1413+
13711414
float fSpeedXY = (SquareRoot(Pow(fSpeed[0], 2.0) + Pow(fSpeed[1], 2.0)));
13721415
float fScale = (fLimit / fSpeedXY);
13731416

13741417
if(fScale < 1.0)
13751418
{
1376-
if (prespeed_type == 5)
1419+
if (prespeed_type == 5 || prespeed_type == 6)
13771420
{
13781421
float zSpeed = fSpeed[2];
13791422
fSpeed[2] = 0.0;
@@ -1428,6 +1471,14 @@ public Action Shavit_OnUserCmdPre(int client, int &buttons, int &impulse, float
14281471
return Plugin_Continue;
14291472
}
14301473

1474+
public void Shavit_OnEnterZone(int client, int type, int track, int id, int entity, int data)
1475+
{
1476+
if (type == Zone_Start && track == Shavit_GetClientTrack(client))
1477+
{
1478+
gF_ZoneStartSpeedLimit[client] = float(data);
1479+
}
1480+
}
1481+
14311482
public void OnClientPutInServer(int client)
14321483
{
14331484
SDKHook(client, SDKHook_SetTransmit, OnSetTransmit);
@@ -1439,6 +1490,7 @@ public void OnClientPutInServer(int client)
14391490

14401491
gI_LastWeaponTick[client] = 0;
14411492
gI_LastNoclipTick[client] = 0;
1493+
gI_LastGroundLandTick[client] = 0;
14421494

14431495
if(IsFakeClient(client))
14441496
{
@@ -2290,8 +2342,22 @@ public Action Shavit_OnStartPre(int client, int track, bool& skipGroundTimer)
22902342
GetEntPropVector(client, Prop_Data, "m_vecAbsVelocity", fSpeed);
22912343

22922344
float fLimit = (Shavit_GetStyleSettingFloat(gI_Style[client], "runspeed") + gCV_PrestrafeLimit.FloatValue);
2345+
float cfgLimit = Shavit_GetStyleSettingFloat(gI_Style[client], "maxprestrafe");
2346+
float zoneLimit = gF_ZoneStartSpeedLimit[client];
22932347
float maxPrestrafe = StyleMaxPrestrafe(gI_Style[client]);
2294-
if (fLimit > maxPrestrafe) fLimit = maxPrestrafe;
2348+
2349+
if (zoneLimit > 0.0)
2350+
{
2351+
fLimit = zoneLimit;
2352+
}
2353+
else if (cfgLimit > 0.0)
2354+
{
2355+
fLimit = cfgLimit;
2356+
}
2357+
else if (fLimit > maxPrestrafe)
2358+
{
2359+
fLimit = maxPrestrafe;
2360+
}
22952361

22962362
// if trying to jump, add a very low limit to stop prespeeding in an elegant way
22972363
// otherwise, make sure nothing weird is happening (such as sliding at ridiculous speeds, at zone enter)
@@ -2305,7 +2371,7 @@ public Action Shavit_OnStartPre(int client, int track, bool& skipGroundTimer)
23052371

23062372
if(fScale < 1.0)
23072373
{
2308-
if (prespeed_type == 5)
2374+
if (prespeed_type == 5 || prespeed_type == 6)
23092375
{
23102376
float zSpeed = fSpeed[2];
23112377
fSpeed[2] = 0.0;

addons/sourcemod/scripting/shavit-zones.sp

+14-1
Original file line numberDiff line numberDiff line change
@@ -4406,7 +4406,20 @@ void CreateEditMenu(int client, bool autostage=false)
44064406
FormatEx(sMenuItem, 64, "%T", "ZoneForceRender", client, ((gA_EditCache[client].iFlags & ZF_ForceRender) > 0)? "":"");
44074407
menu.AddItem("forcerender", sMenuItem);
44084408

4409-
if (gA_EditCache[client].iType == Zone_Stage)
4409+
if (gA_EditCache[client].iType == Zone_Start)
4410+
{
4411+
if (gA_EditCache[client].iData == 0)
4412+
{
4413+
FormatEx(sMenuItem, 64, "%T", "ZoneSetSpeedLimitDefault", client, gA_EditCache[client].iData);
4414+
}
4415+
else
4416+
{
4417+
FormatEx(sMenuItem, 64, "%T", "ZoneSetSpeedLimit", client, gA_EditCache[client].iData);
4418+
}
4419+
4420+
menu.AddItem("datafromchat", sMenuItem);
4421+
}
4422+
else if (gA_EditCache[client].iType == Zone_Stage)
44104423
{
44114424
if (autostage)
44124425
{

addons/sourcemod/translations/shavit-zones.phrases.txt

+5
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,11 @@
260260
"#format" "{1:d}"
261261
"en" "Custom speed limit: {1} (No Limit)"
262262
}
263+
"ZoneSetSpeedLimitDefault"
264+
{
265+
"#format" "{1:d}"
266+
"en" "Custom speed limit: {1} (Default Speedcap)"
267+
}
263268
"ZoneSetStage"
264269
{
265270
"#format" "{1:d}"

0 commit comments

Comments
 (0)