Started using Atom - let it auto indent everything.

This commit is contained in:
shavitush 2016-03-07 16:14:21 +02:00
parent da1438f379
commit e04243592d
13 changed files with 476 additions and 476 deletions

2
.gitignore vendored
View File

@ -1,4 +1,4 @@
# SourcePawn # SourcePawn
*.smx *.smx
*.dll *.dll
*.so *.so

View File

@ -21,4 +21,4 @@
- [x] + player slaying zone - [x] + player slaying zone
- [x] + cvar "shavit_zones_style" - [x] + cvar "shavit_zones_style"
0 - 3d (default) 0 - 3d (default)
1 - 2d 1 - 2d

View File

@ -8,4 +8,4 @@
- [x] + Allow creation of freestyle zones - [x] + Allow creation of freestyle zones
- [x] + Make multiple freestyle zones possible (damn you Aoki and badges for making stuff difficult!) - [x] + Make multiple freestyle zones possible (damn you Aoki and badges for making stuff difficult!)
- [x] + Handle deletion of multiple freestyle zones - [x] + Handle deletion of multiple freestyle zones
- [x] + Handle drawing of end/freestyle zones properly - [x] + Handle drawing of end/freestyle zones properly

View File

@ -19,9 +19,9 @@ a bhop server should be simple
"Databases" "Databases"
{ {
"driver_default" "mysql" "driver_default" "mysql"
// When specifying "host", you may use an IP address, a hostname, or a socket file path // When specifying "host", you may use an IP address, a hostname, or a socket file path
"default" "default"
{ {
"driver" "default" "driver" "default"
@ -32,7 +32,7 @@ a bhop server should be simple
//"timeout" "0" //"timeout" "0"
//"port" "0" //"port" "0"
} }
"shavit" "shavit"
{ {
"driver" "mysql" "driver" "mysql"
@ -62,4 +62,4 @@ shavit-zones - wouldn't really call it required but it's actually needed to get
- [ ] Add admin interface (delete replay data) - [ ] Add admin interface (delete replay data)
- [ ] Remove replay bot on deletion of the #1 record - [ ] Remove replay bot on deletion of the #1 record
~ [NEW PLUGIN] shavit-ranks: ~ [NEW PLUGIN] shavit-ranks:

View File

@ -23,4 +23,4 @@
} }
} }
} }
} }

View File

