SelectiveBhop: Add natives and !bhop admin command
This commit is contained in:
parent
5ce7c627e0
commit
051348fb71
@ -7,6 +7,7 @@
|
||||
#undef REQUIRE_PLUGIN
|
||||
#include <zombiereloaded>
|
||||
#define REQUIRE_PLUGIN
|
||||
#include <SelectiveBhop>
|
||||
|
||||
ConVar g_CVar_sv_enablebunnyhopping;
|
||||
ConVar g_CVar_zr_disablebunnyhopping;
|
||||
@ -15,6 +16,8 @@ enum
|
||||
{
|
||||
LIMITED_NONE = 0,
|
||||
LIMITED_GENERAL = 1,
|
||||
|
||||
// Temp
|
||||
LIMITED_ZOMBIE = 2
|
||||
}
|
||||
|
||||
@ -25,6 +28,8 @@ bool g_bInOnPlayerRunCmd = false;
|
||||
int g_ClientLimited[MAXPLAYERS + 1] = {LIMITED_NONE, ...};
|
||||
int g_ActiveLimitedFlags = LIMITED_GENERAL;
|
||||
|
||||
StringMap g_ClientLimitedCache;
|
||||
|
||||
public Plugin myinfo =
|
||||
{
|
||||
name = "Selective Bunnyhop",
|
||||
@ -35,6 +40,8 @@ public Plugin myinfo =
|
||||
|
||||
public void OnPluginStart()
|
||||
{
|
||||
LoadTranslations("common.phrases");
|
||||
|
||||
g_CVar_sv_enablebunnyhopping = FindConVar("sv_enablebunnyhopping");
|
||||
g_CVar_sv_enablebunnyhopping.Flags &= ~FCVAR_REPLICATED;
|
||||
g_CVar_sv_enablebunnyhopping.AddChangeHook(OnConVarChanged);
|
||||
@ -44,8 +51,12 @@ public void OnPluginStart()
|
||||
g_CVar_zr_disablebunnyhopping.AddChangeHook(OnConVarChanged);
|
||||
g_bZombieEnabled = g_CVar_zr_disablebunnyhopping.BoolValue;
|
||||
|
||||
g_ClientLimitedCache = new StringMap();
|
||||
|
||||
HookEvent("round_start", Event_RoundStart, EventHookMode_PostNoCopy);
|
||||
|
||||
RegAdminCmd("sm_bhop", Command_Bhop, ADMFLAG_GENERIC, "sm_bhop <#userid|name> <0|1>");
|
||||
|
||||
/* Late load */
|
||||
for(int i = 1; i <= MaxClients; i++)
|
||||
{
|
||||
@ -60,9 +71,13 @@ public void OnPluginStart()
|
||||
UpdateClients();
|
||||
}
|
||||
|
||||
public void OnClientPutInServer(int client)
|
||||
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
|
||||
{
|
||||
TransmitConVar(client);
|
||||
CreateNative("LimitBhop", Native_LimitBhop);
|
||||
CreateNative("IsBhopLimited", Native_IsBhopLimited);
|
||||
RegPluginLibrary("SelectiveBhop");
|
||||
|
||||
return APLRes_Success;
|
||||
}
|
||||
|
||||
public void OnPluginEnd()
|
||||
@ -82,6 +97,45 @@ public void OnPluginEnd()
|
||||
}
|
||||
}
|
||||
|
||||
public void OnMapEnd()
|
||||
{
|
||||
g_ClientLimitedCache.Clear();
|
||||
}
|
||||
|
||||
public void OnClientPutInServer(int client)
|
||||
{
|
||||
TransmitConVar(client);
|
||||
}
|
||||
|
||||
public void OnClientDisconnect(int client)
|
||||
{
|
||||
// Remove temp
|
||||
int LimitedFlag = g_ClientLimited[client] & ~(LIMITED_ZOMBIE);
|
||||
|
||||
if(LimitedFlag != LIMITED_NONE)
|
||||
{
|
||||
char sSteamID[64];
|
||||
if(GetClientAuthId(client, AuthId_Engine, sSteamID, sizeof(sSteamID)))
|
||||
g_ClientLimitedCache.SetValue(sSteamID, LimitedFlag, true);
|
||||
}
|
||||
|
||||
g_ClientLimited[client] = LIMITED_NONE;
|
||||
}
|
||||
|
||||
public void OnClientPostAdminCheck(int client)
|
||||
{
|
||||
char sSteamID[64];
|
||||
if(GetClientAuthId(client, AuthId_Engine, sSteamID, sizeof(sSteamID)))
|
||||
{
|
||||
int LimitedFlag;
|
||||
if(g_ClientLimitedCache.GetValue(sSteamID, LimitedFlag))
|
||||
{
|
||||
AddLimitedFlag(client, LimitedFlag);
|
||||
g_ClientLimitedCache.Remove(sSteamID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnConVarChanged(ConVar convar, const char[] oldValue, const char[] newValue)
|
||||
{
|
||||
if(convar == g_CVar_sv_enablebunnyhopping)
|
||||
@ -230,3 +284,94 @@ stock void TransmitConVar(int client)
|
||||
else
|
||||
g_CVar_sv_enablebunnyhopping.ReplicateToClient(client, "0");
|
||||
}
|
||||
|
||||
public Action Command_Bhop(int client, int argc)
|
||||
{
|
||||
if(argc < 2)
|
||||
{
|
||||
ReplyToCommand(client, "[SM] Usage: sm_bhop <#userid|name> <0|1>");
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
char sArg[64];
|
||||
char sArg2[2];
|
||||
char sTargetName[MAX_TARGET_LENGTH];
|
||||
int iTargets[MAXPLAYERS];
|
||||
int iTargetCount;
|
||||
bool bIsML;
|
||||
bool bValue;
|
||||
|
||||
GetCmdArg(1, sArg, sizeof(sArg));
|
||||
GetCmdArg(2, sArg2, sizeof(sArg2));
|
||||
|
||||
bValue = sArg2[0] == '1' ? true : false;
|
||||
|
||||
if((iTargetCount = ProcessTargetString(sArg, client, iTargets, MAXPLAYERS, COMMAND_FILTER_NO_MULTI, sTargetName, sizeof(sTargetName), bIsML)) <= 0)
|
||||
{
|
||||
ReplyToTargetError(client, iTargetCount);
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
for(int i = 0; i < iTargetCount; i++)
|
||||
{
|
||||
if(bValue)
|
||||
RemoveLimitedFlag(iTargets[i], LIMITED_GENERAL);
|
||||
else
|
||||
AddLimitedFlag(iTargets[i], LIMITED_GENERAL);
|
||||
}
|
||||
|
||||
ShowActivity2(client, "\x01[SM] \x04", "\x01\x04%s\x01 bunnyhop on target \x04%s", bValue ? "Un-limited" : "Limited", sTargetName);
|
||||
|
||||
if(iTargetCount > 1)
|
||||
LogAction(client, -1, "\"%L\" %s bunnyhop on target \"%s\"", client, bValue ? "Un-limited" : "Limited", sTargetName);
|
||||
else
|
||||
LogAction(client, iTargets[0], "\"%L\" %s bunnyhop on target \"%L\"", client, bValue ? "Un-limited" : "Limited", iTargets[0]);
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public int Native_LimitBhop(Handle plugin, int numParams)
|
||||
{
|
||||
int client = GetNativeCell(1);
|
||||
bool bLimited = view_as<bool>(GetNativeCell(2));
|
||||
|
||||
if(client > MaxClients || client <= 0)
|
||||
{
|
||||
ThrowNativeError(SP_ERROR_NATIVE, "Client is not valid.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(!IsClientInGame(client))
|
||||
{
|
||||
ThrowNativeError(SP_ERROR_NATIVE, "Client is not in-game.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(bLimited)
|
||||
AddLimitedFlag(client, LIMITED_GENERAL);
|
||||
else
|
||||
RemoveLimitedFlag(client, LIMITED_GENERAL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int Native_IsBhopLimited(Handle plugin, int numParams)
|
||||
{
|
||||
int client = GetNativeCell(1);
|
||||
|
||||
if(client > MaxClients || client <= 0)
|
||||
{
|
||||
ThrowNativeError(SP_ERROR_NATIVE, "Client is not valid.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(!IsClientInGame(client))
|
||||
{
|
||||
ThrowNativeError(SP_ERROR_NATIVE, "Client is not in-game.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
int LimitedFlag = g_ClientLimited[client] & ~(LIMITED_ZOMBIE);
|
||||
|
||||
return LimitedFlag != LIMITED_NONE;
|
||||
}
|
||||
|
26
SelectiveBhop/scripting/include/SelectiveBhop.inc
Normal file
26
SelectiveBhop/scripting/include/SelectiveBhop.inc
Normal file
@ -0,0 +1,26 @@
|
||||
#if defined _SelectiveBhop_Included
|
||||
#endinput
|
||||
#endif
|
||||
#define _SelectiveBhop_Included
|
||||
|
||||
native int LimitBhop(int client, bool bLimited);
|
||||
native int IsBhopLimited(int client);
|
||||
|
||||
public SharedPlugin __pl_SelectiveBhop =
|
||||
{
|
||||
name = "SelectiveBhop",
|
||||
file = "SelectiveBhop.smx",
|
||||
#if defined REQUIRE_PLUGIN
|
||||
required = 1,
|
||||
#else
|
||||
required = 0,
|
||||
#endif
|
||||
};
|
||||
|
||||
#if !defined REQUIRE_PLUGIN
|
||||
public __pl_SelectiveBhop_SetNTVOptional()
|
||||
{
|
||||
MarkNativeAsOptional("LimitBhop");
|
||||
MarkNativeAsOptional("IsBhopLimited");
|
||||
}
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user