LagCompensation: per client toggle
This commit is contained in:
parent
a7ecd549cd
commit
7c23a2c6e8
@ -3,6 +3,8 @@
|
||||
#include <sdktools>
|
||||
#include <PhysHooks>
|
||||
#include <dhooks>
|
||||
#include <clientprefs>
|
||||
#include <multicolors>
|
||||
|
||||
#define SetBit(%1,%2) ((%1)[(%2) >> 5] |= (1 << ((%2) & 31)))
|
||||
#define ClearBit(%1,%2) ((%1)[(%2) >> 5] &= ~(1 << ((%2) & 31)))
|
||||
@ -139,8 +141,18 @@ int g_aaFilterClientSolidTouch[((MAXPLAYERS + 1) * MAX_EDICTS) / 32];
|
||||
int g_aBlockTriggerMoved[MAX_EDICTS / 32];
|
||||
int g_aBlacklisted[MAX_EDICTS / 32];
|
||||
|
||||
Handle g_hCookie_DisableLagComp;
|
||||
bool g_bDisableLagComp[MAXPLAYERS+1];
|
||||
int g_iLastCommandUsed[MAXPLAYERS+1];
|
||||
|
||||
public void OnPluginStart()
|
||||
{
|
||||
g_hCookie_DisableLagComp = RegClientCookie("disable_lagcomp", "", CookieAccess_Private);
|
||||
RegConsoleCmd("sm_lagcomp", OnToggleLagCompSettings);
|
||||
RegConsoleCmd("sm_ping", OnToggleLagCompSettings);
|
||||
RegConsoleCmd("sm_0ping", OnToggleLagCompSettings);
|
||||
SetCookieMenuItem(MenuHandler_CookieMenu, 0, "LagCompensation");
|
||||
|
||||
Handle hGameData = LoadGameConfigFile("LagCompensation.games");
|
||||
if(!hGameData)
|
||||
SetFailState("Failed to load LagCompensation gamedata.");
|
||||
@ -336,6 +348,12 @@ public void OnMapStart()
|
||||
/* Late Load */
|
||||
if(bLate)
|
||||
{
|
||||
for (int i = 1; i <= MaxClients; i++)
|
||||
{
|
||||
if (IsValidClient(i) && AreClientCookiesCached(i))
|
||||
OnClientCookiesCached(i);
|
||||
}
|
||||
|
||||
int entity = INVALID_ENT_REFERENCE;
|
||||
while((entity = FindEntityByClassname(entity, "*")) != INVALID_ENT_REFERENCE)
|
||||
{
|
||||
@ -745,6 +763,9 @@ public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float vel[3
|
||||
if(!IsPlayerAlive(client))
|
||||
return Plugin_Continue;
|
||||
|
||||
if(g_bDisableLagComp[client])
|
||||
return Plugin_Continue;
|
||||
|
||||
// -1 because the newest record in the list is one tick old
|
||||
// this is because we simulate players first
|
||||
// hence no new entity record was inserted on the current tick
|
||||
@ -1225,3 +1246,108 @@ stock void PrintToBoth(const char[] format, any ...)
|
||||
}
|
||||
}
|
||||
}
|
||||
public void OnClientCookiesCached(int client)
|
||||
{
|
||||
char sBuffer[16];
|
||||
GetClientCookie(client, g_hCookie_DisableLagComp, sBuffer, sizeof(sBuffer));
|
||||
if (sBuffer[0])
|
||||
g_bDisableLagComp[client] = true;
|
||||
else
|
||||
g_bDisableLagComp[client] = false;
|
||||
}
|
||||
|
||||
public void OnClientDisconnect(int client)
|
||||
{
|
||||
g_bDisableLagComp[client] = false;
|
||||
}
|
||||
|
||||
public Action OnLagCompSettings(int client, int args)
|
||||
{
|
||||
ShowSettingsMenu(client);
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action OnToggleLagCompSettings(int client, int args)
|
||||
{
|
||||
ToggleLagCompSettings(client);
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public void ToggleLagCompSettings(int client)
|
||||
{
|
||||
int iTimeSinceLastCommand = GetTime() - g_iLastCommandUsed[client];
|
||||
if (iTimeSinceLastCommand < 10)
|
||||
{
|
||||
CPrintToChat(client, "{cyan}[LagCompensation] {white}You need to wait {red}%d seconds {white}to toggle this setting again!", 10 - iTimeSinceLastCommand);
|
||||
return;
|
||||
}
|
||||
|
||||
g_bDisableLagComp[client] = !g_bDisableLagComp[client];
|
||||
SetClientCookie(client, g_hCookie_DisableLagComp, g_bDisableLagComp[client] ? "1" : "");
|
||||
|
||||
CPrintToChat(client, "{cyan}[LagCompensation] {white}%s.", g_bDisableLagComp[client] ? "LagCompensation Disabled" : "LagCompensation Enabled");
|
||||
g_iLastCommandUsed[client] = GetTime();
|
||||
}
|
||||
|
||||
public void ShowSettingsMenu(int client)
|
||||
{
|
||||
Menu menu = new Menu(MenuHandler_MainMenu);
|
||||
|
||||
menu.SetTitle("LagCompensation Settings", client);
|
||||
|
||||
char sBuffer[128];
|
||||
|
||||
Format(sBuffer, sizeof(sBuffer), "LagCompensation: %s", g_bDisableLagComp[client] ? "Disabled" : "Enabled");
|
||||
menu.AddItem("0", sBuffer);
|
||||
|
||||
menu.ExitBackButton = true;
|
||||
|
||||
menu.Display(client, MENU_TIME_FOREVER);
|
||||
}
|
||||
|
||||
public void MenuHandler_CookieMenu(int client, CookieMenuAction action, any info, char[] buffer, int maxlen)
|
||||
{
|
||||
switch(action)
|
||||
{
|
||||
case(CookieMenuAction_DisplayOption):
|
||||
{
|
||||
Format(buffer, maxlen, "LagCompensation", client);
|
||||
}
|
||||
case(CookieMenuAction_SelectOption):
|
||||
{
|
||||
ShowSettingsMenu(client);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int MenuHandler_MainMenu(Menu menu, MenuAction action, int client, int selection)
|
||||
{
|
||||
switch(action)
|
||||
{
|
||||
case(MenuAction_Select):
|
||||
{
|
||||
switch(selection)
|
||||
{
|
||||
case(0): ToggleLagCompSettings(client);
|
||||
}
|
||||
|
||||
ShowSettingsMenu(client);
|
||||
}
|
||||
case(MenuAction_Cancel):
|
||||
{
|
||||
ShowCookieMenu(client);
|
||||
}
|
||||
case(MenuAction_End):
|
||||
{
|
||||
delete menu;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stock int IsValidClient(int client, bool nobots = true)
|
||||
{
|
||||
if (client <= 0 || client > MaxClients || !IsClientConnected(client) || (nobots && IsFakeClient(client)))
|
||||
return false;
|
||||
|
||||
return IsClientInGame(client);
|
||||
}
|
Loading…
Reference in New Issue
Block a user