@ -7,7 +7,7 @@
* This program is free software; you can redistribute it and/or modify it under * 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 * the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation. * Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * 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 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
@ -68,7 +68,7 @@ ConVar gCV_Leftright = null;
ConVar gCV_Restart = null; ConVar gCV_Restart = null;
ConVar gCV_Pause = null; ConVar gCV_Pause = null;
public Plugin myinfo = public Plugin myinfo =
{ {
name = "[shavit] Core", name = "[shavit] Core",
author = "shavit", author = "shavit",
@ -92,7 +92,7 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max
CreateNative("Shavit_GetTimer", Native_GetTimer); CreateNative("Shavit_GetTimer", Native_GetTimer);
CreateNative("Shavit_PauseTimer", Native_PauseTimer); CreateNative("Shavit_PauseTimer", Native_PauseTimer);
CreateNative("Shavit_ResumeTimer", Native_ResumeTimer); CreateNative("Shavit_ResumeTimer", Native_ResumeTimer);
MarkNativeAsOptional("Shavit_GetGameType"); MarkNativeAsOptional("Shavit_GetGameType");
MarkNativeAsOptional("Shavit_GetDB"); MarkNativeAsOptional("Shavit_GetDB");
MarkNativeAsOptional("Shavit_StartTimer"); MarkNativeAsOptional("Shavit_StartTimer");
@ -101,13 +101,13 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max
MarkNativeAsOptional("Shavit_GetTimer"); MarkNativeAsOptional("Shavit_GetTimer");
MarkNativeAsOptional("Shavit_PauseTimer"); MarkNativeAsOptional("Shavit_PauseTimer");
MarkNativeAsOptional("Shavit_ResumeTimer"); MarkNativeAsOptional("Shavit_ResumeTimer");
// prevent errors from shavit-zones // prevent errors from shavit-zones
MarkNativeAsOptional("Shavit_InsideZone"); MarkNativeAsOptional("Shavit_InsideZone");
// registers library, check "bool LibraryExists(const char[] name)" in order to use with other plugins // registers library, check "bool LibraryExists(const char[] name)" in order to use with other plugins
RegPluginLibrary("shavit"); RegPluginLibrary("shavit");
gB_Late = late; gB_Late = late;
return APLRes_Success; return APLRes_Success;
@ -180,7 +180,7 @@ public void OnPluginStart()
RegConsoleCmd("sm_pause", Command_TogglePause, "Toggle pause."); RegConsoleCmd("sm_pause", Command_TogglePause, "Toggle pause.");
RegConsoleCmd("sm_unpause", Command_TogglePause, "Toggle pause."); RegConsoleCmd("sm_unpause", Command_TogglePause, "Toggle pause.");
RegConsoleCmd("sm_resume", Command_TogglePause, "Toggle pause"); RegConsoleCmd("sm_resume", Command_TogglePause, "Toggle pause");
// autobhop toggle // autobhop toggle
RegConsoleCmd("sm_auto", Command_AutoBhop, "Toggle autobhop."); RegConsoleCmd("sm_auto", Command_AutoBhop, "Toggle autobhop.");
RegConsoleCmd("sm_autobhop", Command_AutoBhop, "Toggle autobhop."); RegConsoleCmd("sm_autobhop", Command_AutoBhop, "Toggle autobhop.");
@ -189,27 +189,27 @@ public void OnPluginStart()
#if defined DEBUG #if defined DEBUG
RegConsoleCmd("sm_finishtest", Command_FinishTest); RegConsoleCmd("sm_finishtest", Command_FinishTest);
#endif #endif
CreateConVar("shavit_version", SHAVIT_VERSION, "Plugin version.", FCVAR_PLUGIN|FCVAR_NOTIFY|FCVAR_DONTRECORD); CreateConVar("shavit_version", SHAVIT_VERSION, "Plugin version.", FCVAR_PLUGIN|FCVAR_NOTIFY|FCVAR_DONTRECORD);
gCV_Autobhop = CreateConVar("shavit_core_autobhop", "1", "Enable autobhop?", FCVAR_PLUGIN|FCVAR_NOTIFY); gCV_Autobhop = CreateConVar("shavit_core_autobhop", "1", "Enable autobhop?", FCVAR_PLUGIN|FCVAR_NOTIFY);
gCV_Leftright = CreateConVar("shavit_core_blockleftright", "1", "Block +left/right?", FCVAR_PLUGIN|FCVAR_NOTIFY); gCV_Leftright = CreateConVar("shavit_core_blockleftright", "1", "Block +left/right?", FCVAR_PLUGIN|FCVAR_NOTIFY);
gCV_Restart = CreateConVar("shavit_core_restart", "1", "Allow commands that restart the timer?", FCVAR_PLUGIN|FCVAR_NOTIFY); gCV_Restart = CreateConVar("shavit_core_restart", "1", "Allow commands that restart the timer?", FCVAR_PLUGIN|FCVAR_NOTIFY);
gCV_Pause = CreateConVar("shavit_core_pause", "1", "Allow pausing?", FCVAR_PLUGIN|FCVAR_NOTIFY); gCV_Pause = CreateConVar("shavit_core_pause", "1", "Allow pausing?", FCVAR_PLUGIN|FCVAR_NOTIFY);
AutoExecConfig(); AutoExecConfig();
// late // late
if(gB_Late) if(gB_Late)
{ {
OnAdminMenuReady(null); OnAdminMenuReady(null);
for(int i = 1; i <= MaxClients; i++) for(int i = 1; i <= MaxClients; i++)
{ {
OnClientPutInServer(i); OnClientPutInServer(i);
} }
} }
gB_Zones = LibraryExists("shavit-zones"); gB_Zones = LibraryExists("shavit-zones");
} }
@ -232,7 +232,7 @@ public void OnLibraryRemoved(const char[] name)
public void OnAdminMenuReady(Handle topmenu) public void OnAdminMenuReady(Handle topmenu)
{ {
Handle hTopMenu = INVALID_HANDLE; Handle hTopMenu = INVALID_HANDLE;
if(LibraryExists("adminmenu") && ((hTopMenu = GetAdminTopMenu()) != INVALID_HANDLE)) if(LibraryExists("adminmenu") && ((hTopMenu = GetAdminTopMenu()) != INVALID_HANDLE))
{ {
AddToTopMenu(hTopMenu, "Timer Commands", TopMenuObject_Category, CategoryHandler, INVALID_TOPMENUOBJECT); AddToTopMenu(hTopMenu, "Timer Commands", TopMenuObject_Category, CategoryHandler, INVALID_TOPMENUOBJECT);
@ -268,20 +268,20 @@ public Action Command_StartTimer(int client, int args)
{ {
return Plugin_Handled; return Plugin_Handled;
} }
if(!gCV_Restart.BoolValue) if(!gCV_Restart.BoolValue)
{ {
if(args != -1) if(args != -1)
{ {
char sCommand[16]; char sCommand[16];
GetCmdArg(0, sCommand, 16); GetCmdArg(0, sCommand, 16);
ReplyToCommand(client, "%s The command (\x03%s\x01) is disabled.", PREFIX, sCommand); ReplyToCommand(client, "%s The command (\x03%s\x01) is disabled.", PREFIX, sCommand);
} }
return Plugin_Handled; return Plugin_Handled;
} }
Call_StartForward(gH_Forwards_OnRestart); Call_StartForward(gH_Forwards_OnRestart);
Call_PushCell(client); Call_PushCell(client);
Call_Finish(); Call_Finish();
@ -309,21 +309,21 @@ public Action Command_TogglePause(int client, int args)
{ {
return Plugin_Handled; return Plugin_Handled;
} }
if(!gCV_Pause.BoolValue) if(!gCV_Pause.BoolValue)
{ {
char sCommand[16]; char sCommand[16];
GetCmdArg(0, sCommand, 16); GetCmdArg(0, sCommand, 16);
ReplyToCommand(client, "%s The command (\x03%s\x01) is disabled.", PREFIX, sCommand); ReplyToCommand(client, "%s The command (\x03%s\x01) is disabled.", PREFIX, sCommand);
return Plugin_Handled; return Plugin_Handled;
} }
if(!(GetEntityFlags(client) & FL_ONGROUND)) if(!(GetEntityFlags(client) & FL_ONGROUND))
{ {
ReplyToCommand(client, "%s You are not allowed to pause when not on ground.", PREFIX); ReplyToCommand(client, "%s You are not allowed to pause when not on ground.", PREFIX);
return Plugin_Handled; return Plugin_Handled;
} }
@ -336,7 +336,7 @@ public Action Command_TogglePause(int client, int args)
{ {
PauseTimer(client); PauseTimer(client);
} }
return Plugin_Handled; return Plugin_Handled;
} }
@ -355,11 +355,11 @@ public Action Command_AutoBhop(int client, int args)
{ {
return Plugin_Handled; return Plugin_Handled;
} }
gB_Auto[client] = !gB_Auto[client]; gB_Auto[client] = !gB_Auto[client];
ReplyToCommand(client, "%s Autobhop %s\x01.", PREFIX, gB_Auto[client]? "\x04enabled":"\x02disabled"); ReplyToCommand(client, "%s Autobhop %s\x01.", PREFIX, gB_Auto[client]? "\x04enabled":"\x02disabled");
return Plugin_Handled; return Plugin_Handled;
} }
@ -417,9 +417,9 @@ public Action Command_Forwards(int client, int args)
gBS_Style[client] = Style_Forwards; gBS_Style[client] = Style_Forwards;
ReplyToCommand(client, "%s You have selected to play \x03Forwards", PREFIX); ReplyToCommand(client, "%s You have selected to play \x03Forwards", PREFIX);
StopTimer(client); StopTimer(client);
Command_StartTimer(client, -1); Command_StartTimer(client, -1);
return Plugin_Handled; return Plugin_Handled;
@ -431,13 +431,13 @@ public Action Command_Sideways(int client, int args)
{ {
return Plugin_Handled; return Plugin_Handled;
} }
gBS_Style[client] = Style_Sideways; gBS_Style[client] = Style_Sideways;
ReplyToCommand(client, "%s You have selected to play \x03Sideways", PREFIX); ReplyToCommand(client, "%s You have selected to play \x03Sideways", PREFIX);
StopTimer(client); StopTimer(client);
Command_StartTimer(client, -1); Command_StartTimer(client, -1);
return Plugin_Handled; return Plugin_Handled;
@ -502,7 +502,7 @@ public int Native_StartTimer(Handle handler, int numParams)
if(!IsFakeClient(client)) if(!IsFakeClient(client))
{ {
StartTimer(client); StartTimer(client);
Call_StartForward(gH_Forwards_Start); Call_StartForward(gH_Forwards_Start);
Call_PushCell(client); Call_PushCell(client);
Call_Finish(); Call_Finish();
@ -537,14 +537,14 @@ public int Native_FinishMap(Handle handler, int numParams)
public int Native_PauseTimer(Handle handler, int numParams) public int Native_PauseTimer(Handle handler, int numParams)
{ {
int client = GetNativeCell(1); int client = GetNativeCell(1);
PauseTimer(client); PauseTimer(client);
} }
public int Native_ResumeTimer(Handle handler, int numParams) public int Native_ResumeTimer(Handle handler, int numParams)
{ {
int client = GetNativeCell(1); int client = GetNativeCell(1);
ResumeTimer(client); ResumeTimer(client);
} }
@ -610,7 +610,7 @@ public float CalculateTime(int client)
{ {
if(!gB_ClientPaused[client]) if(!gB_ClientPaused[client])
{ {
return GetEngineTime() - gF_StartTime[client] - gF_PauseTotalTime[client]; return GetEngineTime() - gF_StartTime[client] - gF_PauseTotalTime[client];
} }
else else
@ -627,7 +627,7 @@ public void OnClientDisconnect(int client)
public void OnClientPutInServer(int client) public void OnClientPutInServer(int client)
{ {
gB_Auto[client] = true; gB_Auto[client] = true;
StopTimer(client); StopTimer(client);
gBS_Style[client] = Style_Forwards; gBS_Style[client] = Style_Forwards;
@ -743,7 +743,7 @@ public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float vel[3
} }
bool bEdit = false; bool bEdit = false;
// SW cheat blocking // SW cheat blocking
if(!Shavit_InsideZone(client, Zone_Freestyle) && gBS_Style[client] == Style_Sideways && !bOnLadder && (vel[1] != 0.0 || buttons & IN_MOVELEFT || buttons & IN_MOVERIGHT)) if(!Shavit_InsideZone(client, Zone_Freestyle) && gBS_Style[client] == Style_Sideways && !bOnLadder && (vel[1] != 0.0 || buttons & IN_MOVELEFT || buttons & IN_MOVERIGHT))
{ {

View File

@ -7,7 +7,7 @@
* This program is free software; you can redistribute it and/or modify it under * 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 * the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation. * Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * 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 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
@ -36,7 +36,7 @@ bool gB_HUD[MAXPLAYERS+1] = {true, ...};
int gI_StartCycle = 0; int gI_StartCycle = 0;
char gS_Start[][] = char gS_Start[][] =
{ {
"ff0000", "ff0000",
"ff4000", "ff4000",
@ -52,7 +52,7 @@ char gS_Start[][] =
int gI_EndCycle = 0; int gI_EndCycle = 0;
char gS_End[][] = char gS_End[][] =
{ {
"ff0000", "ff0000",
"ff4000", "ff4000",
@ -64,7 +64,7 @@ char gS_End[][] =
"77449c" "77449c"
}; };
public Plugin myinfo = public Plugin myinfo =
{ {
name = "[shavit] HUD", name = "[shavit] HUD",
author = "shavit", author = "shavit",
@ -90,12 +90,12 @@ public void OnPluginStart()
{ {
// prevent errors in case the replay bot isn't loaded // prevent errors in case the replay bot isn't loaded
gB_Replay = LibraryExists("shavit-replay"); gB_Replay = LibraryExists("shavit-replay");
CreateTimer(0.1, UpdateHUD_Timer, INVALID_HANDLE, TIMER_REPEAT); CreateTimer(0.1, UpdateHUD_Timer, INVALID_HANDLE, TIMER_REPEAT);
RegConsoleCmd("sm_togglehud", Command_ToggleHUD, "Toggle the timer's HUD"); RegConsoleCmd("sm_togglehud", Command_ToggleHUD, "Toggle the timer's HUD");
RegConsoleCmd("sm_hud", Command_ToggleHUD, "Toggle the timer's HUD"); RegConsoleCmd("sm_hud", Command_ToggleHUD, "Toggle the timer's HUD");
RegConsoleCmd("sm_zonehud", Command_ToggleZoneHUD, "Toggle the timer's flashing zone HUD"); RegConsoleCmd("sm_zonehud", Command_ToggleZoneHUD, "Toggle the timer's flashing zone HUD");
} }
@ -107,18 +107,18 @@ public void OnClientPutInServer(int client)
public Action Command_ToggleHUD(int client, int args) public Action Command_ToggleHUD(int client, int args)
{ {
gB_HUD[client] = !gB_HUD[client]; gB_HUD[client] = !gB_HUD[client];
ReplyToCommand(client, "%s HUD %s\x01.", PREFIX, gB_HUD[client]? "\x04enabled":(gSG_Type == Game_CSGO? "\x02disabled":"\x05disabled")); ReplyToCommand(client, "%s HUD %s\x01.", PREFIX, gB_HUD[client]? "\x04enabled":(gSG_Type == Game_CSGO? "\x02disabled":"\x05disabled"));
return Plugin_Handled; return Plugin_Handled;
} }
public Action Command_ToggleZoneHUD(int client, int args) public Action Command_ToggleZoneHUD(int client, int args)
{ {
gB_ZoneHUD[client] = !gB_ZoneHUD[client]; gB_ZoneHUD[client] = !gB_ZoneHUD[client];
ReplyToCommand(client, "%s Zone HUD %s\x01.", PREFIX, gB_ZoneHUD[client]? "\x04enabled":(gSG_Type == Game_CSGO? "\x02disabled":"\x05disabled")); ReplyToCommand(client, "%s Zone HUD %s\x01.", PREFIX, gB_ZoneHUD[client]? "\x04enabled":(gSG_Type == Game_CSGO? "\x02disabled":"\x05disabled"));
return Plugin_Handled; return Plugin_Handled;
} }
@ -153,19 +153,19 @@ public void OnConfigsExecuted()
public Action UpdateHUD_Timer(Handle Timer) public Action UpdateHUD_Timer(Handle Timer)
{ {
gI_StartCycle++; gI_StartCycle++;
if(gI_StartCycle > 9) if(gI_StartCycle > 9)
{ {
gI_StartCycle = 0; gI_StartCycle = 0;
} }
gI_EndCycle++; gI_EndCycle++;
if(gI_EndCycle > 7) if(gI_EndCycle > 7)
{ {
gI_EndCycle = 0; gI_EndCycle = 0;
} }
for(int i = 1; i <= MaxClients; i++) for(int i = 1; i <= MaxClients; i++)
{ {
if(!IsValidClient(i) || !gB_HUD[i]) if(!IsValidClient(i) || !gB_HUD[i])
@ -195,23 +195,23 @@ public void UpdateHUD(int client)
} }
} }
} }
char sHintText[256]; char sHintText[256];
if(gB_ZoneHUD[client] && gSG_Type == Game_CSGO && Shavit_InsideZone(target, Zone_Start)) if(gB_ZoneHUD[client] && gSG_Type == Game_CSGO && Shavit_InsideZone(target, Zone_Start))
{ {
FormatEx(sHintText, 256, "<font size=\"45\" color=\"#%s\">Start Zone</font>", gS_Start[gI_StartCycle]); FormatEx(sHintText, 256, "<font size=\"45\" color=\"#%s\">Start Zone</font>", gS_Start[gI_StartCycle]);
PrintHintText(client, sHintText); PrintHintText(client, sHintText);
} }
else if(gB_ZoneHUD[client] && gSG_Type == Game_CSGO && Shavit_InsideZone(target, Zone_End)) else if(gB_ZoneHUD[client] && gSG_Type == Game_CSGO && Shavit_InsideZone(target, Zone_End))
{ {
FormatEx(sHintText, 256, "<font size=\"45\" color=\"#%s\">End Zone</font>", gS_End[gI_EndCycle]); FormatEx(sHintText, 256, "<font size=\"45\" color=\"#%s\">End Zone</font>", gS_End[gI_EndCycle]);
PrintHintText(client, sHintText); PrintHintText(client, sHintText);
} }
else if(!IsFakeClient(target)) else if(!IsFakeClient(target))
{ {
float fTime; float fTime;
@ -219,119 +219,119 @@ public void UpdateHUD(int client)
BhopStyle bsStyle; BhopStyle bsStyle;
bool bStarted; bool bStarted;
Shavit_GetTimer(target, fTime, iJumps, bsStyle, bStarted); Shavit_GetTimer(target, fTime, iJumps, bsStyle, bStarted);
float fWR; float fWR;
Shavit_GetWRTime(bsStyle, fWR); Shavit_GetWRTime(bsStyle, fWR);
float fSpeed[3]; float fSpeed[3];
GetEntPropVector(target, Prop_Data, "m_vecVelocity", fSpeed); GetEntPropVector(target, Prop_Data, "m_vecVelocity", fSpeed);
float fSpeed_New = SquareRoot(Pow(fSpeed[0], 2.0) + Pow(fSpeed[1], 2.0)); float fSpeed_New = SquareRoot(Pow(fSpeed[0], 2.0) + Pow(fSpeed[1], 2.0));
float fPB; float fPB;
Shavit_GetPlayerPB(target, bsStyle, fPB); Shavit_GetPlayerPB(target, bsStyle, fPB);
char sPB[32]; char sPB[32];
FormatSeconds(fPB, sPB, 32); FormatSeconds(fPB, sPB, 32);
char sTime[32]; char sTime[32];
FormatSeconds(fTime, sTime, 32, false); FormatSeconds(fTime, sTime, 32, false);
if(gSG_Type == Game_CSGO) if(gSG_Type == Game_CSGO)
{ {
FormatEx(sHintText, 256, "<font face='Stratum2'>"); FormatEx(sHintText, 256, "<font face='Stratum2'>");
if(bStarted) if(bStarted)
{ {
char sColor[8]; char sColor[8];
if(fTime < fWR || fWR == 0.0) if(fTime < fWR || fWR == 0.0)
{ {
strcopy(sColor, 8, "00FF00"); strcopy(sColor, 8, "00FF00");
} }
else if(fPB != 0.0 && fTime < fPB) else if(fPB != 0.0 && fTime < fPB)
{ {
strcopy(sColor, 8, "FFA500"); strcopy(sColor, 8, "FFA500");
} }
else else
{ {
strcopy(sColor, 8, "FF0000"); strcopy(sColor, 8, "FF0000");
} }
Format(sHintText, 256, "%sTime: <font color='#%s'>%s</font>", sHintText, sColor, sTime); Format(sHintText, 256, "%sTime: <font color='#%s'>%s</font>", sHintText, sColor, sTime);
} }
Format(sHintText, 256, "%s\nStyle: <font color='%s</font>", sHintText, bsStyle == Style_Forwards? "#797FD4'>Forwards":"#B54CB3'>Sideways"); Format(sHintText, 256, "%s\nStyle: <font color='%s</font>", sHintText, bsStyle == Style_Forwards? "#797FD4'>Forwards":"#B54CB3'>Sideways");
if(fPB > 0.00) if(fPB > 0.00)
{ {
Format(sHintText, 256, "%s\tPB: %s", sHintText, sPB); Format(sHintText, 256, "%s\tPB: %s", sHintText, sPB);
} }
Format(sHintText, 256, "%s\nSpeed: %.02f%s", sHintText, fSpeed_New, fSpeed_New < 10? "\t":""); Format(sHintText, 256, "%s\nSpeed: %.02f%s", sHintText, fSpeed_New, fSpeed_New < 10? "\t":"");
if(bStarted) if(bStarted)
{ {
Format(sHintText, 256, "%s\tJumps: %d", sHintText, iJumps); Format(sHintText, 256, "%s\tJumps: %d", sHintText, iJumps);
} }
Format(sHintText, 256, "%s\nPlayer: <font color='#BF6821'>%N</font>", sHintText, target); Format(sHintText, 256, "%s\nPlayer: <font color='#BF6821'>%N</font>", sHintText, target);
Format(sHintText, 256, "%s</font>", sHintText); Format(sHintText, 256, "%s</font>", sHintText);
} }
else else
{ {
if(bStarted) if(bStarted)
{ {
FormatEx(sHintText, 256, "Time: %s", sTime); FormatEx(sHintText, 256, "Time: %s", sTime);
Format(sHintText, 256, "%s\nStyle: %s", sHintText, bsStyle == Style_Forwards? "Forwards":"Sideways"); Format(sHintText, 256, "%s\nStyle: %s", sHintText, bsStyle == Style_Forwards? "Forwards":"Sideways");
} }
else else
{ {
FormatEx(sHintText, 256, "Style: %s", bsStyle == Style_Forwards? "Forwards":"Sideways"); FormatEx(sHintText, 256, "Style: %s", bsStyle == Style_Forwards? "Forwards":"Sideways");
} }
if(fPB > 0.00) if(fPB > 0.00)
{ {
Format(sHintText, 256, "%s\nPB: %s", sHintText, sPB); Format(sHintText, 256, "%s\nPB: %s", sHintText, sPB);
} }
Format(sHintText, 256, "%s\nSpeed: %.02f%s", sHintText, fSpeed_New, fSpeed_New < 10? "\t":""); Format(sHintText, 256, "%s\nSpeed: %.02f%s", sHintText, fSpeed_New, fSpeed_New < 10? "\t":"");
if(bStarted) if(bStarted)
{ {
Format(sHintText, 256, "%s\nJumps: %d", sHintText, iJumps); Format(sHintText, 256, "%s\nJumps: %d", sHintText, iJumps);
} }
Format(sHintText, 256, "%s\nPlayer: %N", sHintText, target); Format(sHintText, 256, "%s\nPlayer: %N", sHintText, target);
} }
PrintHintText(client, sHintText); PrintHintText(client, sHintText);
} }
else if(gB_Replay) else if(gB_Replay)
{ {
BhopStyle bsStyle = (target == Shavit_GetReplayBotIndex(Style_Forwards)? Style_Forwards:Style_Sideways); BhopStyle bsStyle = (target == Shavit_GetReplayBotIndex(Style_Forwards)? Style_Forwards:Style_Sideways);
/* will work on this when I find enough time /* will work on this when I find enough time
float fBotStart; float fBotStart;
Shavit_GetReplayBotFirstFrame(bsStyle, fBotStart); Shavit_GetReplayBotFirstFrame(bsStyle, fBotStart);
float fTime = GetEngineTime() - fBotStart; float fTime = GetEngineTime() - fBotStart;
char sTime[32]; char sTime[32];
FormatSeconds(fTime, sTime, 32, false);*/ FormatSeconds(fTime, sTime, 32, false);*/
float fSpeed[3]; float fSpeed[3];
GetEntPropVector(target, Prop_Data, "m_vecVelocity", fSpeed); GetEntPropVector(target, Prop_Data, "m_vecVelocity", fSpeed);
float fSpeed_New = SquareRoot(Pow(fSpeed[0], 2.0) + Pow(fSpeed[1], 2.0)); float fSpeed_New = SquareRoot(Pow(fSpeed[0], 2.0) + Pow(fSpeed[1], 2.0));
if(gSG_Type == Game_CSGO) if(gSG_Type == Game_CSGO)
{ {
FormatEx(sHintText, 256, "<font face='Stratum2'>"); FormatEx(sHintText, 256, "<font face='Stratum2'>");
@ -340,14 +340,14 @@ public void UpdateHUD(int client)
Format(sHintText, 256, "%s\nSpeed: %.02f", sHintText, fSpeed_New); Format(sHintText, 256, "%s\nSpeed: %.02f", sHintText, fSpeed_New);
Format(sHintText, 256, "%s</font>", sHintText); Format(sHintText, 256, "%s</font>", sHintText);
} }
else else
{ {
FormatEx(sHintText, 256, "\t- Replay Bot -", sHintText); FormatEx(sHintText, 256, "\t- Replay Bot -", sHintText);
Format(sHintText, 256, "%s\nStyle: %s", sHintText, bsStyle == Style_Forwards? "Forwards":"Sideways"); Format(sHintText, 256, "%s\nStyle: %s", sHintText, bsStyle == Style_Forwards? "Forwards":"Sideways");
Format(sHintText, 256, "%s\nSpeed: %.02f", sHintText, fSpeed_New); Format(sHintText, 256, "%s\nSpeed: %.02f", sHintText, fSpeed_New);
} }
PrintHintText(client, sHintText); PrintHintText(client, sHintText);
} }
} }

View File

@ -7,7 +7,7 @@
* This program is free software; you can redistribute it and/or modify it under * 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 * the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation. * Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * 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 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
@ -44,7 +44,7 @@ ConVar gCV_RespawnOnTeam = null;
// dhooks // dhooks
Handle gH_GetMaxPlayerSpeed = null; Handle gH_GetMaxPlayerSpeed = null;
public Plugin myinfo = public Plugin myinfo =
{ {
name = "[shavit] Miscellaneous", name = "[shavit] Miscellaneous",
author = "shavit", author = "shavit",
@ -63,7 +63,7 @@ public void OnPluginStart()
// spectator list // spectator list
RegConsoleCmd("sm_specs", Command_Specs, "Show a list of spectators."); RegConsoleCmd("sm_specs", Command_Specs, "Show a list of spectators.");
RegConsoleCmd("sm_spectators", Command_Specs, "Show a list of spectators."); RegConsoleCmd("sm_spectators", Command_Specs, "Show a list of spectators.");
// spec // spec
RegConsoleCmd("sm_spec", Command_Spec, "Moves you to the spectators' team. Usage: sm_spec [target]"); RegConsoleCmd("sm_spec", Command_Spec, "Moves you to the spectators' team. Usage: sm_spec [target]");
RegConsoleCmd("sm_spectate", Command_Spec, "Moves you to the spectators' team. Usage: sm_spectate [target]"); RegConsoleCmd("sm_spectate", Command_Spec, "Moves you to the spectators' team. Usage: sm_spectate [target]");
@ -71,61 +71,61 @@ public void OnPluginStart()
// hide // hide
RegConsoleCmd("sm_hide", Command_Hide, "Toggle players' hiding."); RegConsoleCmd("sm_hide", Command_Hide, "Toggle players' hiding.");
RegConsoleCmd("sm_unhide", Command_Hide, "Toggle players' hiding."); RegConsoleCmd("sm_unhide", Command_Hide, "Toggle players' hiding.");
// tpto // tpto
RegConsoleCmd("sm_tpto", Command_Teleport, "Teleport to another player. Usage: sm_tpto [target]"); RegConsoleCmd("sm_tpto", Command_Teleport, "Teleport to another player. Usage: sm_tpto [target]");
RegConsoleCmd("sm_goto", Command_Teleport, "Teleport to another player. Usage: sm_goto [target]"); RegConsoleCmd("sm_goto", Command_Teleport, "Teleport to another player. Usage: sm_goto [target]");
// hook teamjoins // hook teamjoins
AddCommandListener(Command_Jointeam, "jointeam"); AddCommandListener(Command_Jointeam, "jointeam");
// message // message
CreateTimer(600.0, Timer_Message, INVALID_HANDLE, TIMER_REPEAT); CreateTimer(600.0, Timer_Message, INVALID_HANDLE, TIMER_REPEAT);
// hooks // hooks
HookEvent("player_spawn", Player_Spawn); HookEvent("player_spawn", Player_Spawn);
HookEvent("player_team", Player_Team, EventHookMode_Pre); HookEvent("player_team", Player_Team, EventHookMode_Pre);
// let's fix issues with phrases :D // let's fix issues with phrases :D
LoadTranslations("common.phrases"); LoadTranslations("common.phrases");
// CS:GO weapon cleanup // CS:GO weapon cleanup
if(Shavit_GetGameType() == Game_CSGO) if(Shavit_GetGameType() == Game_CSGO)
{ {
ConVar hDeathDropGun = FindConVar("mp_death_drop_gun"); ConVar hDeathDropGun = FindConVar("mp_death_drop_gun");
if(hDeathDropGun != null) if(hDeathDropGun != null)
{ {
hDeathDropGun.SetBool(false); hDeathDropGun.SetBool(false);
} }
else else
{ {
LogError("idk what's wrong but for some reason, your CS:GO server is missing the \"mp_death_drop_gun\" cvar. go find what's causing it because I dunno"); LogError("idk what's wrong but for some reason, your CS:GO server is missing the \"mp_death_drop_gun\" cvar. go find what's causing it because I dunno");
} }
} }
// cvars and stuff // cvars and stuff
gCV_GodMode = CreateConVar("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."); gCV_GodMode = CreateConVar("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.");
gCV_PreSpeed = CreateConVar("shavit_misc_prespeed", "3", "Stop prespeed in startzone?\n0 - Disabled\n1 - Limit 280 speed.\n2 - Block bhopping in startzone\n3 - Limit 280 speed and block bhopping in startzone."); gCV_PreSpeed = CreateConVar("shavit_misc_prespeed", "3", "Stop prespeed in startzone?\n0 - Disabled\n1 - Limit 280 speed.\n2 - Block bhopping in startzone\n3 - Limit 280 speed and block bhopping in startzone.");
gCV_HideTeamChanges = CreateConVar("shavit_misc_hideteamchanges", "1", "Hide team changes in chat?\n0 - Disabled\n1 - Enabled"); gCV_HideTeamChanges = CreateConVar("shavit_misc_hideteamchanges", "1", "Hide team changes in chat?\n0 - Disabled\n1 - Enabled");
gCV_RespawnOnTeam = CreateConVar("shavit_misc_respawnonteam", "1", "Respawn whenever a player joins a team?\n0 - Disabled\n1 - Enabled"); gCV_RespawnOnTeam = CreateConVar("shavit_misc_respawnonteam", "1", "Respawn whenever a player joins a team?\n0 - Disabled\n1 - Enabled");
AutoExecConfig(); AutoExecConfig();
if(LibraryExists("dhooks")) if(LibraryExists("dhooks"))
{ {
Handle hGameData = LoadGameConfigFile("shavit.games"); Handle hGameData = LoadGameConfigFile("shavit.games");
if(hGameData != null) if(hGameData != null)
{ {
int iOffset = GameConfGetOffset(hGameData, "GetMaxPlayerSpeed"); int iOffset = GameConfGetOffset(hGameData, "GetMaxPlayerSpeed");
gH_GetMaxPlayerSpeed = DHookCreate(iOffset, HookType_Entity, ReturnType_Float, ThisPointer_CBaseEntity, DHook_GetMaxPlayerSpeed); gH_GetMaxPlayerSpeed = DHookCreate(iOffset, HookType_Entity, ReturnType_Float, ThisPointer_CBaseEntity, DHook_GetMaxPlayerSpeed);
} }
CloseHandle(hGameData); CloseHandle(hGameData);
} }
// late load // late load
if(gB_Late) if(gB_Late)
{ {
@ -143,18 +143,18 @@ public Action Command_Jointeam(int client, const char[] command, int args)
{ {
char arg1[8]; char arg1[8];
GetCmdArg(1, arg1, 8); GetCmdArg(1, arg1, 8);
int iTeam = StringToInt(arg1); int iTeam = StringToInt(arg1);
// client is trying to join the same team he's now. // client is trying to join the same team he's now.
// i'll let the game handle it. // i'll let the game handle it.
if(GetClientTeam(client) == iTeam) if(GetClientTeam(client) == iTeam)
{ {
return Plugin_Continue; return Plugin_Continue;
} }
bool bRespawn = false; bool bRespawn = false;
switch(iTeam) switch(iTeam)
{ {
case CS_TEAM_T: case CS_TEAM_T:
@ -163,41 +163,41 @@ public Action Command_Jointeam(int client, const char[] command, int args)
if(FindEntityByClassname(-1, "info_player_terrorist") != -1) if(FindEntityByClassname(-1, "info_player_terrorist") != -1)
{ {
bRespawn = true; bRespawn = true;
CS_SwitchTeam(client, CS_TEAM_T); CS_SwitchTeam(client, CS_TEAM_T);
} }
} }
case CS_TEAM_CT: case CS_TEAM_CT:
{ {
// if CT spawns are available in the map // if CT spawns are available in the map
if(FindEntityByClassname(-1, "info_player_counterterrorist") != -1) if(FindEntityByClassname(-1, "info_player_counterterrorist") != -1)
{ {
bRespawn = true; bRespawn = true;
CS_SwitchTeam(client, CS_TEAM_CT); CS_SwitchTeam(client, CS_TEAM_CT);
} }
} }
// if they chose to spectate, i'll force them to join the spectators // if they chose to spectate, i'll force them to join the spectators
case CS_TEAM_SPECTATOR: case CS_TEAM_SPECTATOR:
{ {
CS_SwitchTeam(client, CS_TEAM_SPECTATOR); CS_SwitchTeam(client, CS_TEAM_SPECTATOR);
} }
default: default:
{ {
return Plugin_Continue; return Plugin_Continue;
} }
} }
if(bRespawn && gCV_RespawnOnTeam.BoolValue) if(bRespawn && gCV_RespawnOnTeam.BoolValue)
{ {
CS_RespawnPlayer(client); CS_RespawnPlayer(client);
return Plugin_Handled; return Plugin_Handled;
} }
return Plugin_Continue; return Plugin_Continue;
} }
@ -206,10 +206,10 @@ public MRESReturn DHook_GetMaxPlayerSpeed(int pThis, Handle hReturn)
if(IsValidClient(pThis, true)) if(IsValidClient(pThis, true))
{ {
DHookSetReturn(hReturn, 250.000); DHookSetReturn(hReturn, 250.000);
return MRES_Override; return MRES_Override;
} }
return MRES_Ignored; return MRES_Ignored;
} }
@ -241,7 +241,7 @@ public Action OnPlayerRunCmd(int client, int &buttons)
Shavit_StopTimer(client); Shavit_StopTimer(client);
} }
} }
if(Shavit_InsideZone(client, Zone_Start)) if(Shavit_InsideZone(client, Zone_Start))
{ {
if((gCV_PreSpeed.IntValue == 2 || gCV_PreSpeed.IntValue == 3) && !(gF_LastFlags[client] & FL_ONGROUND) && (GetEntityFlags(client) & FL_ONGROUND) && buttons & IN_JUMP) if((gCV_PreSpeed.IntValue == 2 || gCV_PreSpeed.IntValue == 3) && !(gF_LastFlags[client] & FL_ONGROUND) && (GetEntityFlags(client) & FL_ONGROUND) && buttons & IN_JUMP)
@ -249,7 +249,7 @@ public Action OnPlayerRunCmd(int client, int &buttons)
TeleportEntity(client, NULL_VECTOR, NULL_VECTOR, view_as<float>({0.0, 0.0, 0.0})); TeleportEntity(client, NULL_VECTOR, NULL_VECTOR, view_as<float>({0.0, 0.0, 0.0}));
PrintToChat(client, "%s Bhopping in the start zone is not allowed.", PREFIX); PrintToChat(client, "%s Bhopping in the start zone is not allowed.", PREFIX);
gF_LastFlags[client] = GetEntityFlags(client); gF_LastFlags[client] = GetEntityFlags(client);
return Plugin_Continue; return Plugin_Continue;
} }
@ -260,19 +260,19 @@ public Action OnPlayerRunCmd(int client, int &buttons)
float fSpeed_New = SquareRoot(Pow(fSpeed[0], 2.0) + Pow(fSpeed[1], 2.0)); float fSpeed_New = SquareRoot(Pow(fSpeed[0], 2.0) + Pow(fSpeed[1], 2.0));
float fScale = 280.0 / fSpeed_New; float fScale = 280.0 / fSpeed_New;
if(fScale < 1.0) // 280 / 281 = below 1 | 280 / 279 = above 1 if(fScale < 1.0) // 280 / 281 = below 1 | 280 / 279 = above 1
{ {
fSpeed[0] *= fScale; fSpeed[0] *= fScale;
fSpeed[1] *= fScale; fSpeed[1] *= fScale;
TeleportEntity(client, NULL_VECTOR, NULL_VECTOR, fSpeed); TeleportEntity(client, NULL_VECTOR, NULL_VECTOR, fSpeed);
} }
} }
} }
gF_LastFlags[client] = GetEntityFlags(client); gF_LastFlags[client] = GetEntityFlags(client);
return Plugin_Continue; return Plugin_Continue;
} }
@ -282,7 +282,7 @@ public void OnClientPutInServer(int client)
SDKHook(client, SDKHook_SetTransmit, OnSetTransmit); SDKHook(client, SDKHook_SetTransmit, OnSetTransmit);
SDKHook(client, SDKHook_OnTakeDamage, OnTakeDamage); SDKHook(client, SDKHook_OnTakeDamage, OnTakeDamage);
if(gH_GetMaxPlayerSpeed != null) if(gH_GetMaxPlayerSpeed != null)
{ {
DHookEntity(gH_GetMaxPlayerSpeed, true, client); DHookEntity(gH_GetMaxPlayerSpeed, true, client);
@ -297,7 +297,7 @@ public Action OnTakeDamage(int victim, int attacker)
{ {
return Plugin_Continue; return Plugin_Continue;
} }
case 1: case 1:
{ {
// 0 - world/fall damage // 0 - world/fall damage
@ -306,7 +306,7 @@ public Action OnTakeDamage(int victim, int attacker)
return Plugin_Handled; return Plugin_Handled;
} }
} }
case 2: case 2:
{ {
if(IsValidClient(attacker, true)) if(IsValidClient(attacker, true))
@ -314,14 +314,14 @@ public Action OnTakeDamage(int victim, int attacker)
return Plugin_Handled; return Plugin_Handled;
} }
} }
// else // else
default: default:
{ {
return Plugin_Handled; return Plugin_Handled;
} }
} }
return Plugin_Continue; return Plugin_Continue;
} }
@ -334,7 +334,7 @@ public Action OnSetTransmit(int entity, int client)
{ {
return Plugin_Handled; return Plugin_Handled;
} }
else if(GetEntProp(client, Prop_Send, "m_iObserverMode") != 6 && GetEntPropEnt(client, Prop_Send, "m_hObserverTarget") != entity) else if(GetEntProp(client, Prop_Send, "m_iObserverMode") != 6 && GetEntPropEnt(client, Prop_Send, "m_hObserverTarget") != entity)
{ {
return Plugin_Handled; return Plugin_Handled;
@ -352,7 +352,7 @@ public Action OnClientSayCommand(int client, const char[] command, const char[]
{ {
return Plugin_Handled; return Plugin_Handled;
} }
return Plugin_Continue; return Plugin_Continue;
} }
@ -364,7 +364,7 @@ public Action Command_Hide(int client, int args)
} }
gB_Hide[client] = !gB_Hide[client]; gB_Hide[client] = !gB_Hide[client];
// I use PTC instead of RTC there because I have an sm_hide bind just like many people :) // I use PTC instead of RTC there because I have an sm_hide bind just like many people :)
PrintToChat(client, "%s You are now %shiding players.", PREFIX, gB_Hide[client]? "":"not "); PrintToChat(client, "%s You are now %shiding players.", PREFIX, gB_Hide[client]? "":"not ");
@ -377,24 +377,24 @@ public Action Command_Spec(int client, int args)
{ {
return Plugin_Handled; return Plugin_Handled;
} }
ChangeClientTeam(client, CS_TEAM_SPECTATOR); ChangeClientTeam(client, CS_TEAM_SPECTATOR);
if(args > 0) if(args > 0)
{ {
char sArgs[MAX_TARGET_LENGTH]; char sArgs[MAX_TARGET_LENGTH];
GetCmdArgString(sArgs, MAX_TARGET_LENGTH); GetCmdArgString(sArgs, MAX_TARGET_LENGTH);
int iTarget = FindTarget(client, sArgs, false, false); int iTarget = FindTarget(client, sArgs, false, false);
if(iTarget == -1) if(iTarget == -1)
{ {
return Plugin_Handled; return Plugin_Handled;
} }
SetEntPropEnt(client, Prop_Send, "m_hObserverTarget", iTarget); SetEntPropEnt(client, Prop_Send, "m_hObserverTarget", iTarget);
} }
return Plugin_Handled; return Plugin_Handled;
} }
@ -404,48 +404,48 @@ public Action Command_Teleport(int client, int args)
{ {
return Plugin_Handled; return Plugin_Handled;
} }
if(args > 0) if(args > 0)
{ {
char sArgs[MAX_TARGET_LENGTH]; char sArgs[MAX_TARGET_LENGTH];
GetCmdArgString(sArgs, MAX_TARGET_LENGTH); GetCmdArgString(sArgs, MAX_TARGET_LENGTH);
int iTarget = FindTarget(client, sArgs, false, false); int iTarget = FindTarget(client, sArgs, false, false);
if(iTarget == -1) if(iTarget == -1)
{ {
return Plugin_Handled; return Plugin_Handled;
} }
Teleport(client, GetClientSerial(iTarget)); Teleport(client, GetClientSerial(iTarget));
} }
else else
{ {
Menu menu = CreateMenu(MenuHandler_Teleport); Menu menu = CreateMenu(MenuHandler_Teleport);
menu.SetTitle("Teleport to:"); menu.SetTitle("Teleport to:");
for(int i = 1; i <= MaxClients; i++) for(int i = 1; i <= MaxClients; i++)
{ {
if(!IsValidClient(i, true) || i == client) if(!IsValidClient(i, true) || i == client)
{ {
continue; continue;
} }
char serial[16]; char serial[16];
IntToString(GetClientSerial(i), serial, 16); IntToString(GetClientSerial(i), serial, 16);
char sName[MAX_NAME_LENGTH]; char sName[MAX_NAME_LENGTH];
GetClientName(i, sName, MAX_NAME_LENGTH); GetClientName(i, sName, MAX_NAME_LENGTH);
menu.AddItem(serial, sName); menu.AddItem(serial, sName);
} }
menu.ExitButton = true; menu.ExitButton = true;
menu.Display(client, 60); menu.Display(client, 60);
} }
return Plugin_Handled; return Plugin_Handled;
} }
@ -455,13 +455,13 @@ public int MenuHandler_Teleport(Menu menu, MenuAction action, int param1, int pa
{ {
char info[16]; char info[16];
menu.GetItem(param2, info, 16); menu.GetItem(param2, info, 16);
if(Teleport(param1, StringToInt(info)) == -1) if(Teleport(param1, StringToInt(info)) == -1)
{ {
Command_Teleport(param1, 0); Command_Teleport(param1, 0);
} }
} }
else if(action == MenuAction_End) else if(action == MenuAction_End)
{ {
delete menu; delete menu;
@ -473,33 +473,33 @@ public int Teleport(int client, int targetserial)
if(!IsPlayerAlive(client)) if(!IsPlayerAlive(client))
{ {
PrintToChat(client, "%s You can teleport only if you are alive.", PREFIX); PrintToChat(client, "%s You can teleport only if you are alive.", PREFIX);
return -1; return -1;
} }
int iTarget = GetClientFromSerial(targetserial); int iTarget = GetClientFromSerial(targetserial);
if(Shavit_InsideZone(client, Zone_Start) || Shavit_InsideZone(client, Zone_End)) if(Shavit_InsideZone(client, Zone_Start) || Shavit_InsideZone(client, Zone_End))
{ {
PrintToChat(client, "%s You cannot teleport inside the start/end zones.", PREFIX); PrintToChat(client, "%s You cannot teleport inside the start/end zones.", PREFIX);
return -1; return -1;
} }
if(!iTarget) if(!iTarget)
{ {
PrintToChat(client, "%s Invalid target.", PREFIX); PrintToChat(client, "%s Invalid target.", PREFIX);
return -1; return -1;
} }
float vecPosition[3]; float vecPosition[3];
GetClientAbsOrigin(iTarget, vecPosition); GetClientAbsOrigin(iTarget, vecPosition);
Shavit_StopTimer(client); Shavit_StopTimer(client);
TeleportEntity(client, vecPosition, NULL_VECTOR, NULL_VECTOR); TeleportEntity(client, vecPosition, NULL_VECTOR, NULL_VECTOR);
return 0; return 0;
} }
@ -601,12 +601,12 @@ public void Shavit_OnRestart(int client)
{ {
CS_SwitchTeam(client, CS_TEAM_T); CS_SwitchTeam(client, CS_TEAM_T);
} }
else else
{ {
CS_SwitchTeam(client, CS_TEAM_CT); CS_SwitchTeam(client, CS_TEAM_CT);
} }
CreateTimer(0.1, Respawn, client); CreateTimer(0.1, Respawn, client);
} }
} }
@ -625,10 +625,10 @@ public Action Respawn(Handle Timer, any client)
if(IsValidClient(client) && !IsPlayerAlive(client)) if(IsValidClient(client) && !IsPlayerAlive(client))
{ {
CS_RespawnPlayer(client); CS_RespawnPlayer(client);
RestartTimer(client); RestartTimer(client);
} }
return Plugin_Handled; return Plugin_Handled;
} }
@ -645,9 +645,9 @@ public Action Player_Team(Handle event, const char[] name, bool dontBroadcast)
if(gCV_HideTeamChanges.BoolValue) if(gCV_HideTeamChanges.BoolValue)
{ {
SetEventBroadcast(event, true); SetEventBroadcast(event, true);
return Plugin_Changed; return Plugin_Changed;
} }
return Plugin_Continue; return Plugin_Continue;
} }

