Merge branch 'master' into dev

This commit is contained in:
shavit 2016-10-03 11:06:52 +03:00 committed by GitHub
commit 62c00c2974
3 changed files with 268 additions and 6 deletions

View File

@ -23,6 +23,7 @@ a bhop server should be simple
* [The RTLer](https://forums.alliedmods.net/showthread.php?p=1649882) - required for properly formatted RTL text within `shavit-chat`.
* [Chat-Processor](https://forums.alliedmods.net/showthread.php?t=286913) - for more proper parsing inside `shavit-chat`.
* `sv_disable_immunity_alpha` set to 1 in CS:GO for `shavit_misc_playeropacity` to work.
* [Bunnyhop Statistics](https://forums.alliedmods.net/showthread.php?t=286135) - to show amount of scrolls for non-auto styles in the key display.
# Installation:
1. If you want to use MySQL (**VERY RECOMMENDED**) add a database entry in addons/sourcemod/configs/databases.cfg, call it "shavit". The plugin also supports the "sqlite" driver. You can also skip this step and not modify databases.cfg.

View File

@ -0,0 +1,215 @@
/*
* Bunnyhop Statistics API - Include file
* by: shavit
*
* This file is part of Bunnyhop Statistics API.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#if defined _bhopstats_included
#endinput
#endif
#define _bhopstats_included
#define BHOPSTATS_VERSION "1.2.0"
enum CheatType(+=1)
{
Cheat_HighPerfects = 0,
Cheat_Auto,
Cheat_JumpSpam
};
/**
* Called when the jump key is pressed.
*
* @param client Client index.
* @param onground True if the jump key will do anything for the player when tapped.
* @param perfcct Was the jump perfectly timed?
* @noreturn
*/
forward void Bunnyhop_OnJumpPressed(int client, bool onground, bool perfect);
/**
* Called when the jump key is released.
*
* @param client Client index.
* @param onground True if the jump key will do anything for the player when tapped.
* @noreturn
*/
forward void Bunnyhop_OnJumpReleased(int client, bool onground);
/**
* Called when the player touches the ground.
*
* @param client Client index.
* @noreturn
*/
forward void Bunnyhop_OnTouchGround(int client);
/**
* Called when the player leaves the ground, by either jumping or falling from somewhere.
* AKA the HookEventless better version of player_jump.
* The `jumped` variable is true if the ground was left by tapping the jump key, or false if the player fell from somewhere.
* `ladder` is true if the player left the 'ground' from a ladder.
*
* @param client Client index.
* @param jumped Did the client leave the ground by jumping?
* @param ladder Did the client leave the ground by leaving a ladder, aka ladderstrafing?
* @noreturn
*/
forward void Bunnyhop_OnLeaveGround(int client, bool jumped, bool ladder);
/**
* Retrieves the amount of separate +jump inputs since the player left the ground.
*
* @param client Client index.
* @return Amount of +jump inputs since the left the ground, or 0 if the player is on ground.
*/
native int Bunnyhop_GetScrollCount(int client);
/**
* Checks if the player is on ground, or if the jump key will function as in actually triggering a jump or altering velocity.
* The result will be true if the player is on a ladder or in water, as jumping will be functional.
*
* @param client Client index.
* @return Boolean value of 'is the player on ground?'
*/
native bool Bunnyhop_IsOnGround(int client);
/**
* Checks if the player is holding his jump key.
*
* @param client Client index.
* @return Boolean value of 'is the player holding the jump key?''
*/
native bool Bunnyhop_IsHoldingJump(int client);
/**
* Gets a percentage of perfectly timed bunnyhops.
* Resets at player connection or the Bunnyhop_ResetPerfectJumps native for it is called.
*
* @param client Client index.
* @return Perfect jump percentage. Results are from 0.0 to 100.0.
*/
native float Bunnyhop_GetPerfectJumps(int client);
/**
* Resets the perfect jumps percentage of a player back to 0.0.
*
* @param client Client index.
* @noreturn
*/
native void Bunnyhop_ResetPerfectJumps(int client);
methodmap BunnyhopStats __nullable__
{
public BunnyhopStats(int client)
{
return view_as<BunnyhopStats>(client);
}
property int index
{
public get()
{
return view_as<int>(this);
}
}
property int ScrollCount
{
public get()
{
return Bunnyhop_GetScrollCount(this.index);
}
}
property bool OnGround
{
public get()
{
return Bunnyhop_IsOnGround(this.index);
}
}
property bool HoldingJump
{
public get()
{
return Bunnyhop_IsHoldingJump(this.index);
}
}
property float PerfectJumps
{
public get()
{
return Bunnyhop_GetPerfectJumps(this.index);
}
}
public void ResetPrefects()
{
Bunnyhop_ResetPerfectJumps(this.index);
}
public static int GetScrollCount(int client)
{
return Bunnyhop_GetScrollCount(client);
}
public static bool IsOnGround(int client)
{
return Bunnyhop_IsOnGround(client);
}
public static bool IsHoldingJump(int client)
{
return Bunnyhop_IsHoldingJump(client);
}
public static float GetPerfectJumps(int client)
{
return Bunnyhop_GetPerfectJumps(client);
}
public static float ResetPrefectJumps(int client)
{
return Bunnyhop_ResetPerfectJumps(client);
}
}
public SharedPlugin __pl_bhopstats =
{
name = "bhopstats",
file = "bhopstats.smx",
#if defined REQUIRE_PLUGIN
required = 1
#else
required = 0
#endif
};
#if !defined REQUIRE_PLUGIN
public void __pl_bhopstats_SetNTVOptional()
{
MarkNativeAsOptional("Bunnyhop_GetScrollCount");
MarkNativeAsOptional("Bunnyhop_IsOnGround");
MarkNativeAsOptional("Bunnyhop_IsHoldingJump");
MarkNativeAsOptional("Bunnyhop_GetPerfectJumps");
MarkNativeAsOptional("Bunnyhop_ResetPerfectJumps");
}
#endif

View File

@ -23,6 +23,7 @@
#undef REQUIRE_PLUGIN
#include <shavit>
#include <bhopstats>
#pragma newdecls required
#pragma semicolon 1
@ -49,6 +50,7 @@ EngineVersion gEV_Type = Engine_Unknown;
// modules
bool gB_Replay = false;
bool gB_Zones = false;
bool gB_BhopStats = false;
// zone colors
char gS_StartColors[][] =
@ -67,6 +69,8 @@ int gI_Cycle = 0;
Handle gH_HUDCookie = null;
int gI_HUDSettings[MAXPLAYERS+1];
int gI_NameLength = MAX_NAME_LENGTH;
int gI_LastScrollCount[MAXPLAYERS+1];
int gI_ScrollCount[MAXPLAYERS+1];
bool gB_Late = false;
@ -118,6 +122,7 @@ public void OnPluginStart()
// prevent errors in case the replay bot isn't loaded
gB_Replay = LibraryExists("shavit-replay");
gB_Zones = LibraryExists("shavit-zones");
gB_BhopStats = LibraryExists("bhopstats");
// cron
CreateTimer(0.10, UpdateHUD_Timer, INVALID_HANDLE, TIMER_REPEAT);
@ -165,6 +170,12 @@ public void Shavit_OnStyleConfigLoaded(int styles)
gI_Styles = styles;
}
public void OnClientPutInServer(int client)
{
gI_LastScrollCount[client] = 0;
gI_ScrollCount[client] = 0;
}
public void OnClientCookiesCached(int client)
{
char[] sHUDSettings = new char[8];
@ -289,6 +300,11 @@ public void OnLibraryAdded(const char[] name)
{
gB_Zones = true;
}
else if(StrEqual(name, "bhopstats"))
{
gB_BhopStats = true;
}
}
public void OnLibraryRemoved(const char[] name)
@ -302,6 +318,11 @@ public void OnLibraryRemoved(const char[] name)
{
gB_Zones = false;
}
else if(StrEqual(name, "bhopstats"))
{
gB_BhopStats = false;
}
}
public void OnConfigsExecuted()
@ -612,6 +633,29 @@ public void UpdateKeyOverlay(int client, Panel panel, bool &draw)
draw = true;
}
public void Bunnyhop_OnTouchGround(int client)
{
gI_LastScrollCount[client] = BunnyhopStats.GetScrollCount(client);
}
public void Bunnyhop_OnJumpPressed(int client)
{
gI_ScrollCount[client] = BunnyhopStats.GetScrollCount(client);
if(gA_StyleSettings[Shavit_GetBhopStyle(client)][bAutobhop] || gEV_Type != Engine_CSS)
{
return;
}
for(int i = 1; i <= MaxClients; i++)
{
if(i == client || (IsValidClient(i) && GetHUDTarget(i) == client))
{
UpdateCenterKeys(i);
}
}
}
public void UpdateCenterKeys(int client)
{
if((gI_HUDSettings[client] & HUD_KEYOVERLAY) == 0)
@ -628,15 +672,17 @@ public void UpdateCenterKeys(int client)
int buttons = GetClientButtons(target);
if(gA_StyleSettings[Shavit_GetBhopStyle(target)][bAutobhop]) // don't include [JUMP] for autobhop styles
char[] sCenterText = new char[64];
FormatEx(sCenterText, 64, "%s %s %s\n%s %s %s",
(buttons & IN_DUCK > 0)? "C":"-", (buttons & IN_FORWARD > 0)? "W":"-", (buttons & IN_JUMP > 0)? "J":"-",
(buttons & IN_MOVELEFT > 0)? "A":"-", (buttons & IN_BACK > 0)? "S":"-", (buttons & IN_MOVERIGHT > 0)? "D":"-");
if(gB_BhopStats && !gA_StyleSettings[Shavit_GetBhopStyle(target)][bAutobhop])
{
PrintCenterText(client, "[%s]\n %s\n%s %s %s", (buttons & IN_DUCK) > 0? "DUCK":"----", (buttons & IN_FORWARD) > 0? "W":"-", (buttons & IN_MOVELEFT) > 0? "A":"-", (buttons & IN_BACK) > 0? "S":"-", (buttons & IN_MOVERIGHT) > 0? "D":"-");
Format(sCenterText, 64, "%s\n%d %d", sCenterText, gI_ScrollCount[client], gI_LastScrollCount[target]);
}
else
{
PrintCenterText(client, "[%s] [%s]\n %s\n%s %s %s", (buttons & IN_JUMP) > 0? "JUMP":"----", (buttons & IN_DUCK) > 0? "DUCK":"----", (buttons & IN_FORWARD) > 0? "W":"-", (buttons & IN_MOVELEFT) > 0? "A":"-", (buttons & IN_BACK) > 0? "S":"-", (buttons & IN_MOVERIGHT) > 0? "D":"-");
}
PrintCenterText(client, "%s", sCenterText);
}
public void UpdateSpectatorList(int client, Panel panel, bool &draw)