Skip to content

Commit

Permalink
Add sv_autobunnyhopping support for CS:GO (#277)
Browse files Browse the repository at this point in the history
  • Loading branch information
shavitush committed Oct 14, 2016
1 parent ba65c8f commit bcf690e
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 24 deletions.
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ General
- [x] Migrate ADT_Arrays to ArrayList.
- [x] Support "out of the box" installations and SQLite support.
- [x] Implement a config file for styles and use Dynamic to load them, add Shavit_OnStylesLoaded and caching natives.
- [ ] Save timer variables on Dynamic's per-player settings.
- [ ] Add support for multiple tracks (main/bonus etc).

Core
--
Expand All @@ -99,7 +99,6 @@ Core
- [x] Add `lastlogin` column to `users`.
- [x] Allow late loading by adding Shavit_OnDatabaseLoaded() and get the new database handle in modules.
- [x] Add style changing commands (config file).
- [ ] Add bonus timer.

HUD
--
Expand All @@ -115,7 +114,7 @@ HUD
- [x] Add potential map rank.
- [x] Add strafes/sync. (replace 'Player' with strafes and sync in csgo, use keyhinttext for sync in css)
- [x] Show 'time left' to HUD (CS:S only).
- [ ] Support for bonus timer.
- [ ] Support for multiple tracks.

Replay
--
Expand All @@ -126,7 +125,7 @@ Replay
- [x] Make replay bots dead if there's no replay data loaded.
- [x] Clear player cache on spawn/death.
- [x] Add admin interface. (delete replay data, `sm_deletereplay` for RCON admins.
- [ ] Bonus replay for default style.
- [ ] Support for multiple tracks and styles.

Stats
--
Expand Down Expand Up @@ -208,7 +207,7 @@ Chat **(NEW!)**

Zones
--
- [x] Add teleport zones (multiple). Use the command `sm_tpzone` between the time of setting the zone and confirming the setup.
- [x] Add teleport zones (multiple). ~~Use the command `sm_tpzone` between the time of setting the zone and confirming the setup.~~ made them very easy to setup!
- [x] Use string explosion in ZoneAdjuster_Handler and ZoneEdge_Handler for code efficiency.
- [x] CANCELED: Migrate zone settings to use Dynamic. (i didn't think *too* far into it before i started)
- [x] Handle teleport zones. (teleport to a value from gV_Teleport)
Expand All @@ -232,7 +231,7 @@ World Records
- [x] Add strafes/sync to the WR menu where available.
- [x] Add 'player stats' to submenu.
- [x] Grab points from `playertimes` instead of calculating on the fly.
- [ ] Add `sm_bwr` `sm_bonuswr` `sm_bonusworldrecord`.
- [ ] Support multiple tracks.

Time Limits
--
Expand Down
61 changes: 45 additions & 16 deletions scripting/shavit-core.sp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ char gS_MySQLPrefix[32];

// server side
ConVar sv_airaccelerate = null;
ConVar sv_autobunnyhopping = null;

// timer settings
bool gB_Registered = false;
Expand Down Expand Up @@ -194,6 +195,9 @@ public void OnPluginStart()
{
gSG_Type = Game_CSGO;
gF_HSW_Requirement = 449.00;

sv_autobunnyhopping = FindConVar("sv_autobunnyhopping");
sv_autobunnyhopping.Flags &= ~FCVAR_NOTIFY;
}

else
Expand Down Expand Up @@ -940,6 +944,11 @@ public void OnClientDisconnect(int client)

public void OnClientCookiesCached(int client)
{
if(IsFakeClient(client))
{
return;
}

char[] sCookie = new char[4];
GetClientCookie(client, gH_AutoBhopCookie, sCookie, 4);
gB_Auto[client] = (strlen(sCookie) > 0)? view_as<bool>(StringToInt(sCookie)):true;
Expand All @@ -950,10 +959,15 @@ public void OnClientCookiesCached(int client)

public void OnClientPutInServer(int client)
{
StopTimer(client);

if(IsFakeClient(client))
{
return;
}

gB_Auto[client] = true;
gBS_Style[client] = view_as<BhopStyle>(0);

StopTimer(client);
gB_DoubleSteps[client] = false;
gF_StrafeWarning[client] = 0.0;

Expand All @@ -962,7 +976,7 @@ public void OnClientPutInServer(int client)
OnClientCookiesCached(client);
}

if(gH_SQL == null || !IsValidClient(client) || IsFakeClient(client))
if(gH_SQL == null)
{
return;
}
Expand Down Expand Up @@ -1295,6 +1309,7 @@ public void PreThink(int client)
if(IsPlayerAlive(client))
{
sv_airaccelerate.IntValue = gA_StyleSettings[gBS_Style[client]][iAiraccelerate];
UpdateAutobhop(client);
}
}

Expand Down Expand Up @@ -1403,28 +1418,32 @@ public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float vel[3
gI_Strafes[client]++;
}

// autobhop
if(gA_StyleSettings[gBS_Style[client]][bAutobhop] && gB_Autobhop && gB_Auto[client])
// autobhop for cs:s
// cs:go has a built-in autobhop cvar
if(gEV_Type == Engine_CSS)
{
bool bInWater = (GetEntProp(client, Prop_Send, "m_nWaterLevel") >= 2);
bool bOnLadder = (GetEntityMoveType(client) == MOVETYPE_LADDER);

if((buttons & IN_JUMP) > 0 && iGroundEntity == -1 && !bOnLadder && !bInWater)
if(gA_StyleSettings[gBS_Style[client]][bAutobhop] && gB_Autobhop && gB_Auto[client])
{
buttons &= ~IN_JUMP;
bool bInWater = (GetEntProp(client, Prop_Send, "m_nWaterLevel") >= 2);
bool bOnLadder = (GetEntityMoveType(client) == MOVETYPE_LADDER);

if((buttons & IN_JUMP) > 0 && iGroundEntity == -1 && !bOnLadder && !bInWater)
{
buttons &= ~IN_JUMP;
}

else if(gB_DoubleSteps[client] && (iGroundEntity != -1 || bOnLadder || bInWater))
{
buttons |= IN_JUMP;
}
}

else if(gB_DoubleSteps[client] && (iGroundEntity != -1 || bOnLadder || bInWater))
else if(gB_DoubleSteps[client])
{
buttons |= IN_JUMP;
}
}

else if(gB_DoubleSteps[client])
{
buttons |= IN_JUMP;
}

if(bInStart && gB_BlockPreJump && !gA_StyleSettings[gBS_Style[client]][bPrespeed] && (vel[2] > 0 || (buttons & IN_JUMP) > 0))
{
vel[2] = 0.0;
Expand Down Expand Up @@ -1525,3 +1544,13 @@ public bool Inconsistency(const float[] vel, const int buttons)
{
return ((vel[0] > 0.0 && (buttons & IN_FORWARD) == 0) || (vel[0] < 0.0 && (buttons & IN_BACK) == 0) || (vel[1] < 0.0 && (buttons & IN_MOVELEFT) == 0) || (vel[1] > 0.0 && (buttons & IN_MOVERIGHT) == 0));
}

public void UpdateAutobhop(int client)
{
if(gEV_Type != Engine_CSGO || sv_autobunnyhopping == null)
{
return;
}

sv_autobunnyhopping.BoolValue = (gA_StyleSettings[gBS_Style[client]][bAutobhop] && gB_Autobhop && gB_Auto[client]);
}
3 changes: 1 addition & 2 deletions scripting/shavit-misc.sp
Original file line number Diff line number Diff line change
Expand Up @@ -1222,8 +1222,7 @@ public void RestartTimer(int client)

public void Player_Spawn(Event event, const char[] name, bool dontBroadcast)
{
int userid = event.GetInt("userid");
int client = GetClientOfUserId(userid);
int client = GetClientOfUserId(event.GetInt("userid"));

if(gB_HideRadar)
{
Expand Down

0 comments on commit bcf690e

Please sign in to comment.