View File

@ -7,7 +7,7 @@
* This program is free software; you can redistribute it and/or modify it under * 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 * the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation. * Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * 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 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
@ -47,7 +47,7 @@ char gS_Map[128];
ConVar bot_quota = null; ConVar bot_quota = null;
public Plugin myinfo = public Plugin myinfo =
{ {
name = "[shavit] Replay Bot", name = "[shavit] Replay Bot",
author = "shavit, ofir", author = "shavit, ofir",
@ -60,10 +60,10 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max
{ {
CreateNative("Shavit_GetReplayBotFirstFrame", Native_GetReplayBotFirstFrame); CreateNative("Shavit_GetReplayBotFirstFrame", Native_GetReplayBotFirstFrame);
CreateNative("Shavit_GetReplayBotIndex", Native_GetReplayBotIndex); CreateNative("Shavit_GetReplayBotIndex", Native_GetReplayBotIndex);
MarkNativeAsOptional("Shavit_GetReplayBotFirstFrame"); MarkNativeAsOptional("Shavit_GetReplayBotFirstFrame");
MarkNativeAsOptional("Shavit_GetReplayBotIndex"); MarkNativeAsOptional("Shavit_GetReplayBotIndex");
// registers library, check "bool LibraryExists(const char[] name)" in order to use with other plugins // registers library, check "bool LibraryExists(const char[] name)" in order to use with other plugins
RegPluginLibrary("shavit-replay"); RegPluginLibrary("shavit-replay");
@ -73,30 +73,30 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max
public void OnPluginStart() public void OnPluginStart()
{ {
bot_quota = FindConVar("bot_quota"); bot_quota = FindConVar("bot_quota");
CreateTimer(1.0, BotCheck, INVALID_HANDLE, TIMER_REPEAT); CreateTimer(1.0, BotCheck, INVALID_HANDLE, TIMER_REPEAT);
for(int i = 1; i <= MaxClients; i++) for(int i = 1; i <= MaxClients; i++)
{ {
OnClientPutInServer(i); OnClientPutInServer(i);
} }
gF_Tickrate = (1.0 / GetTickInterval()); gF_Tickrate = (1.0 / GetTickInterval());
// insert delete replay command here // insert delete replay command here
} }
public int Native_GetReplayBotFirstFrame(Handle handler, int numParams) public int Native_GetReplayBotFirstFrame(Handle handler, int numParams)
{ {
BhopStyle style = GetNativeCell(1); BhopStyle style = GetNativeCell(1);
SetNativeCellRef(2, gF_StartTick[style]); SetNativeCellRef(2, gF_StartTick[style]);
} }
public int Native_GetReplayBotIndex(Handle handler, int numParams) public int Native_GetReplayBotIndex(Handle handler, int numParams)
{ {
BhopStyle style = GetNativeCell(1); BhopStyle style = GetNativeCell(1);
return gI_ReplayBotClient[style]; return gI_ReplayBotClient[style];
} }
@ -106,14 +106,14 @@ public Action BotCheck(Handle Timer)
{ {
bot_quota.SetInt(MAX_STYLES); bot_quota.SetInt(MAX_STYLES);
} }
// resets bot // resets bot
if(gI_ReplayBotClient[Style_Forwards] == gI_ReplayBotClient[Style_Sideways]) if(gI_ReplayBotClient[Style_Forwards] == gI_ReplayBotClient[Style_Sideways])
{ {
gI_ReplayBotClient[Style_Forwards] = 0; gI_ReplayBotClient[Style_Forwards] = 0;
gI_ReplayBotClient[Style_Sideways] = 0; gI_ReplayBotClient[Style_Sideways] = 0;
} }
for(int i = 0; i < MAX_STYLES; i++) for(int i = 0; i < MAX_STYLES; i++)
{ {
if(gI_ReplayBotClient[i] == 0 || !IsValidClient(gI_ReplayBotClient[i])) if(gI_ReplayBotClient[i] == 0 || !IsValidClient(gI_ReplayBotClient[i]))
@ -124,52 +124,52 @@ public Action BotCheck(Handle Timer)
{ {
continue; continue;
} }
gI_ReplayBotClient[i] = j; gI_ReplayBotClient[i] = j;
} }
} }
if(!IsValidClient(gI_ReplayBotClient[i])) if(!IsValidClient(gI_ReplayBotClient[i]))
{ {
continue; continue;
} }
if(!IsPlayerAlive(gI_ReplayBotClient[i])) if(!IsPlayerAlive(gI_ReplayBotClient[i]))
{ {
CS_RespawnPlayer(gI_ReplayBotClient[i]); CS_RespawnPlayer(gI_ReplayBotClient[i]);
} }
if(GetPlayerWeaponSlot(gI_ReplayBotClient[i], CS_SLOT_KNIFE) == -1) if(GetPlayerWeaponSlot(gI_ReplayBotClient[i], CS_SLOT_KNIFE) == -1)
{ {
GivePlayerItem(gI_ReplayBotClient[i], "weapon_knife"); GivePlayerItem(gI_ReplayBotClient[i], "weapon_knife");
} }
CS_SetClientContributionScore(gI_ReplayBotClient[i], 2000); CS_SetClientContributionScore(gI_ReplayBotClient[i], 2000);
char sStyle[16]; char sStyle[16];
FormatEx(sStyle, 16, "%s REPLAY", i == view_as<int>(Style_Forwards)? "NM":"SW"); FormatEx(sStyle, 16, "%s REPLAY", i == view_as<int>(Style_Forwards)? "NM":"SW");
CS_SetClientClanTag(gI_ReplayBotClient[i], sStyle); CS_SetClientClanTag(gI_ReplayBotClient[i], sStyle);
char sName[MAX_NAME_LENGTH]; char sName[MAX_NAME_LENGTH];
GetClientName(gI_ReplayBotClient[i], sName, MAX_NAME_LENGTH); GetClientName(gI_ReplayBotClient[i], sName, MAX_NAME_LENGTH);
float fWRTime; float fWRTime;
Shavit_GetWRTime(view_as<BhopStyle>(i), fWRTime); Shavit_GetWRTime(view_as<BhopStyle>(i), fWRTime);
if(gA_Frames[i] == null || fWRTime == 0.0) if(gA_Frames[i] == null || fWRTime == 0.0)
{ {
char sCurrentName[MAX_NAME_LENGTH]; char sCurrentName[MAX_NAME_LENGTH];
strcopy(sCurrentName, MAX_NAME_LENGTH, sName); strcopy(sCurrentName, MAX_NAME_LENGTH, sName);
FormatEx(sName, MAX_NAME_LENGTH, "%s unloaded", i == view_as<int>(Style_Forwards)? "NM":"SW"); FormatEx(sName, MAX_NAME_LENGTH, "%s unloaded", i == view_as<int>(Style_Forwards)? "NM":"SW");
if(!StrEqual(sName, sCurrentName)) if(!StrEqual(sName, sCurrentName))
{ {
SetClientName(gI_ReplayBotClient[i], sName); SetClientName(gI_ReplayBotClient[i], sName);
} }
} }
else if(!StrEqual(gS_BotName[i], sName)) else if(!StrEqual(gS_BotName[i], sName))
{ {
SetClientName(gI_ReplayBotClient[i], gS_BotName[i]); SetClientName(gI_ReplayBotClient[i], gS_BotName[i]);
@ -195,7 +195,7 @@ public Action HookTriggers(int entity, int other)
{ {
return Plugin_Handled; return Plugin_Handled;
} }
return Plugin_Continue; return Plugin_Continue;
} }
@ -203,90 +203,90 @@ public void OnMapStart()
{ {
GetCurrentMap(gS_Map, 128); GetCurrentMap(gS_Map, 128);
RemoveMapPath(gS_Map, gS_Map, 128); RemoveMapPath(gS_Map, gS_Map, 128);
char sTempMap[140]; char sTempMap[140];
FormatEx(sTempMap, 140, "maps/%s.nav", gS_Map); FormatEx(sTempMap, 140, "maps/%s.nav", gS_Map);
if(!FileExists(sTempMap)) if(!FileExists(sTempMap))
{ {
File_Copy("maps/base.nav", sTempMap); File_Copy("maps/base.nav", sTempMap);
ForceChangeLevel(gS_Map, ".nav file generate"); ForceChangeLevel(gS_Map, ".nav file generate");
return; return;
} }
/*ConVar bot_zombie = FindConVar("bot_zombie"); /*ConVar bot_zombie = FindConVar("bot_zombie");
// idk if it exists in CS:S, safety check ;p // idk if it exists in CS:S, safety check ;p
if(bot_zombie != null) if(bot_zombie != null)
{ {
bot_zombie.Flags = FCVAR_GAMEDLL|FCVAR_REPLICATED; bot_zombie.Flags = FCVAR_GAMEDLL|FCVAR_REPLICATED;
bot_zombie.SetBool(true); bot_zombie.SetBool(true);
}*/ }*/
ConVar bot_stop = FindConVar("bot_stop"); ConVar bot_stop = FindConVar("bot_stop");
bot_stop.SetBool(true); bot_stop.SetBool(true);
if(Shavit_GetGameType() == Game_CSGO) if(Shavit_GetGameType() == Game_CSGO)
{ {
// I have literally no idea why the fuck does this return invalid handle. // I have literally no idea why the fuck does this return invalid handle.
// FindConVar("bot_controllable").SetBool(false); // FindConVar("bot_controllable").SetBool(false);
ConVar bot_controllable = FindConVar("bot_controllable"); ConVar bot_controllable = FindConVar("bot_controllable");
bot_controllable.SetBool(false); bot_controllable.SetBool(false);
delete bot_controllable; delete bot_controllable;
} }
ConVar bot_quota_mode = FindConVar("bot_quota_mode"); ConVar bot_quota_mode = FindConVar("bot_quota_mode");
bot_quota_mode.SetString("normal"); bot_quota_mode.SetString("normal");
ConVar mp_autoteambalance = FindConVar("mp_autoteambalance"); ConVar mp_autoteambalance = FindConVar("mp_autoteambalance");
mp_autoteambalance.SetBool(false); mp_autoteambalance.SetBool(false);
ConVar mp_limitteams = FindConVar("mp_limitteams"); ConVar mp_limitteams = FindConVar("mp_limitteams");
mp_limitteams.SetInt(0); mp_limitteams.SetInt(0);
ServerCommand("bot_kick"); ServerCommand("bot_kick");
for(int i = 1; i <= MAX_STYLES; i++) for(int i = 1; i <= MAX_STYLES; i++)
{ {
ServerCommand("bot_add"); ServerCommand("bot_add");
} }
ConVar bot_join_after_player = FindConVar("bot_join_after_player"); ConVar bot_join_after_player = FindConVar("bot_join_after_player");
bot_join_after_player.SetBool(false); bot_join_after_player.SetBool(false);
ConVar bot_chatter = FindConVar("bot_chatter"); ConVar bot_chatter = FindConVar("bot_chatter");
bot_chatter.SetString("off"); bot_chatter.SetString("off");
ConVar bot_auto_vacate = FindConVar("bot_auto_vacate"); ConVar bot_auto_vacate = FindConVar("bot_auto_vacate");
bot_auto_vacate.SetBool(false); bot_auto_vacate.SetBool(false);
/*ConVar mp_ignore_round_win_conditions = FindConVar("mp_ignore_round_win_conditions"); /*ConVar mp_ignore_round_win_conditions = FindConVar("mp_ignore_round_win_conditions");
mp_ignore_round_win_conditions.SetBool(true);*/ mp_ignore_round_win_conditions.SetBool(true);*/
char sPath[PLATFORM_MAX_PATH]; char sPath[PLATFORM_MAX_PATH];
BuildPath(Path_SM, sPath, PLATFORM_MAX_PATH, "data/replaybot"); BuildPath(Path_SM, sPath, PLATFORM_MAX_PATH, "data/replaybot");
if(!DirExists(sPath)) if(!DirExists(sPath))
{ {
CreateDirectory(sPath, 511); CreateDirectory(sPath, 511);
} }
for(int i = 0; i < MAX_STYLES; i++) for(int i = 0; i < MAX_STYLES; i++)
{ {
gI_ReplayTick[i] = 0; gI_ReplayTick[i] = 0;
gA_Frames[i] = new ArrayList(5); gA_Frames[i] = new ArrayList(5);
BuildPath(Path_SM, sPath, PLATFORM_MAX_PATH, "data/replaybot/%d", i); BuildPath(Path_SM, sPath, PLATFORM_MAX_PATH, "data/replaybot/%d", i);
if(!DirExists(sPath)) if(!DirExists(sPath))
{ {
CreateDirectory(sPath, 511); CreateDirectory(sPath, 511);
} }
if(!LoadReplay(view_as<BhopStyle>(i))) if(!LoadReplay(view_as<BhopStyle>(i)))
{ {
FormatEx(gS_BotName[i], MAX_NAME_LENGTH, "%s unloaded", i == view_as<int>(Style_Forwards)? "NM":"SW"); FormatEx(gS_BotName[i], MAX_NAME_LENGTH, "%s unloaded", i == view_as<int>(Style_Forwards)? "NM":"SW");
@ -302,37 +302,37 @@ public bool LoadReplay(BhopStyle style)
if(FileExists(sPath)) if(FileExists(sPath))
{ {
Handle hFile = OpenFile(sPath, "r"); Handle hFile = OpenFile(sPath, "r");
ReadFileLine(hFile, gS_BotName[style], MAX_NAME_LENGTH); ReadFileLine(hFile, gS_BotName[style], MAX_NAME_LENGTH);
TrimString(gS_BotName[style]); TrimString(gS_BotName[style]);
char sLine[320]; char sLine[320];
char sExplodedLine[5][64]; char sExplodedLine[5][64];
ReadFileLine(hFile, sLine, 320); ReadFileLine(hFile, sLine, 320);
int iSize = 0; int iSize = 0;
while(!IsEndOfFile(hFile)) while(!IsEndOfFile(hFile))
{ {
ReadFileLine(hFile, sLine, 320); ReadFileLine(hFile, sLine, 320);
ExplodeString(sLine, "|", sExplodedLine, 5, 64); ExplodeString(sLine, "|", sExplodedLine, 5, 64);
gA_Frames[style].Resize(++iSize); gA_Frames[style].Resize(++iSize);
SetArrayCell(gA_Frames[style], iSize - 1, StringToFloat(sExplodedLine[0]), 0); SetArrayCell(gA_Frames[style], iSize - 1, StringToFloat(sExplodedLine[0]), 0);
SetArrayCell(gA_Frames[style], iSize - 1, StringToFloat(sExplodedLine[1]), 1); SetArrayCell(gA_Frames[style], iSize - 1, StringToFloat(sExplodedLine[1]), 1);
SetArrayCell(gA_Frames[style], iSize - 1, StringToFloat(sExplodedLine[2]), 2); SetArrayCell(gA_Frames[style], iSize - 1, StringToFloat(sExplodedLine[2]), 2);
SetArrayCell(gA_Frames[style], iSize - 1, StringToFloat(sExplodedLine[3]), 3); SetArrayCell(gA_Frames[style], iSize - 1, StringToFloat(sExplodedLine[3]), 3);
SetArrayCell(gA_Frames[style], iSize - 1, StringToFloat(sExplodedLine[4]), 4); SetArrayCell(gA_Frames[style], iSize - 1, StringToFloat(sExplodedLine[4]), 4);
} }
delete hFile; delete hFile;
return true; return true;
} }
return false; return false;
} }
@ -340,23 +340,23 @@ public void SaveReplay(BhopStyle style)
{ {
char sPath[PLATFORM_MAX_PATH]; char sPath[PLATFORM_MAX_PATH];
BuildPath(Path_SM, sPath, PLATFORM_MAX_PATH, "data/replaybot/%d/%s.replay", style, gS_Map); BuildPath(Path_SM, sPath, PLATFORM_MAX_PATH, "data/replaybot/%d/%s.replay", style, gS_Map);
if(DirExists(sPath)) if(DirExists(sPath))
{ {
DeleteFile(sPath); DeleteFile(sPath);
} }
Handle hFile = OpenFile(sPath, "w"); Handle hFile = OpenFile(sPath, "w");
WriteFileLine(hFile, gS_BotName[style]); WriteFileLine(hFile, gS_BotName[style]);
int iSize = gA_Frames[style].Length; int iSize = gA_Frames[style].Length;
char sBuffer[320]; char sBuffer[320];
for(int i = 0; i < iSize; i++) for(int i = 0; i < iSize; i++)
{ {
FormatEx(sBuffer, 320, "%f|%f|%f|%f|%f", GetArrayCell(gA_Frames[style], i, 0), GetArrayCell(gA_Frames[style], i, 1), GetArrayCell(gA_Frames[style], i, 2), GetArrayCell(gA_Frames[style], i, 3), GetArrayCell(gA_Frames[style], i, 4)); FormatEx(sBuffer, 320, "%f|%f|%f|%f|%f", GetArrayCell(gA_Frames[style], i, 0), GetArrayCell(gA_Frames[style], i, 1), GetArrayCell(gA_Frames[style], i, 2), GetArrayCell(gA_Frames[style], i, 3), GetArrayCell(gA_Frames[style], i, 4));
WriteFileLine(hFile, sBuffer); WriteFileLine(hFile, sBuffer);
} }
} }
@ -367,24 +367,24 @@ public void OnClientPutInServer(int client)
{ {
return; return;
} }
/*if(IsFakeClient(client)) /*if(IsFakeClient(client))
{ {
if(gI_ReplayBotClient[Style_Forwards] == 0) if(gI_ReplayBotClient[Style_Forwards] == 0)
{ {
gI_ReplayBotClient[Style_Forwards] = client; gI_ReplayBotClient[Style_Forwards] = client;
// strcopy(gS_BotName[Style_Sideways], MAX_NAME_LENGTH, "NM unloaded"); // strcopy(gS_BotName[Style_Sideways], MAX_NAME_LENGTH, "NM unloaded");
} }
else if(gI_ReplayBotClient[Style_Sideways] == 0) else if(gI_ReplayBotClient[Style_Sideways] == 0)
{ {
gI_ReplayBotClient[Style_Sideways] = client; gI_ReplayBotClient[Style_Sideways] = client;
// strcopy(gS_BotName[Style_Sideways], MAX_NAME_LENGTH, "SW unloaded"); // strcopy(gS_BotName[Style_Sideways], MAX_NAME_LENGTH, "SW unloaded");
} }
} }
else else
{*/ {*/
gA_PlayerFrames[client] = new ArrayList(5); gA_PlayerFrames[client] = new ArrayList(5);
@ -397,7 +397,7 @@ public void OnClientDisconnect(int client)
{ {
gI_ReplayBotClient[Style_Forwards] = 0; gI_ReplayBotClient[Style_Forwards] = 0;
} }
else if(client == gI_ReplayBotClient[Style_Sideways]) else if(client == gI_ReplayBotClient[Style_Sideways])
{ {
gI_ReplayBotClient[Style_Sideways] = 0; gI_ReplayBotClient[Style_Sideways] = 0;
@ -409,9 +409,9 @@ public void Shavit_OnStart(int client)
if(!IsFakeClient(client)) if(!IsFakeClient(client))
{ {
gA_PlayerFrames[client].Clear(); gA_PlayerFrames[client].Clear();
gI_PlayerFrames[client] = 0; gI_PlayerFrames[client] = 0;
gB_Record[client] = true; gB_Record[client] = true;
} }
} }
@ -424,24 +424,24 @@ public void Shavit_OnFinish(int client, BhopStyle style, float time, int jumps)
public void Shavit_OnWorldRecord(int client, BhopStyle style, float time, int jumps) public void Shavit_OnWorldRecord(int client, BhopStyle style, float time, int jumps)
{ {
gA_Frames[style] = gA_PlayerFrames[client].Clone(); gA_Frames[style] = gA_PlayerFrames[client].Clone();
gI_ReplayTick[style] = 0; gI_ReplayTick[style] = 0;
char sWRTime[16]; char sWRTime[16];
FormatSeconds(time, sWRTime, 16); FormatSeconds(time, sWRTime, 16);
FormatEx(gS_BotName[style], MAX_NAME_LENGTH, "%s - %N", sWRTime, client); FormatEx(gS_BotName[style], MAX_NAME_LENGTH, "%s - %N", sWRTime, client);
if(gI_ReplayBotClient[style] != 0) if(gI_ReplayBotClient[style] != 0)
{ {
// I won't be hiding this message, players can easily see the new WR like that. // I won't be hiding this message, players can easily see the new WR like that.
// gB_ShowNameChanges = false; // gB_ShowNameChanges = false;
SetClientName(gI_ReplayBotClient[style], gS_BotName[style]); SetClientName(gI_ReplayBotClient[style], gS_BotName[style]);
} }
gA_PlayerFrames[client].Clear(); gA_PlayerFrames[client].Clear();
SaveReplay(style); SaveReplay(style);
} }
@ -459,94 +459,94 @@ public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float vel[3
{ {
float vecPosition[3]; float vecPosition[3];
GetClientAbsOrigin(client, vecPosition); GetClientAbsOrigin(client, vecPosition);
if(client == gI_ReplayBotClient[Style_Forwards] || client == gI_ReplayBotClient[Style_Sideways]) if(client == gI_ReplayBotClient[Style_Forwards] || client == gI_ReplayBotClient[Style_Sideways])
{ {
SetEntProp(client, Prop_Data, "m_CollisionGroup", 1); SetEntProp(client, Prop_Data, "m_CollisionGroup", 1);
BhopStyle style = (client == gI_ReplayBotClient[Style_Forwards]? Style_Forwards:Style_Sideways); BhopStyle style = (client == gI_ReplayBotClient[Style_Forwards]? Style_Forwards:Style_Sideways);
if(gA_Frames[style] == null) // if no replay is loaded if(gA_Frames[style] == null) // if no replay is loaded
{ {
return Plugin_Continue; return Plugin_Continue;
} }
float fWRTime; float fWRTime;
Shavit_GetWRTime(style, fWRTime); Shavit_GetWRTime(style, fWRTime);
if(fWRTime != 0.0 && gI_ReplayTick[style] != -1) if(fWRTime != 0.0 && gI_ReplayTick[style] != -1)
{ {
if(gI_ReplayTick[style] >= gA_Frames[style].Length - 10) if(gI_ReplayTick[style] >= gA_Frames[style].Length - 10)
{ {
gI_ReplayTick[style] = -1; gI_ReplayTick[style] = -1;
CreateTimer(1.5, ResetReplay, style, TIMER_FLAG_NO_MAPCHANGE); CreateTimer(1.5, ResetReplay, style, TIMER_FLAG_NO_MAPCHANGE);
return Plugin_Continue; return Plugin_Continue;
} }
if(gI_ReplayTick[style] == 1) if(gI_ReplayTick[style] == 1)
{ {
gF_StartTick[style] = GetEngineTime(); gF_StartTick[style] = GetEngineTime();
} }
gI_ReplayTick[style]++; gI_ReplayTick[style]++;
float vecCurrentPosition[3]; float vecCurrentPosition[3];
vecCurrentPosition[0] = GetArrayCell(gA_Frames[style], gI_ReplayTick[style] - 1, 0); vecCurrentPosition[0] = GetArrayCell(gA_Frames[style], gI_ReplayTick[style] - 1, 0);
vecCurrentPosition[1] = GetArrayCell(gA_Frames[style], gI_ReplayTick[style] - 1, 1); vecCurrentPosition[1] = GetArrayCell(gA_Frames[style], gI_ReplayTick[style] - 1, 1);
vecCurrentPosition[2] = GetArrayCell(gA_Frames[style], gI_ReplayTick[style] - 1, 2); vecCurrentPosition[2] = GetArrayCell(gA_Frames[style], gI_ReplayTick[style] - 1, 2);
float vecAngles[3]; float vecAngles[3];
vecAngles[0] = GetArrayCell(gA_Frames[style], gI_ReplayTick[style] - 1, 3); vecAngles[0] = GetArrayCell(gA_Frames[style], gI_ReplayTick[style] - 1, 3);
vecAngles[1] = GetArrayCell(gA_Frames[style], gI_ReplayTick[style] - 1, 4); vecAngles[1] = GetArrayCell(gA_Frames[style], gI_ReplayTick[style] - 1, 4);
float vecVelocity[3]; float vecVelocity[3];
float fDistance = 0.0; float fDistance = 0.0;
if(gA_Frames[style].Length >= gI_ReplayTick[style] + 1) if(gA_Frames[style].Length >= gI_ReplayTick[style] + 1)
{ {
float vecNextPosition[3]; float vecNextPosition[3];
vecNextPosition[0] = GetArrayCell(gA_Frames[style], gI_ReplayTick[style], 0); vecNextPosition[0] = GetArrayCell(gA_Frames[style], gI_ReplayTick[style], 0);
vecNextPosition[1] = GetArrayCell(gA_Frames[style], gI_ReplayTick[style], 1); vecNextPosition[1] = GetArrayCell(gA_Frames[style], gI_ReplayTick[style], 1);
vecNextPosition[2] = GetArrayCell(gA_Frames[style], gI_ReplayTick[style], 2); vecNextPosition[2] = GetArrayCell(gA_Frames[style], gI_ReplayTick[style], 2);
fDistance = GetVectorDistance(vecPosition, vecNextPosition); fDistance = GetVectorDistance(vecPosition, vecNextPosition);
MakeVectorFromPoints(vecCurrentPosition, vecNextPosition, vecVelocity); MakeVectorFromPoints(vecCurrentPosition, vecNextPosition, vecVelocity);
ScaleVector(vecVelocity, gF_Tickrate); ScaleVector(vecVelocity, gF_Tickrate);
} }
if(fDistance >= 25.0) if(fDistance >= 25.0)
{ {
TeleportEntity(client, vecCurrentPosition, vecAngles, vecVelocity); TeleportEntity(client, vecCurrentPosition, vecAngles, vecVelocity);
} }
else else
{ {
TeleportEntity(client, NULL_VECTOR, vecAngles, vecVelocity); TeleportEntity(client, NULL_VECTOR, vecAngles, vecVelocity);
} }
} }
} }
else else
{ {
if(gB_Record[client] && !Shavit_InsideZone(client, Zone_Start)) if(gB_Record[client] && !Shavit_InsideZone(client, Zone_Start))
{ {
gI_PlayerFrames[client]++; gI_PlayerFrames[client]++;
gA_PlayerFrames[client].Resize(gI_PlayerFrames[client]); gA_PlayerFrames[client].Resize(gI_PlayerFrames[client]);
SetArrayCell(gA_PlayerFrames[client], gI_PlayerFrames[client] - 1, vecPosition[0], 0); SetArrayCell(gA_PlayerFrames[client], gI_PlayerFrames[client] - 1, vecPosition[0], 0);
SetArrayCell(gA_PlayerFrames[client], gI_PlayerFrames[client] - 1, vecPosition[1], 1); SetArrayCell(gA_PlayerFrames[client], gI_PlayerFrames[client] - 1, vecPosition[1], 1);
SetArrayCell(gA_PlayerFrames[client], gI_PlayerFrames[client] - 1, vecPosition[2], 2); SetArrayCell(gA_PlayerFrames[client], gI_PlayerFrames[client] - 1, vecPosition[2], 2);
SetArrayCell(gA_PlayerFrames[client], gI_PlayerFrames[client] - 1, angles[0], 3); SetArrayCell(gA_PlayerFrames[client], gI_PlayerFrames[client] - 1, angles[0], 3);
SetArrayCell(gA_PlayerFrames[client], gI_PlayerFrames[client] - 1, angles[1], 4); SetArrayCell(gA_PlayerFrames[client], gI_PlayerFrames[client] - 1, angles[1], 4);
} }
} }
return Plugin_Continue; return Plugin_Continue;
} }
@ -558,13 +558,13 @@ public Action ResetReplay(Handle Timer, any data)
// https://forums.alliedmods.net/showthread.php?p=2307350 // https://forums.alliedmods.net/showthread.php?p=2307350
/** /**
* Copy a substring from source to destination * Copy a substring from source to destination
* *
* @param source String to copy from * @param source String to copy from
* @param start position to start at, 0 numbered. Negative means to start that many characters from the end. * @param start position to start at, 0 numbered. Negative means to start that many characters from the end.
* @param len number of characters to copy. Negative means to not copy that many characters from the end. * @param len number of characters to copy. Negative means to not copy that many characters from the end.
* @param destination String to copy to * @param destination String to copy to
* @param maxlen Length of destination string. Must be 1 or greater. * @param maxlen Length of destination string. Must be 1 or greater.
* *
* @return True on success, false if number of characters copied would be negative. * @return True on success, false if number of characters copied would be negative.
* NOTE: There is no mechanism to get the remaining characters of a string. * NOTE: There is no mechanism to get the remaining characters of a string.
* Instead, use strcopy with source[start] for that. * Instead, use strcopy with source[start] for that.
@ -575,38 +575,38 @@ stock bool SubString(const char[] source, int start, int len, char[] destination
{ {
ThrowError("Destination size must be 1 or greater, but was %d", maxlen); ThrowError("Destination size must be 1 or greater, but was %d", maxlen);
} }
if(len == 0) if(len == 0)
{ {
destination[0] = '\0'; destination[0] = '\0';
return true; return true;
} }
if(start < 0) if(start < 0)
{ {
start = strlen(source) + start; start = strlen(source) + start;
if(start < 0) if(start < 0)
{ {
start = 0; start = 0;
} }
} }
if(len < 0) if(len < 0)
{ {
len = strlen(source) + len - start; len = strlen(source) + len - start;
if(len < 0) if(len < 0)
{ {
return false; return false;
} }
} }
int realLength = len + 1 < maxlen? len + 1:maxlen; int realLength = len + 1 < maxlen? len + 1:maxlen;
strcopy(destination, realLength, source[start]); strcopy(destination, realLength, source[start]);
return true; return true;
} }
@ -614,11 +614,11 @@ stock bool SubString(const char[] source, int start, int len, char[] destination
* Remove the path from the map name * Remove the path from the map name
* This was intended to remove workshop paths. * This was intended to remove workshop paths.
* Used internally by MapEqual and FindMapStringInArray. * Used internally by MapEqual and FindMapStringInArray.
* *
* @param map Map name * @param map Map name
* @param destination String to copy map name to * @param destination String to copy map name to
* @param maxlen Length of destination string * @param maxlen Length of destination string
* *
* @return True if path was removed, false if map and destination are the same * @return True if path was removed, false if map and destination are the same
*/ */
stock bool RemoveMapPath(const char[] map, char[] destination, int maxlen) stock bool RemoveMapPath(const char[] map, char[] destination, int maxlen)
@ -627,13 +627,13 @@ stock bool RemoveMapPath(const char[] map, char[] destination, int maxlen)
{ {
ThrowError("Bad map name: %s", map); ThrowError("Bad map name: %s", map);
} }
int pos = FindCharInString(map, '/', true); int pos = FindCharInString(map, '/', true);
if(pos == -1) if(pos == -1)
{ {
pos = FindCharInString(map, '\\', true); pos = FindCharInString(map, '\\', true);
if(pos == -1) if(pos == -1)
{ {
strcopy(destination, maxlen, map); strcopy(destination, maxlen, map);
@ -642,9 +642,9 @@ stock bool RemoveMapPath(const char[] map, char[] destination, int maxlen)
} }
int len = strlen(map) - 1 - pos; int len = strlen(map) - 1 - pos;
SubString(map, pos + 1, len, destination, maxlen); SubString(map, pos + 1, len, destination, maxlen);
return true; return true;
} }
@ -670,7 +670,7 @@ stock bool File_Copy(const char[] source, const char[] destination)
if(file_destination == null) if(file_destination == null)
{ {
delete file_source; delete file_source;
return false; return false;
} }
@ -680,7 +680,7 @@ stock bool File_Copy(const char[] source, const char[] destination)
while(!IsEndOfFile(file_source)) while(!IsEndOfFile(file_source))
{ {
cache = ReadFile(file_source, buffer, 32, 1); cache = ReadFile(file_source, buffer, 32, 1);
WriteFile(file_destination, buffer, cache, 1); WriteFile(file_destination, buffer, cache, 1);
} }

View File

@ -7,7 +7,7 @@
* This program is free software; you can redistribute it and/or modify it under * 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 * the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation. * Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * 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 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
@ -28,7 +28,7 @@
// database handle // database handle
Database gH_SQL = null; Database gH_SQL = null;
public Plugin myinfo = public Plugin myinfo =
{ {
name = "[shavit] Player Stats", name = "[shavit] Player Stats",
author = "shavit", author = "shavit",
@ -43,7 +43,7 @@ public void OnAllPluginsLoaded()
{ {
SetFailState("shavit-wr is required for the plugin to work."); SetFailState("shavit-wr is required for the plugin to work.");
} }
// database shit // database shit
Shavit_GetDB(gH_SQL); Shavit_GetDB(gH_SQL);
} }
@ -52,13 +52,13 @@ public void OnPluginStart()
{ {
RegConsoleCmd("sm_profile", Command_Profile, "Show the player's profile. Usage: sm_profile [target]"); RegConsoleCmd("sm_profile", Command_Profile, "Show the player's profile. Usage: sm_profile [target]");
RegConsoleCmd("sm_stats", Command_Profile, "Show the player's profile. Usage: sm_profile [target]"); RegConsoleCmd("sm_stats", Command_Profile, "Show the player's profile. Usage: sm_profile [target]");
RegConsoleCmd("sm_mapsdone", Command_Mapsdone, "Show maps that the player have done already. Usage: sm_mapsdone [target]"); RegConsoleCmd("sm_mapsdone", Command_Mapsdone, "Show maps that the player have done already. Usage: sm_mapsdone [target]");
RegConsoleCmd("sm_mapsleft", Command_Mapsleft, "Show maps that the player doesn't have them cleared yet. Usage: sm_mapsleft [target]"); RegConsoleCmd("sm_mapsleft", Command_Mapsleft, "Show maps that the player doesn't have them cleared yet. Usage: sm_mapsleft [target]");
RegConsoleCmd("sm_mapsdonesw", Command_MapsdoneSW, "[SW] Show maps done. Usage: sm_mapsdonesw [target]"); RegConsoleCmd("sm_mapsdonesw", Command_MapsdoneSW, "[SW] Show maps done. Usage: sm_mapsdonesw [target]");
RegConsoleCmd("sm_mapsleftsw", Command_MapsleftSW, "[SW] Show maps that the player doesn't have them cleared yet. Usage: sm_mapsleftsw [target]"); RegConsoleCmd("sm_mapsleftsw", Command_MapsleftSW, "[SW] Show maps that the player doesn't have them cleared yet. Usage: sm_mapsleftsw [target]");
LoadTranslations("common.phrases"); LoadTranslations("common.phrases");
} }
@ -68,24 +68,24 @@ public Action Command_Mapsdone(int client, int args)
{ {
return Plugin_Handled; return Plugin_Handled;
} }
int target = client; int target = client;
if(args > 0) if(args > 0)
{ {
char sArgs[64]; char sArgs[64];
GetCmdArgString(sArgs, 64); GetCmdArgString(sArgs, 64);
target = FindTarget(client, sArgs, true, false); target = FindTarget(client, sArgs, true, false);
if(target == -1) if(target == -1)
{ {
return Plugin_Handled; return Plugin_Handled;
} }
} }
ShowMaps(client, target, "mapsdone"); ShowMaps(client, target, "mapsdone");
return Plugin_Handled; return Plugin_Handled;
} }
@ -95,24 +95,24 @@ public Action Command_Mapsleft(int client, int args)
{ {
return Plugin_Handled; return Plugin_Handled;
} }
int target = client; int target = client;
if(args > 0) if(args > 0)
{ {
char sArgs[64]; char sArgs[64];
GetCmdArgString(sArgs, 64); GetCmdArgString(sArgs, 64);
target = FindTarget(client, sArgs, true, false); target = FindTarget(client, sArgs, true, false);
if(target == -1) if(target == -1)
{ {
return Plugin_Handled; return Plugin_Handled;
} }
} }
ShowMaps(client, target, "mapsleft"); ShowMaps(client, target, "mapsleft");
return Plugin_Handled; return Plugin_Handled;
} }
@ -122,24 +122,24 @@ public Action Command_MapsdoneSW(int client, int args)
{ {
return Plugin_Handled; return Plugin_Handled;
} }
int target = client; int target = client;
if(args > 0) if(args > 0)
{ {
char sArgs[64]; char sArgs[64];
GetCmdArgString(sArgs, 64); GetCmdArgString(sArgs, 64);
target = FindTarget(client, sArgs, true, false); target = FindTarget(client, sArgs, true, false);
if(target == -1) if(target == -1)
{ {
return Plugin_Handled; return Plugin_Handled;
} }
} }
ShowMaps(client, target, "mapsdonesw"); ShowMaps(client, target, "mapsdonesw");
return Plugin_Handled; return Plugin_Handled;
} }
@ -149,24 +149,24 @@ public Action Command_MapsleftSW(int client, int args)
{ {
return Plugin_Handled; return Plugin_Handled;
} }
int target = client; int target = client;
if(args > 0) if(args > 0)
{ {
char sArgs[64]; char sArgs[64];
GetCmdArgString(sArgs, 64); GetCmdArgString(sArgs, 64);
target = FindTarget(client, sArgs, true, false); target = FindTarget(client, sArgs, true, false);
if(target == -1) if(target == -1)
{ {
return Plugin_Handled; return Plugin_Handled;
} }
} }
ShowMaps(client, target, "mapsleftsw"); ShowMaps(client, target, "mapsleftsw");
return Plugin_Handled; return Plugin_Handled;
} }
@ -176,42 +176,42 @@ public Action Command_Profile(int client, int args)
{ {
return Plugin_Handled; return Plugin_Handled;
} }
int target = client; int target = client;
if(args > 0) if(args > 0)
{ {
char sArgs[64]; char sArgs[64];
GetCmdArgString(sArgs, 64); GetCmdArgString(sArgs, 64);
target = FindTarget(client, sArgs, true, false); target = FindTarget(client, sArgs, true, false);
if(target == -1) if(target == -1)
{ {
return Plugin_Handled; return Plugin_Handled;
} }
} }
char sAuthID[32]; char sAuthID[32];
GetClientAuthId(target, AuthId_Steam3, sAuthID, 32); GetClientAuthId(target, AuthId_Steam3, sAuthID, 32);
Menu menu = CreateMenu(MenuHandler_Profile); Menu menu = CreateMenu(MenuHandler_Profile);
menu.SetTitle("%N's profile.\nSteamID3: %s", target, sAuthID); menu.SetTitle("%N's profile.\nSteamID3: %s", target, sAuthID);
menu.AddItem("mapsdone", "Maps done (Forwards)"); menu.AddItem("mapsdone", "Maps done (Forwards)");
menu.AddItem("mapsleft", "Maps left (Forwards)"); menu.AddItem("mapsleft", "Maps left (Forwards)");
menu.AddItem("mapsdonesw", "Maps done (Sideways)"); menu.AddItem("mapsdonesw", "Maps done (Sideways)");
menu.AddItem("mapsleftsw", "Maps left (Sideways)"); menu.AddItem("mapsleftsw", "Maps left (Sideways)");
char sTarget[8]; char sTarget[8];
IntToString(target, sTarget, 8); IntToString(target, sTarget, 8);
AddMenuItem(menu, "id", sTarget, ITEMDRAW_IGNORE); AddMenuItem(menu, "id", sTarget, ITEMDRAW_IGNORE);
SetMenuExitButton(menu, true); SetMenuExitButton(menu, true);
DisplayMenu(menu, client, 20); DisplayMenu(menu, client, 20);
return Plugin_Handled; return Plugin_Handled;
} }
@ -220,27 +220,27 @@ public int MenuHandler_Profile(Menu menu, MenuAction action, int param1, int par
if(action == MenuAction_Select) if(action == MenuAction_Select)
{ {
char info[16]; char info[16];
int target; int target;
for(int i = 0; i < menu.ItemCount; i++) for(int i = 0; i < menu.ItemCount; i++)
{ {
char data[8]; char data[8];
menu.GetItem(i, info, 16, _, data, 8); menu.GetItem(i, info, 16, _, data, 8);
if(StrEqual(info, "id")) if(StrEqual(info, "id"))
{ {
target = StringToInt(data); target = StringToInt(data);
break; break;
} }
} }
menu.GetItem(param2, info, 16); menu.GetItem(param2, info, 16);
ShowMaps(param1, target, info); ShowMaps(param1, target, info);
} }
else if(action == MenuAction_End) else if(action == MenuAction_End)
{ {
CloseHandle(menu); CloseHandle(menu);
@ -252,25 +252,25 @@ public void ShowMaps(int client, int target, const char[] category)
{ {
char sAuth[32]; char sAuth[32];
GetClientAuthId(target, AuthId_Steam3, sAuth, 32); GetClientAuthId(target, AuthId_Steam3, sAuth, 32);
char sQuery[256]; char sQuery[256];
if(StrContains(category, "done") != -1) if(StrContains(category, "done") != -1)
{ {
FormatEx(sQuery, 256, "SELECT map, time, jumps FROM playertimes WHERE auth = '%s' AND style = %d ORDER BY map;", sAuth, StrEqual(category, "mapsdone")? 0:1); FormatEx(sQuery, 256, "SELECT map, time, jumps FROM playertimes WHERE auth = '%s' AND style = %d ORDER BY map;", sAuth, StrEqual(category, "mapsdone")? 0:1);
} }
else else
{ {
FormatEx(sQuery, 256, "SELECT DISTINCT m.map FROM mapzones m LEFT JOIN playertimes r ON r.map = m.map AND r.auth = '%s' AND r.style = %d WHERE r.map IS NULL ORDER BY m.map;", sAuth, StrEqual(category, "mapsleft")? 0:1); FormatEx(sQuery, 256, "SELECT DISTINCT m.map FROM mapzones m LEFT JOIN playertimes r ON r.map = m.map AND r.auth = '%s' AND r.style = %d WHERE r.map IS NULL ORDER BY m.map;", sAuth, StrEqual(category, "mapsleft")? 0:1);
// PrintToConsole(client, sQuery); // PrintToConsole(client, sQuery);
} }
DataPack datapack = CreateDataPack(); DataPack datapack = CreateDataPack();
datapack.WriteCell(GetClientSerial(client)); datapack.WriteCell(GetClientSerial(client));
datapack.WriteCell(GetClientSerial(target)); datapack.WriteCell(GetClientSerial(target));
datapack.WriteString(category); datapack.WriteString(category);
SQL_TQuery(gH_SQL, ShowMapsCallback, sQuery, datapack, DBPrio_High); SQL_TQuery(gH_SQL, ShowMapsCallback, sQuery, datapack, DBPrio_High);
} }
@ -279,97 +279,97 @@ public void ShowMapsCallback(Handle owner, Handle hndl, const char[] error, any
if(hndl == null) if(hndl == null)
{ {
CloseHandle(data); CloseHandle(data);
LogError("Timer (ShowMaps SELECT) SQL query failed. Reason: %s", error); LogError("Timer (ShowMaps SELECT) SQL query failed. Reason: %s", error);
return; return;
} }
ResetPack(data); ResetPack(data);
int clientserial = ReadPackCell(data); int clientserial = ReadPackCell(data);
int targetserial = ReadPackCell(data); int targetserial = ReadPackCell(data);
char sCategory[16]; char sCategory[16];
ReadPackString(data, sCategory, 16); ReadPackString(data, sCategory, 16);
CloseHandle(data); CloseHandle(data);
int client = GetClientFromSerial(clientserial); int client = GetClientFromSerial(clientserial);
if(!IsValidClient(client)) if(!IsValidClient(client))
{ {
return; return;
} }
int target = GetClientFromSerial(targetserial); int target = GetClientFromSerial(targetserial);
if(!IsValidClient(client)) if(!IsValidClient(client))
{ {
return; return;
} }
int rows = SQL_GetRowCount(hndl); int rows = SQL_GetRowCount(hndl);
char sTitle[64]; char sTitle[64];
if(StrEqual(sCategory, "mapsdone")) if(StrEqual(sCategory, "mapsdone"))
{ {
FormatEx(sTitle, 32, "Maps done for %N: (%d)", target, rows); FormatEx(sTitle, 32, "Maps done for %N: (%d)", target, rows);
} }
else if(StrEqual(sCategory, "mapsleft")) else if(StrEqual(sCategory, "mapsleft"))
{ {
FormatEx(sTitle, 32, "Maps left for %N: (%d)", target, rows); FormatEx(sTitle, 32, "Maps left for %N: (%d)", target, rows);
} }
else if(StrEqual(sCategory, "mapsdonesw")) else if(StrEqual(sCategory, "mapsdonesw"))
{ {
FormatEx(sTitle, 32, "[SW] Maps done for %N: (%d)", target, rows); FormatEx(sTitle, 32, "[SW] Maps done for %N: (%d)", target, rows);
} }
else if(StrEqual(sCategory, "mapsleftsw")) else if(StrEqual(sCategory, "mapsleftsw"))
{ {
FormatEx(sTitle, 32, "[SW] Maps left for %N: (%d)", target, rows); FormatEx(sTitle, 32, "[SW] Maps left for %N: (%d)", target, rows);
} }
Menu menu = CreateMenu(MenuHandler_ShowMaps); Menu menu = CreateMenu(MenuHandler_ShowMaps);
menu.SetTitle(sTitle); menu.SetTitle(sTitle);
while(SQL_FetchRow(hndl)) while(SQL_FetchRow(hndl))
{ {
char sMap[128]; char sMap[128];
SQL_FetchString(hndl, 0, sMap, 128); SQL_FetchString(hndl, 0, sMap, 128);
char sDisplay[192]; char sDisplay[192];
if(StrContains(sCategory, "done") != -1) if(StrContains(sCategory, "done") != -1)
{ {
float time = SQL_FetchFloat(hndl, 1); float time = SQL_FetchFloat(hndl, 1);
int jumps = SQL_FetchInt(hndl, 2); int jumps = SQL_FetchInt(hndl, 2);
char sTime[32]; char sTime[32];
FormatSeconds(time, sTime, 32); FormatSeconds(time, sTime, 32);
FormatEx(sDisplay, 192, "%s - %s (%d jumps)", sMap, sTime, jumps); FormatEx(sDisplay, 192, "%s - %s (%d jumps)", sMap, sTime, jumps);
} }
else else
{ {
FormatEx(sDisplay, 192, "%s", sMap); FormatEx(sDisplay, 192, "%s", sMap);
} }
// adding map as info, may be used in the future // adding map as info, may be used in the future
menu.AddItem(sMap, sDisplay); menu.AddItem(sMap, sDisplay);
} }
if(!GetMenuItemCount(menu)) if(!GetMenuItemCount(menu))
{ {
AddMenuItem(menu, "nope", "No results."); AddMenuItem(menu, "nope", "No results.");
} }
menu.ExitButton = true; menu.ExitButton = true;
menu.Display(client, 60); menu.Display(client, 60);
} }

View File

@ -7,7 +7,7 @@
* This program is free software; you can redistribute it and/or modify it under * 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 * the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation. * Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * 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 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
@ -43,7 +43,7 @@ ConVar gCV_MinimumTimes = null;
ConVar gCV_PlayerAmount = null; ConVar gCV_PlayerAmount = null;
ConVar gCV_Style = null; ConVar gCV_Style = null;
public Plugin myinfo = public Plugin myinfo =
{ {
name = "[shavit] Dynamic Timelimits", name = "[shavit] Dynamic Timelimits",
author = "shavit", author = "shavit",
@ -58,7 +58,7 @@ public void OnAllPluginsLoaded()
{ {
SetFailState("shavit-wr is required for the plugin to work."); SetFailState("shavit-wr is required for the plugin to work.");
} }
// database shit // database shit
Shavit_GetDB(gH_SQL); Shavit_GetDB(gH_SQL);
} }
@ -66,17 +66,17 @@ public void OnAllPluginsLoaded()
public void OnPluginStart() public void OnPluginStart()
{ {
gCV_TimeLimit = FindConVar("mp_timelimit"); gCV_TimeLimit = FindConVar("mp_timelimit");
gCV_RoundTime = FindConVar("mp_roundtime"); gCV_RoundTime = FindConVar("mp_roundtime");
gCV_RoundTime.SetBounds(ConVarBound_Upper, false); gCV_RoundTime.SetBounds(ConVarBound_Upper, false);
gCV_RestartGame = FindConVar("mp_restartgame"); gCV_RestartGame = FindConVar("mp_restartgame");
gCV_DefaultLimit = CreateConVar("shavit_timelimit_default", "60.0", "Default timelimit to use in case there isn't an average.", FCVAR_PLUGIN, true, 10.0); gCV_DefaultLimit = CreateConVar("shavit_timelimit_default", "60.0", "Default timelimit to use in case there isn't an average.", FCVAR_PLUGIN, true, 10.0);
gCV_MinimumTimes = CreateConVar("shavit_timelimit_minimumtimes", "5", "Minimum amount of times required to calculate an average.", FCVAR_PLUGIN, true, 5.0); gCV_MinimumTimes = CreateConVar("shavit_timelimit_minimumtimes", "5", "Minimum amount of times required to calculate an average.", FCVAR_PLUGIN, true, 5.0);
gCV_PlayerAmount = CreateConVar("shavit_timelimit_playertime", "25", "Limited amount of times to grab from the database to calculate an average.\nSet to 0 to have it \"unlimited\".", FCVAR_PLUGIN); gCV_PlayerAmount = CreateConVar("shavit_timelimit_playertime", "25", "Limited amount of times to grab from the database to calculate an average.\nSet to 0 to have it \"unlimited\".", FCVAR_PLUGIN);
gCV_Style = CreateConVar("shavit_timelimit_style", "1", "If set to 1, calculate an average only from times that the \"forwards\" style was used to set.", FCVAR_PLUGIN, true, 0.0, true, 1.0); gCV_Style = CreateConVar("shavit_timelimit_style", "1", "If set to 1, calculate an average only from times that the \"forwards\" style was used to set.", FCVAR_PLUGIN, true, 0.0, true, 1.0);
AutoExecConfig(); AutoExecConfig();
} }
@ -86,14 +86,14 @@ public void OnMapStart()
{ {
char sMap[128]; char sMap[128];
GetCurrentMap(sMap, 128); GetCurrentMap(sMap, 128);
char sQuery[256]; char sQuery[256];
FormatEx(sQuery, 256, "SELECT time FROM playertimes WHERE map = '%s' %sLIMIT %d;", sMap, gCV_Style.BoolValue? "AND style = 0 ":"", gCV_PlayerAmount.IntValue); FormatEx(sQuery, 256, "SELECT time FROM playertimes WHERE map = '%s' %sLIMIT %d;", sMap, gCV_Style.BoolValue? "AND style = 0 ":"", gCV_PlayerAmount.IntValue);
#if defined DEBUG #if defined DEBUG
PrintToServer(sQuery); PrintToServer(sQuery);
#endif #endif
SQL_TQuery(gH_SQL, SQL_GetMapTimes, sQuery, 0, DBPrio_High); SQL_TQuery(gH_SQL, SQL_GetMapTimes, sQuery, 0, DBPrio_High);
} }
} }
@ -106,80 +106,80 @@ public void SQL_GetMapTimes(Handle owner, Handle hndl, const char[] error, any d
return; return;
} }
int iRows = SQL_GetRowCount(hndl); int iRows = SQL_GetRowCount(hndl);
if(iRows >= gCV_MinimumTimes.IntValue) if(iRows >= gCV_MinimumTimes.IntValue)
{ {
float fTotal = 0.0; float fTotal = 0.0;
while(SQL_FetchRow(hndl)) while(SQL_FetchRow(hndl))
{ {
fTotal += SQL_FetchFloat(hndl, 0); fTotal += SQL_FetchFloat(hndl, 0);
#if defined DEBUG #if defined DEBUG
PrintToServer("total: %.02f", fTotal); PrintToServer("total: %.02f", fTotal);
#endif #endif
} }
float fAverage = (fTotal / 60 / iRows); float fAverage = (fTotal / 60 / iRows);
#if defined DEBUG #if defined DEBUG
PrintToServer("fAverage 1: %.02f", fAverage); PrintToServer("fAverage 1: %.02f", fAverage);
#endif #endif
if(fAverage <= 1) if(fAverage <= 1)
{ {
fAverage *= 10; fAverage *= 10;
} }
else if(fAverage <= 2) else if(fAverage <= 2)
{ {
fAverage *= 9; fAverage *= 9;
} }
else if(fAverage <= 4) else if(fAverage <= 4)
{ {
fAverage *= 8; fAverage *= 8;
} }
else if(fAverage <= 8) else if(fAverage <= 8)
{ {
fAverage *= 7; fAverage *= 7;
} }
else if(fAverage <= 10) else if(fAverage <= 10)
{ {
fAverage *= 6; fAverage *= 6;
} }
#if defined DEBUG #if defined DEBUG
PrintToServer("fAverage 2: %.02f", fAverage); PrintToServer("fAverage 2: %.02f", fAverage);
#endif #endif
fAverage += 5; // I give extra 5 minutes, so players can actually retry the map until they get a good time. fAverage += 5; // I give extra 5 minutes, so players can actually retry the map until they get a good time.
#if defined DEBUG #if defined DEBUG
PrintToServer("fAverage 3: %.02f", fAverage); PrintToServer("fAverage 3: %.02f", fAverage);
#endif #endif
if(fAverage < 20) if(fAverage < 20)
{ {
fAverage = 20.0; fAverage = 20.0;
} }
else if(fAverage > 120) else if(fAverage > 120)
{ {
fAverage = 120.0; fAverage = 120.0;
} }
#if defined DEBUG #if defined DEBUG
PrintToServer("fAverage 4: %.02f", fAverage); PrintToServer("fAverage 4: %.02f", fAverage);
#endif #endif
SetLimit(RoundToNearest(fAverage)); SetLimit(RoundToNearest(fAverage));
} }
else else
{ {
SetLimit(RoundToNearest(gCV_DefaultLimit.FloatValue)); SetLimit(RoundToNearest(gCV_DefaultLimit.FloatValue));
@ -190,6 +190,6 @@ public void SetLimit(int time)
{ {
gCV_TimeLimit.SetInt(time); gCV_TimeLimit.SetInt(time);
gCV_RoundTime.SetInt(time); gCV_RoundTime.SetInt(time);
gCV_RestartGame.IntValue = 1; gCV_RestartGame.IntValue = 1;
} }

View File

@ -7,7 +7,7 @@
* This program is free software; you can redistribute it and/or modify it under * 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 * the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation. * Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * 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 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
@ -51,7 +51,7 @@ float gF_PlayerRecord[MAXPLAYERS+1][MAX_STYLES];
// admin menu // admin menu
Handle gH_AdminMenu = null; Handle gH_AdminMenu = null;
public Plugin myinfo = public Plugin myinfo =
{ {
name = "[shavit] World Records", name = "[shavit] World Records",
author = "shavit", author = "shavit",
@ -68,7 +68,7 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max
// get pb // get pb
CreateNative("Shavit_GetPlayerPB", Native_GetPlayerPB); CreateNative("Shavit_GetPlayerPB", Native_GetPlayerPB);
MarkNativeAsOptional("Shavit_GetWRTime"); MarkNativeAsOptional("Shavit_GetWRTime");
MarkNativeAsOptional("Shavit_GetWRName"); MarkNativeAsOptional("Shavit_GetWRName");
MarkNativeAsOptional("Shavit_GetPlayerPB"); MarkNativeAsOptional("Shavit_GetPlayerPB");
@ -117,7 +117,7 @@ public void OnAdminMenuReady(Handle topmenu)
if(LibraryExists("adminmenu") && ((gH_AdminMenu = GetAdminTopMenu()) != null)) if(LibraryExists("adminmenu") && ((gH_AdminMenu = GetAdminTopMenu()) != null))
{ {
TopMenuObject tmoTimer = FindTopMenuCategory(gH_AdminMenu, "Timer Commands"); TopMenuObject tmoTimer = FindTopMenuCategory(gH_AdminMenu, "Timer Commands");
if(tmoTimer != INVALID_TOPMENUOBJECT) if(tmoTimer != INVALID_TOPMENUOBJECT)
{ {
AddToTopMenu(gH_AdminMenu, "sm_deleteall", TopMenuObject_Item, AdminMenu_DeleteAll, tmoTimer, "sm_deleteall", ADMFLAG_RCON); AddToTopMenu(gH_AdminMenu, "sm_deleteall", TopMenuObject_Item, AdminMenu_DeleteAll, tmoTimer, "sm_deleteall", ADMFLAG_RCON);
@ -361,7 +361,7 @@ public Action Command_DeleteAll(int client, int args)
} }
AddMenuItem(menu, "yes", "YES!!! DELETE ALL THE RECORDS!!! THIS ACTION CANNOT BE REVERTED!!!"); AddMenuItem(menu, "yes", "YES!!! DELETE ALL THE RECORDS!!! THIS ACTION CANNOT BE REVERTED!!!");
for(int i = 1; i <= GetRandomInt(1, 3); i++) for(int i = 1; i <= GetRandomInt(1, 3); i++)
{ {
AddMenuItem(menu, "-1", "NO!"); AddMenuItem(menu, "-1", "NO!");
@ -387,7 +387,7 @@ public int MenuHandler_DeleteAll(Handle menu, MenuAction action, int param1, int
return; return;
} }
char sQuery[256]; char sQuery[256];
FormatEx(sQuery, 256, "DELETE FROM playertimes WHERE map = '%s';", gS_Map); FormatEx(sQuery, 256, "DELETE FROM playertimes WHERE map = '%s';", gS_Map);
@ -502,7 +502,7 @@ public int OpenDelete_Handler(Handle menu, MenuAction action, int param1, int pa
{ {
char info[16]; char info[16];
GetMenuItem(menu, param2, info, 16); GetMenuItem(menu, param2, info, 16);
if(StringToInt(info) == -1) if(StringToInt(info) == -1)
{ {
return; return;
@ -517,7 +517,7 @@ public int OpenDelete_Handler(Handle menu, MenuAction action, int param1, int pa
} }
AddMenuItem(hMenu, info, "YES!!! DELETE THE RECORD!!!"); AddMenuItem(hMenu, info, "YES!!! DELETE THE RECORD!!!");
for(int i = 1; i <= GetRandomInt(1, 3); i++) for(int i = 1; i <= GetRandomInt(1, 3); i++)
{ {
AddMenuItem(hMenu, "-1", "NO!"); AddMenuItem(hMenu, "-1", "NO!");
@ -547,7 +547,7 @@ public int DeleteConfirm_Handler(Handle menu, MenuAction action, int param1, int
return; return;
} }
char sQuery[256]; char sQuery[256];
FormatEx(sQuery, 256, "DELETE FROM playertimes WHERE id = '%s';", info); FormatEx(sQuery, 256, "DELETE FROM playertimes WHERE id = '%s';", info);
@ -568,7 +568,7 @@ public void DeleteConfirm_Callback(Handle owner, Handle hndl, const char[] error
return; return;
} }
UpdateWRCache(); UpdateWRCache();
for(int i = 1; i <= MaxClients; i++) for(int i = 1; i <= MaxClients; i++)
@ -594,7 +594,7 @@ public void DeleteAll_Callback(Handle owner, Handle hndl, const char[] error, an
return; return;
} }
UpdateWRCache(); UpdateWRCache();
for(int i = 1; i <= MaxClients; i++) for(int i = 1; i <= MaxClients; i++)
@ -618,19 +618,19 @@ public Action Command_WR(int client, int args)
{ {
return Plugin_Handled; return Plugin_Handled;
} }
char sMap[128]; char sMap[128];
if(!args) if(!args)
{ {
strcopy(sMap, 128, gS_Map); strcopy(sMap, 128, gS_Map);
} }
else else
{ {
GetCmdArgString(sMap, 128); GetCmdArgString(sMap, 128);
} }
StartWRMenu(client, sMap, view_as<int>(Style_Forwards)); StartWRMenu(client, sMap, view_as<int>(Style_Forwards));
return Plugin_Handled; return Plugin_Handled;
@ -642,19 +642,19 @@ public Action Command_WRSW(int client, int args)
{ {
return Plugin_Handled; return Plugin_Handled;
} }
char sMap[128]; char sMap[128];
if(!args) if(!args)
{ {
strcopy(sMap, 128, gS_Map); strcopy(sMap, 128, gS_Map);
} }
else else
{ {
GetCmdArgString(sMap, 128); GetCmdArgString(sMap, 128);
} }
StartWRMenu(client, sMap, view_as<int>(Style_Sideways)); StartWRMenu(client, sMap, view_as<int>(Style_Sideways));
return Plugin_Handled; return Plugin_Handled;
@ -663,30 +663,30 @@ public Action Command_WRSW(int client, int args)
public void StartWRMenu(int client, const char[] map, int style) public void StartWRMenu(int client, const char[] map, int style)
{ {
gBS_LastWR[client] = view_as<BhopStyle>(style); gBS_LastWR[client] = view_as<BhopStyle>(style);
DataPack dp = CreateDataPack(); DataPack dp = CreateDataPack();
dp.WriteCell(GetClientSerial(client)); dp.WriteCell(GetClientSerial(client));
dp.WriteString(map); dp.WriteString(map);
char sQuery[512]; char sQuery[512];
FormatEx(sQuery, 512, "SELECT p.id, u.name, p.time, p.jumps, p.auth, (SELECT COUNT(*) FROM playertimes WHERE map = '%s' AND style = %d) AS records FROM playertimes p JOIN users u ON p.auth = u.auth WHERE map = '%s' AND style = %d ORDER BY time ASC LIMIT 50;", map, style, map, style); FormatEx(sQuery, 512, "SELECT p.id, u.name, p.time, p.jumps, p.auth, (SELECT COUNT(*) FROM playertimes WHERE map = '%s' AND style = %d) AS records FROM playertimes p JOIN users u ON p.auth = u.auth WHERE map = '%s' AND style = %d ORDER BY time ASC LIMIT 50;", map, style, map, style);
SQL_TQuery(gH_SQL, SQL_WR_Callback, sQuery, dp, DBPrio_High); SQL_TQuery(gH_SQL, SQL_WR_Callback, sQuery, dp, DBPrio_High);
return; return;
} }
public void SQL_WR_Callback(Handle owner, Handle hndl, const char[] error, any data) public void SQL_WR_Callback(Handle owner, Handle hndl, const char[] error, any data)
{ {
ResetPack(data); ResetPack(data);
int serial = ReadPackCell(data); int serial = ReadPackCell(data);
char sMap[128]; char sMap[128];
ReadPackString(data, sMap, 128); ReadPackString(data, sMap, 128);
CloseHandle(data); CloseHandle(data);
if(hndl == null) if(hndl == null)
{ {
LogError("Timer (WR SELECT) SQL query failed. Reason: %s", error); LogError("Timer (WR SELECT) SQL query failed. Reason: %s", error);
@ -700,7 +700,7 @@ public void SQL_WR_Callback(Handle owner, Handle hndl, const char[] error, any d
{ {
return; return;
} }
char sAuth[32]; char sAuth[32];
GetClientAuthId(client, AuthId_Steam3, sAuth, 32); GetClientAuthId(client, AuthId_Steam3, sAuth, 32);
@ -708,13 +708,13 @@ public void SQL_WR_Callback(Handle owner, Handle hndl, const char[] error, any d
int iCount = 0; int iCount = 0;
int iMyRank = 0; int iMyRank = 0;
int iRecords = 0; int iRecords = 0;
while(SQL_FetchRow(hndl)) while(SQL_FetchRow(hndl))
{ {
iCount++; iCount++;
// 0 - record id, for statistic purposes. // 0 - record id, for statistic purposes.
int id = SQL_FetchInt(hndl, 0); int id = SQL_FetchInt(hndl, 0);
char sID[8]; char sID[8];
@ -731,21 +731,21 @@ public void SQL_WR_Callback(Handle owner, Handle hndl, const char[] error, any d
// 3 - jumps // 3 - jumps
int iJumps = SQL_FetchInt(hndl, 3); int iJumps = SQL_FetchInt(hndl, 3);
// add item to menu // add item to menu
char sDisplay[128]; char sDisplay[128];
FormatEx(sDisplay, 128, "#%d - %s - %s (%d Jumps)", iCount, sName, sTime, iJumps); FormatEx(sDisplay, 128, "#%d - %s - %s (%d Jumps)", iCount, sName, sTime, iJumps);
AddMenuItem(menu, sID, sDisplay); AddMenuItem(menu, sID, sDisplay);
// check if record exists in the map's top X // check if record exists in the map's top X
char sQueryAuth[32]; char sQueryAuth[32];
SQL_FetchString(hndl, 4, sQueryAuth, 32); SQL_FetchString(hndl, 4, sQueryAuth, 32);
if(StrEqual(sQueryAuth, sAuth)) if(StrEqual(sQueryAuth, sAuth))
{ {
iMyRank = iCount; iMyRank = iCount;
} }
// fetch amount of records // fetch amount of records
if(iRecords == 0) if(iRecords == 0)
{ {
@ -756,25 +756,25 @@ public void SQL_WR_Callback(Handle owner, Handle hndl, const char[] error, any d
if(!GetMenuItemCount(menu)) if(!GetMenuItemCount(menu))
{ {
SetMenuTitle(menu, "Records for %s", sMap); SetMenuTitle(menu, "Records for %s", sMap);
AddMenuItem(menu, "-1", "No records found."); AddMenuItem(menu, "-1", "No records found.");
} }
else else
{ {
// [32] just in case there are 150k records on a map and you're ranked 100k or something // [32] just in case there are 150k records on a map and you're ranked 100k or something
char sRanks[32]; char sRanks[32];
if(gF_PlayerRecord[client][gBS_LastWR[client]] == 0.0) if(gF_PlayerRecord[client][gBS_LastWR[client]] == 0.0)
{ {
FormatEx(sRanks, 32, "(%d record%s)", iRecords, iRecords == 1? "":"s"); FormatEx(sRanks, 32, "(%d record%s)", iRecords, iRecords == 1? "":"s");
} }
else else
{ {
FormatEx(sRanks, 32, "(#%d/%d)", iMyRank, iRecords); FormatEx(sRanks, 32, "(#%d/%d)", iMyRank, iRecords);
} }
SetMenuTitle(menu, "Records for %s:\n%s", sMap, sRanks); SetMenuTitle(menu, "Records for %s:\n%s", sMap, sRanks);
} }
@ -931,14 +931,14 @@ public void SQL_CreateTable_Callback(Handle owner, Handle hndl, const char[] err
return; return;
} }
if(gB_Late) if(gB_Late)
{ {
for(int i = 1; i <= MaxClients; i++) for(int i = 1; i <= MaxClients; i++)
{ {
OnClientPutInServer(i); OnClientPutInServer(i);
} }
gB_Late = false; gB_Late = false;
} }
} }
@ -950,14 +950,14 @@ public void SQL_CreateTable_Callback(Handle owner, Handle hndl, const char[] err
{ {
return thing * -1; return thing * -1;
} }
return thing; return thing;
}*/ }*/
public void Shavit_OnFinish(int client, BhopStyle style, float time, int jumps) public void Shavit_OnFinish(int client, BhopStyle style, float time, int jumps)
{ {
BhopStyle bsStyle = view_as<BhopStyle>(style); BhopStyle bsStyle = view_as<BhopStyle>(style);
char sTime[32]; char sTime[32];
FormatSeconds(time, sTime, 32); FormatSeconds(time, sTime, 32);
@ -973,7 +973,7 @@ public void Shavit_OnFinish(int client, BhopStyle style, float time, int jumps)
UpdateWRCache(); UpdateWRCache();
} }
// 0 - no query // 0 - no query
// 1 - insert // 1 - insert
// 2 - update // 2 - update
@ -988,40 +988,40 @@ public void Shavit_OnFinish(int client, BhopStyle style, float time, int jumps)
{ {
overwrite = 2; overwrite = 2;
} }
float fDifference = (gF_PlayerRecord[client][style] - time) * -1.0; float fDifference = (gF_PlayerRecord[client][style] - time) * -1.0;
char sDifference[16]; char sDifference[16];
FormatSeconds(fDifference, sDifference, 16, true); FormatSeconds(fDifference, sDifference, 16, true);
if(overwrite > 0) if(overwrite > 0)
{ {
char sAuthID[32]; char sAuthID[32];
GetClientAuthId(client, AuthId_Steam3, sAuthID, 32); GetClientAuthId(client, AuthId_Steam3, sAuthID, 32);
char sQuery[512]; char sQuery[512];
if(overwrite == 1) // insert if(overwrite == 1) // insert
{ {
PrintToChatAll("%s \x03%N\x01 finished (%s) on \x07%s\x01 with %d jumps.", PREFIX, client, bsStyle == Style_Forwards? "Forwards":"Sideways", sTime, jumps); PrintToChatAll("%s \x03%N\x01 finished (%s) on \x07%s\x01 with %d jumps.", PREFIX, client, bsStyle == Style_Forwards? "Forwards":"Sideways", sTime, jumps);
// prevent duplicate records in case there's a long enough lag for the mysql server between two map finishes // prevent duplicate records in case there's a long enough lag for the mysql server between two map finishes
// TODO: work on a solution that can function the same while not causing lost records // TODO: work on a solution that can function the same while not causing lost records
if(gH_SQL == null) if(gH_SQL == null)
{ {
return; return;
} }
FormatEx(sQuery, 512, "INSERT INTO playertimes (auth, map, time, jumps, date, style) VALUES ('%s', '%s', %.03f, %d, CURRENT_TIMESTAMP(), '%d');", sAuthID, gS_Map, time, jumps, style); FormatEx(sQuery, 512, "INSERT INTO playertimes (auth, map, time, jumps, date, style) VALUES ('%s', '%s', %.03f, %d, CURRENT_TIMESTAMP(), '%d');", sAuthID, gS_Map, time, jumps, style);
} }
else // update else // update
{ {
PrintToChatAll("%s \x03%N\x01 finished (%s) on \x07%s\x01 with %d jumps. \x0C(%s)", PREFIX, client, bsStyle == Style_Forwards? "Forwards":"Sideways", sTime, jumps, sDifference); PrintToChatAll("%s \x03%N\x01 finished (%s) on \x07%s\x01 with %d jumps. \x0C(%s)", PREFIX, client, bsStyle == Style_Forwards? "Forwards":"Sideways", sTime, jumps, sDifference);
FormatEx(sQuery, 512, "UPDATE playertimes SET time = '%.03f', jumps = '%d', date = CURRENT_TIMESTAMP() WHERE map = '%s' AND auth = '%s' AND style = '%d';", time, jumps, gS_Map, sAuthID, style); FormatEx(sQuery, 512, "UPDATE playertimes SET time = '%.03f', jumps = '%d', date = CURRENT_TIMESTAMP() WHERE map = '%s' AND auth = '%s' AND style = '%d';", time, jumps, gS_Map, sAuthID, style);
} }
SQL_TQuery(gH_SQL, SQL_OnFinish_Callback, sQuery, GetClientSerial(client), DBPrio_High); SQL_TQuery(gH_SQL, SQL_OnFinish_Callback, sQuery, GetClientSerial(client), DBPrio_High);
} }
@ -1031,7 +1031,7 @@ public void Shavit_OnFinish(int client, BhopStyle style, float time, int jumps)
{ {
PrintToChat(client, "%s You have finished (%s) on \x07%s\x01 with %d jumps. \x08(+%s)", PREFIX, bsStyle == Style_Forwards? "Forwards":"Sideways", sTime, jumps, sDifference); PrintToChat(client, "%s You have finished (%s) on \x07%s\x01 with %d jumps. \x08(+%s)", PREFIX, bsStyle == Style_Forwards? "Forwards":"Sideways", sTime, jumps, sDifference);
} }
else else
{ {
PrintToChat(client, "%s You have finished (%s) on \x07%s\x01 with %d jumps.", PREFIX, bsStyle == Style_Forwards? "Forwards":"Sideways", sTime, jumps); PrintToChat(client, "%s You have finished (%s) on \x07%s\x01 with %d jumps.", PREFIX, bsStyle == Style_Forwards? "Forwards":"Sideways", sTime, jumps);

View File

@ -40,7 +40,7 @@ char gS_ZoneNames[MAX_ZONES][] =
"End Zone", // stops timer "End Zone", // stops timer
"Glitch Zone (Respawn Player)", // respawns the player "Glitch Zone (Respawn Player)", // respawns the player
"Glitch Zone (Stop Timer)", // stops the player's timer "Glitch Zone (Stop Timer)", // stops the player's timer
"Slay Player", // slays (kills) players which come to this zone "Slay Player", // slays (kills) players which come to this zone
"Freestyle Zone" // ignores style physics when at this zone. e.g. WASD when SWing "Freestyle Zone" // ignores style physics when at this zone. e.g. WASD when SWing
}; };
@ -112,7 +112,7 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max
// zone natives // zone natives
CreateNative("Shavit_ZoneExists", Native_ZoneExists); CreateNative("Shavit_ZoneExists", Native_ZoneExists);
CreateNative("Shavit_InsideZone", Native_InsideZone); CreateNative("Shavit_InsideZone", Native_InsideZone);
MarkNativeAsOptional("Shavit_ZoneExists"); MarkNativeAsOptional("Shavit_ZoneExists");
// MarkNativeAsOptional("Shavit_InsideZone"); // called in shavit-core // MarkNativeAsOptional("Shavit_InsideZone"); // called in shavit-core
@ -741,7 +741,7 @@ public Action OnPlayerRunCmd(int client, int &buttons)
if(gI_MapStep[client] == 1) if(gI_MapStep[client] == 1)
{ {
gV_Point1[client] = vOrigin; gV_Point1[client] = vOrigin;
// not gonna use gCV_Interval.FloatValue here as we need percision when setting up zones // not gonna use gCV_Interval.FloatValue here as we need percision when setting up zones
CreateTimer(0.1, Timer_Draw, client, TIMER_REPEAT); CreateTimer(0.1, Timer_Draw, client, TIMER_REPEAT);
@ -1385,7 +1385,7 @@ public Action Timer_Draw(Handle Timer, any data)
vPoints[7] = vOrigin; vPoints[7] = vOrigin;
CreateZonePoints(vPoints, gF_RotateAngle[data], gV_Fix1[data], gV_Fix2[data], 1337, false); CreateZonePoints(vPoints, gF_RotateAngle[data], gV_Fix1[data], gV_Fix2[data], 1337, false);
DrawZone(0, vPoints, gI_BeamSprite, 0, gI_Colors[gMZ_Type[data]], 0.1); DrawZone(0, vPoints, gI_BeamSprite, 0, gI_Colors[gMZ_Type[data]], 0.1);
return Plugin_Continue; return Plugin_Continue;
@ -1704,7 +1704,7 @@ public void SQL_CreateTable_Callback(Handle owner, Handle hndl, const char[] err
return; return;
} }
SQL_TQuery(gH_SQL, SQL_CheckRotation_Callback, "SELECT rot_ang FROM mapzones"); SQL_TQuery(gH_SQL, SQL_CheckRotation_Callback, "SELECT rot_ang FROM mapzones");
} }
@ -1732,23 +1732,23 @@ public void Shavit_OnRestart(int client)
{ {
float vCenter[3]; float vCenter[3];
MakeVectorFromPoints(gV_MapZones[0][0], gV_MapZones[0][1], vCenter); MakeVectorFromPoints(gV_MapZones[0][0], gV_MapZones[0][1], vCenter);
// calculate center // calculate center
vCenter[0] /= 2; vCenter[0] /= 2;
vCenter[1] /= 2; vCenter[1] /= 2;
// i could also use ScaleVector() by 0.5f I guess? dunno which is more resource intensive, so i'll do it manually. // i could also use ScaleVector() by 0.5f I guess? dunno which is more resource intensive, so i'll do it manually.
// old method of calculating Z axis // old method of calculating Z axis
// vCenter[2] /= 2; // vCenter[2] /= 2;
// vCenter[2] -= 20; // vCenter[2] -= 20;
// spawn at the same Z axis the start zone is at // spawn at the same Z axis the start zone is at
// this may break some spawns, where there's a displacement instead of a flat surface at the spawn point, for example; bhop_monster_jam ~ recompile with this commented and the old method uncommented if it's an issue! // this may break some spawns, where there's a displacement instead of a flat surface at the spawn point, for example; bhop_monster_jam ~ recompile with this commented and the old method uncommented if it's an issue!
// vCenter[2] = gV_MapZones[0][0] + 84.0; // vCenter[2] = gV_MapZones[0][0] + 84.0;
// ^ didn't work // ^ didn't work
AddVectors(gV_MapZones[0][0], vCenter, vCenter); AddVectors(gV_MapZones[0][0], vCenter, vCenter);
vCenter[2] = gV_MapZones[0][0][2]; vCenter[2] = gV_MapZones[0][0][2];
TeleportEntity(client, vCenter, NULL_VECTOR, view_as<float>({0.0, 0.0, 0.0})); TeleportEntity(client, vCenter, NULL_VECTOR, view_as<float>({0.0, 0.0, 0.0}));