From e8d7653dde610516df8f76960f2c4032bc245359 Mon Sep 17 00:00:00 2001 From: Dogan Date: Wed, 10 Jul 2019 15:34:04 +0200 Subject: [PATCH] HappyHour: improve sm_hh --- HappyHour/scripting/HappyHour.sp | 43 +++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/HappyHour/scripting/HappyHour.sp b/HappyHour/scripting/HappyHour.sp index c24d0fca..c6dff385 100644 --- a/HappyHour/scripting/HappyHour.sp +++ b/HappyHour/scripting/HappyHour.sp @@ -20,7 +20,7 @@ public Plugin myinfo = name = "Happy Hour", author = "Dogan + Neon", description = "Create an happy hour with more rank points", - version = "1.2.0", + version = "1.3.0", url = "" }; @@ -97,7 +97,7 @@ public Action Timer_CheckTime(Handle timer) if(g_bHappyHourAdmin) return Plugin_Continue; - if((InsideTimeFrame(g_iMorningStart, g_iMorningEnd)) || (InsideTimeFrame(g_iNightStart, g_iNightEnd))) + if((InsideTimeFrame(g_iMorningStart, g_iMorningEnd) == 0) || (InsideTimeFrame(g_iNightStart, g_iNightEnd) == 0)) { g_bHappyHour = true; } @@ -109,7 +109,7 @@ public Action Timer_CheckTime(Handle timer) return Plugin_Continue; } -public bool InsideTimeFrame(int MinTime, int MaxTime) +public int InsideTimeFrame(int MinTime, int MaxTime) { char sTime[8]; FormatTime(sTime, sizeof(sTime), "%H%M"); @@ -121,9 +121,22 @@ public bool InsideTimeFrame(int MinTime, int MaxTime) MaxTime = (MaxTime <= MinTime) ? MaxTime + 2400 : MaxTime; if (MinTime <= CurTime <= MaxTime) - return true; + { + return 0; + } + else + { + //Wrap around. + MinTime = (MinTime <= CurTime) ? MinTime + 2400 : MinTime; + MinTime = (MinTime <= MaxTime) ? MinTime + 2400 : MinTime; - return false; + // Convert our 'time' to minutes. + CurTime = (RoundToFloor(float(CurTime / 100)) * 60) + (CurTime % 100); + MinTime = (RoundToFloor(float(MinTime / 100)) * 60) + (MinTime % 100); + MaxTime = (RoundToFloor(float(MaxTime / 100)) * 60) + (MaxTime % 100); + + return MinTime - CurTime; + } } public void OnMapStart() @@ -144,7 +157,25 @@ public Action Command_DisplayHappyHour(int client, int args) } else { - ReplyToCommand(client, "[SM] Happy Hour is currently not active."); + int iTimeleftMorning = InsideTimeFrame(g_iMorningStart, g_iMorningEnd); + int iTimeleftNight = InsideTimeFrame(g_iNightStart, g_iNightEnd); + int iTimeleft; + char sTimeleft[32]; + + if(iTimeleftMorning >= iTimeleftNight) + iTimeleft = iTimeleftNight; + else + iTimeleft = iTimeleftMorning; + + int iHours = (iTimeleft / 60) % 24; + int iMinutes = (iTimeleft % 60); + + if(iHours) + Format(sTimeleft, sizeof(sTimeleft), "%d Hours %02d Minutes", iHours, iMinutes); + else + Format(sTimeleft, sizeof(sTimeleft), "%d Minutes", iMinutes); + + ReplyToCommand(client, "[SM] Happy Hour is currently not active. Timeleft: %s.", sTimeleft); } return Plugin_Handled;