diff --git a/addons/sourcemod/scripting/include/shavit.inc b/addons/sourcemod/scripting/include/shavit.inc index 89a2ccd0..c6fb5c03 100644 --- a/addons/sourcemod/scripting/include/shavit.inc +++ b/addons/sourcemod/scripting/include/shavit.inc @@ -255,7 +255,6 @@ enum struct cp_cache_t int iClassname; ArrayList aFrames; int iPreFrames; - int iTimerPreFrames; bool bSegmented; int iSerial; bool bPractice; @@ -1817,24 +1816,14 @@ native void Shavit_SetCurrentCheckpoint(int client, int index); native int Shavit_GetPlayerPreFrame(int client); /* - * Gets player's timer frame + * Sets player's preeframe length * * @param client Client index - * - * @return Timer start frame - */ -native int Shavit_GetPlayerTimerframe(int client); - -/* - * Sets player's preframe length - * - * @param client Client index - * @param PreFrame PreFrame length - * @param timerPreFrame Timer start frame length + * @param preframe preframe length * * @noreturn */ -native void Shavit_SetPlayerPreFrame(int client, int PreFrame, int timereframe); +native void Shavit_SetPlayerPreFrame(int client, int preframe); /* * Get's the replay bot folder diff --git a/addons/sourcemod/scripting/shavit-hud.sp b/addons/sourcemod/scripting/shavit-hud.sp index 3fc402f7..10dde173 100644 --- a/addons/sourcemod/scripting/shavit-hud.sp +++ b/addons/sourcemod/scripting/shavit-hud.sp @@ -125,6 +125,7 @@ Convar gCV_GradientStepSize = null; Convar gCV_TicksPerUpdate = null; Convar gCV_SpectatorList = null; Convar gCV_UseHUDFix = null; +Convar gCV_PrerunCountDown = null; // timer settings stylestrings_t gS_StyleStrings[STYLE_LIMIT]; @@ -198,6 +199,7 @@ public void OnPluginStart() gCV_TicksPerUpdate = new Convar("shavit_hud_ticksperupdate", "5", "How often (in ticks) should the HUD update?\nPlay around with this value until you find the best for your server.\nThe maximum value is your tickrate.", 0, true, 1.0, true, (1.0 / GetTickInterval())); gCV_SpectatorList = new Convar("shavit_hud_speclist", "1", "Who to show in the specators list?\n0 - everyone\n1 - all admins (admin_speclisthide override to bypass)\n2 - players you can target", 0, true, 0.0, true, 2.0); gCV_UseHUDFix = new Convar("shavit_hud_csgofix", "1", "Apply the csgo color fix to the center hud?\nThis will add a dollar sign and block sourcemod hooks to hint message", 0, true, 0.0, true, 1.0); + gCV_PrerunCountDown = new Convar("shavit_hud_prerun_countdown", "1", "Display prerun countdown to the replay hud?", 0, true, 0.0, true, 1.0); Convar.AutoExecConfig(); @@ -982,7 +984,7 @@ int AddHUDToBuffer_Source2013(int client, huddata_t data, char[] buffer, int max char sTime[32]; FormatSeconds(data.fTime, sTime, 32, false); - if(data.fTime < 0.0) + if(data.fTime < 0.0 && gCV_PrerunCountDown.BoolValue) { Format(sTime, 32, "-%s", sTime); } @@ -990,7 +992,7 @@ int AddHUDToBuffer_Source2013(int client, huddata_t data, char[] buffer, int max char sWR[32]; FormatSeconds(data.fWR, sWR, 32, false); - FormatEx(sLine, 128, "%s / %s\n(%.1f%)", sTime, sWR, ((data.fTime <= 0.0 ? 0.0 : data.fTime / data.fWR) * 100)); + FormatEx(sLine, 128, "%s / %s\n(%.1f%)", sTime, sWR, ((data.fTime < 0.0 ? 0.0 : data.fTime / data.fWR) * 100)); AddHUDLine(buffer, maxlen, sLine, iLines); iLines++; } @@ -1163,10 +1165,15 @@ int AddHUDToBuffer_CSGO(int client, huddata_t data, char[] buffer, int maxlen) char sTime[32]; FormatSeconds(data.fTime, sTime, 32, false); + if(data.fTime < 0.0 && gCV_PrerunCountDown.BoolValue) + { + Format(sTime, 32, "-%s", sTime); + } + char sWR[32]; FormatSeconds(data.fWR, sWR, 32, false); - FormatEx(sLine, 128, "%s / %s (%.1f%%)", sTime, sWR, ((data.fTime / data.fWR) * 100)); + FormatEx(sLine, 128, "%s / %s (%.1f%%)", sTime, sWR, ((data.fTime < 0.0 ? 0.0 : data.fTime / data.fWR) * 100)); AddHUDLine(buffer, maxlen, sLine, iLines); iLines++; } diff --git a/addons/sourcemod/scripting/shavit-misc.sp b/addons/sourcemod/scripting/shavit-misc.sp index 0a400423..f8d8f3a4 100644 --- a/addons/sourcemod/scripting/shavit-misc.sp +++ b/addons/sourcemod/scripting/shavit-misc.sp @@ -64,7 +64,6 @@ enum struct persistent_data_t int iClassname; ArrayList aFrames; int iPreFrames; - int iTimerPreFrames; bool bPractice; } @@ -1129,7 +1128,6 @@ void PersistData(int client) { aData.aFrames = Shavit_GetReplayData(client); aData.iPreFrames = Shavit_GetPlayerPreFrame(client); - aData.iTimerPreFrames = Shavit_GetPlayerTimerframe(client); } aData.fDisconnectTime = GetEngineTime(); @@ -1250,7 +1248,7 @@ public Action Timer_LoadPersistentData(Handle Timer, any data) if(gB_Replay && aData.aFrames != null) { Shavit_SetReplayData(client, aData.aFrames); - Shavit_SetPlayerPreFrame(client, aData.iPreFrames, aData.iTimerPreFrames); + Shavit_SetPlayerPreFrame(client, aData.iPreFrames); } if(aData.bPractice) @@ -2343,7 +2341,6 @@ bool SaveCheckpoint(int client, int index, bool overflow = false) { cpcache.aFrames = Shavit_GetReplayData(target); cpcache.iPreFrames = Shavit_GetPlayerPreFrame(target); - cpcache.iTimerPreFrames = Shavit_GetPlayerTimerframe(target); } cpcache.bSegmented = true; @@ -2556,7 +2553,7 @@ void TeleportToCheckpoint(int client, int index, bool suppressMessage) else { Shavit_SetReplayData(client, cpcache.aFrames); - Shavit_SetPlayerPreFrame(client, cpcache.iPreFrames, cpcache.iTimerPreFrames); + Shavit_SetPlayerPreFrame(client, cpcache.iPreFrames); } } diff --git a/addons/sourcemod/scripting/shavit-replay.sp b/addons/sourcemod/scripting/shavit-replay.sp index 2e7ca3fe..79f52b94 100644 --- a/addons/sourcemod/scripting/shavit-replay.sp +++ b/addons/sourcemod/scripting/shavit-replay.sp @@ -129,6 +129,7 @@ bool gB_Button[MAXPLAYERS+1]; int gI_PlayerFrames[MAXPLAYERS+1]; int gI_PlayerPrerunFrames[MAXPLAYERS+1]; int gI_PlayerTimerStartFrames[MAXPLAYERS+1]; +bool gB_ClearFrame[MAXPLAYERS+1]; ArrayList gA_PlayerFrames[MAXPLAYERS+1]; int gI_Track[MAXPLAYERS+1]; float gF_LastInteraction[MAXPLAYERS+1]; @@ -165,6 +166,8 @@ Convar gCV_BotWeapon = null; Convar gCV_PlaybackCanStop = null; Convar gCV_PlaybackCooldown = null; Convar gCV_PlaybackPreRunTime = null; +Convar gCV_ClearPreRun = null; +ConVar gCV_PrerunCountdown = null; // timer settings int gI_Styles = 0; @@ -218,7 +221,6 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max CreateNative("Shavit_Replay_DeleteMap", Native_Replay_DeleteMap); CreateNative("Shavit_SetReplayData", Native_SetReplayData); CreateNative("Shavit_GetPlayerPreFrame", Native_GetPreFrame); - CreateNative("Shavit_GetPlayerTimerframe", Native_GetTimerFrame); CreateNative("Shavit_SetPlayerPreFrame", Native_SetPreFrame); CreateNative("Shavit_GetReplayBotFolder", Native_GetReplayBotFolder); @@ -261,6 +263,7 @@ public void OnPluginStart() FindConVar((gEV_Type != Engine_TF2)? "bot_quota":"tf_bot_quota").Flags &= ~FCVAR_NOTIFY; FindConVar("bot_stop").Flags &= ~FCVAR_CHEAT; + gCV_PrerunCountdown = FindConVar("shavit_hud_prerun_countdown"); for(int i = 0; i < sizeof(gS_ForcedCvars); i++) { @@ -303,6 +306,7 @@ public void OnPluginStart() gCV_PlaybackCanStop = new Convar("shavit_replay_pbcanstop", "1", "Allow players to stop playback if they requested it?", 0, true, 0.0, true, 1.0); gCV_PlaybackCooldown = new Convar("shavit_replay_pbcooldown", "10.0", "Cooldown in seconds to apply for players between each playback they request/stop.\nDoes not apply to RCON admins.", 0, true, 0.0); gCV_PlaybackPreRunTime = new Convar("shavit_replay_preruntime", "1.0", "Time (in seconds) to record before a player leaves start zone. (The value should NOT be too high)", 0, true, 0.0); + gCV_ClearPreRun = new Convar("shavit_replay_prerun_always", "1", "Record prerun frames outside the start zone?", 0, true, 0.0, true, 1.0); gCV_CentralBot.AddChangeHook(OnConVarChanged); @@ -711,6 +715,13 @@ public int Native_GetReplayTime(Handle handler, int numParams) return view_as(GetReplayLength(Track_Main, track)); } + if(gCV_PrerunCountdown.BoolValue) + { + if(gI_ReplayTick[style] < gA_FrameCache[style][track].iPreFrames) + { + return view_as(float(gI_ReplayTick[style] - gA_FrameCache[style][track].iPreFrames) / gF_Tickrate * gA_StyleSettings[style].fTimescale); + } + } return view_as(float(gI_TimerTick[style]) / gF_Tickrate * gA_StyleSettings[style].fTimescale); } @@ -783,19 +794,9 @@ public int Native_GetPreFrame(Handle handler, int numParams) return gI_PlayerPrerunFrames[GetNativeCell(1)]; } -public int Native_GetTimerFrame(Handle handler, int numParams) -{ - return gI_PlayerTimerStartFrames[GetNativeCell(1)]; -} - public int Native_SetPreFrame(Handle handler, int numParams) { - int client = GetNativeCell(1); - int preframes = GetNativeCell(2); - int timerframes = GetNativeCell(3); - - gI_PlayerPrerunFrames[client] = preframes; - gI_PlayerTimerStartFrames[client] = timerframes; + gI_PlayerPrerunFrames[GetNativeCell(1)] = GetNativeCell(2); } public Action Cron(Handle Timer) @@ -1259,7 +1260,7 @@ bool LoadReplay(int style, int track, const char[] path) return false; } -bool SaveReplay(int style, int track, float time, int steamid, char[] name, int preframes, ArrayList playerrecording, int timerstartframe) +bool SaveReplay(int style, int track, float time, int steamid, char[] name, int preframes, ArrayList playerrecording) { char sTrack[4]; FormatEx(sTrack, 4, "_%d", track); @@ -1278,7 +1279,7 @@ bool SaveReplay(int style, int track, float time, int steamid, char[] name, int fFile.WriteString(gS_Map, true); fFile.WriteInt8(style); fFile.WriteInt8(track); - fFile.WriteInt32(preframes < 0 ? timerstartframe : timerstartframe - preframes); + fFile.WriteInt32(preframes); int iSize = playerrecording.Length; fFile.WriteInt32(iSize); @@ -1290,7 +1291,7 @@ bool SaveReplay(int style, int track, float time, int steamid, char[] name, int int iFramesWritten = 0; gA_Frames[style][track].Clear(); - for(int i = (preframes < 0 ? 0 : preframes); i < iSize; i++) + for(int i = 0; i < iSize; i++) { playerrecording.GetArray(i, aFrameData, CELLS_PER_FRAME); gA_Frames[style][track].PushArray(aFrameData); @@ -1310,11 +1311,11 @@ bool SaveReplay(int style, int track, float time, int steamid, char[] name, int delete fFile; - gA_FrameCache[style][track].iFrameCount = iSize - (preframes < 0 ? 0 : preframes); + gA_FrameCache[style][track].iFrameCount = iSize; gA_FrameCache[style][track].fTime = time; gA_FrameCache[style][track].bNewFormat = true; strcopy(gA_FrameCache[style][track].sReplayName, MAX_NAME_LENGTH, name); - gA_FrameCache[style][track].iPreFrames = preframes < 0 ? timerstartframe : (timerstartframe - preframes); + gA_FrameCache[style][track].iPreFrames = preframes; return true; } @@ -1640,13 +1641,24 @@ public void DeleteFrames(int client) public Action Shavit_OnStart(int client) { - gI_PlayerPrerunFrames[client] = gA_PlayerFrames[client].Length - RoundToFloor(gCV_PlaybackPreRunTime.FloatValue * gF_Tickrate / gA_StyleSettings[Shavit_GetBhopStyle(client)].fTimescale); - gI_PlayerTimerStartFrames[client] = gA_PlayerFrames[client].Length; - - if(gA_PlayerFrames[client].Length >= RoundToFloor(gCV_PlaybackPreRunTime.FloatValue * gF_Tickrate / gA_StyleSettings[Shavit_GetBhopStyle(client)].fTimescale)) + gI_PlayerPrerunFrames[client] = gA_PlayerFrames[client].Length; + + if(!gB_ClearFrame[client]) { - gA_PlayerFrames[client].Erase(0); - gI_PlayerFrames[client]--; + if(!gCV_ClearPreRun.BoolValue) + { + ClearFrames(client); + } + gB_ClearFrame[client] = true; + } + + else + { + if(gA_PlayerFrames[client].Length >= RoundToFloor(gCV_PlaybackPreRunTime.FloatValue * gF_Tickrate / gA_StyleSettings[Shavit_GetBhopStyle(client)].fTimescale)) + { + gA_PlayerFrames[client].Erase(0); + gI_PlayerFrames[client]--; + } } return Plugin_Continue; @@ -1657,6 +1669,14 @@ public void Shavit_OnStop(int client) ClearFrames(client); } +public void Shavit_OnLeaveZone(int client, int type, int track, int id, int entity) +{ + if(type == Zone_Start) + { + gB_ClearFrame[client] = false; + } +} + public void Shavit_OnFinish(int client, int style, float time, int jumps, int strafes, float sync, int track) { if(Shavit_IsPracticeMode(client)) @@ -1666,8 +1686,6 @@ public void Shavit_OnFinish(int client, int style, float time, int jumps, int st if(!gCV_Enabled.BoolValue || (gCV_TimeLimit.FloatValue > 0.0 && time > gCV_TimeLimit.FloatValue)) { - ClearFrames(client); - return; } @@ -1702,7 +1720,7 @@ public void Shavit_OnFinish(int client, int style, float time, int jumps, int st GetClientName(client, sName, MAX_NAME_LENGTH); ReplaceString(sName, MAX_NAME_LENGTH, "#", "?"); - SaveReplay(style, track, time, iSteamID, sName, gI_PlayerPrerunFrames[client], gA_PlayerFrames[client], gI_PlayerTimerStartFrames[client]); + SaveReplay(style, track, time, iSteamID, sName, gI_PlayerPrerunFrames[client], gA_PlayerFrames[client]); if(ReplayEnabled(style)) { diff --git a/addons/sourcemod/scripting/shavit-stats.sp b/addons/sourcemod/scripting/shavit-stats.sp index a674bfa6..3f0f6229 100644 --- a/addons/sourcemod/scripting/shavit-stats.sp +++ b/addons/sourcemod/scripting/shavit-stats.sp @@ -428,7 +428,7 @@ Action OpenStatsMenu(int client, int steamid) "JOIN (SELECT COUNT(*) maps FROM (SELECT map FROM %smapzones WHERE track = 0 AND type = 0 GROUP BY map) s) b " ... "JOIN (SELECT COUNT(*) wrs FROM %splayertimes a JOIN (SELECT MIN(time) time, map FROM %splayertimes WHERE style = 0 AND track = 0 GROUP by map, style, track) b ON a.time = b.time AND a.map = b.map AND track = 0 AND style = 0 WHERE auth = %d) c " ... "JOIN (SELECT name, ip, lastlogin, FORMAT(points, 2) points FROM %susers WHERE auth = %d) d " ... - "JOIN (SELECT COUNT(*) rank FROM %susers u1 JOIN (SELECT points FROM %susers WHERE auth = %d) u2 WHERE u1.points >= u2.points) e " ... + "JOIN (SELECT COUNT(*) rank FROM %susers as u1 JOIN (SELECT points FROM %susers WHERE auth = %d) u2 WHERE u1.points >= u2.points) e " ... "LIMIT 1;", gS_MySQLPrefix, steamid, gS_MySQLPrefix, gS_MySQLPrefix, gS_MySQLPrefix, steamid, gS_MySQLPrefix, steamid, gS_MySQLPrefix, gS_MySQLPrefix, steamid); }