diff --git a/Kill_Sound.cs b/Kill_Sound.cs index 22bfb58..5ca7d98 100644 --- a/Kill_Sound.cs +++ b/Kill_Sound.cs @@ -6,6 +6,8 @@ using CounterStrikeSharp.API; using System.Text; using Newtonsoft.Json; +using CounterStrikeSharp.API.Modules.Timers; +using CounterStrikeSharp.API.Modules.Memory; namespace Kill_Sound; @@ -26,12 +28,17 @@ public class KillSoundConfig : BasePluginConfig public class KillSound : BasePlugin, IPluginConfig { - public override string ModuleName => "Kill Sound"; - public override string ModuleVersion => "1.0.3"; + public override string ModuleName => "Kill Sound (Sound On , Kill , HeadShot , Body , Menu)"; + public override string ModuleVersion => "1.0.4"; public override string ModuleAuthor => "Gold KingZ"; - public override string ModuleDescription => "Sound On , Kill , HeadShot , Body"; + public override string ModuleDescription => "https://github.com/oqyh/cs2-Kill-Sound"; public KillSoundConfig Config { get; set; } = new KillSoundConfig(); - private Dictionary menuon = new Dictionary(); + private Dictionary intromenuon = new Dictionary(); + private Dictionary menuon = new Dictionary(); + private Dictionary menuclose = new Dictionary(); + private Dictionary currentIndexDict = new Dictionary(); + private Dictionary buttonPressed = new Dictionary(); + public void OnConfigParsed(KillSoundConfig config) { Config = config; @@ -41,6 +48,7 @@ public override void Load(bool hotReload) { RegisterEventHandler(OnPlayerDeath); RegisterEventHandler(OnPlayerHurt); + RegisterEventHandler(OnPlayerDisconnect); AddCommandListener("say", OnPlayerSayPublic, HookMode.Post); AddCommandListener("say_team", OnPlayerSayTeam, HookMode.Post); RegisterListener(OnTick); @@ -53,106 +61,322 @@ public void OnTick() { if (player == null || !player.IsValid || player.IsBot || player.IsHLTV) continue; - if (menuon.ContainsKey(player.UserId!.Value)) + var playerid = player.SteamID; + /////////////////////////////////////////// + //Intro Menu (No needed just incase if you need it) + if (intromenuon.ContainsKey(playerid)) { - var playerid = player.SteamID; - string Close = ""; - string Red = ""; - string Cyan = ""; - string Blue = ""; - string DarkBlue = ""; - string LightBlue = ""; - string Purple = ""; - string Yellow = ""; - string Lime = ""; - string Magenta = ""; - string Pink = ""; - string Grey = ""; - string Green = ""; - string Orange = ""; - - PersonData personData = RetrievePersonDataById((int)playerid); StringBuilder builder = new StringBuilder(); - bool test = personData.BoolValue3; - if (!string.IsNullOrEmpty(Config.HeadShotKillSoundPath)) + builder.AppendLine(Localizer["Menu.Intro"]);//Intro menu + var centerhtml = builder.ToString(); + player?.PrintToCenterHtml(centerhtml); + Server.NextFrame(() => { - if(personData.BoolValue1) + AddTimer(3.0f, () => { - if (!string.IsNullOrEmpty(Localizer["Menu.HeadShotKillOff"])) + if (intromenuon.ContainsKey(playerid)) // after 3 secs check if he has intro menu remove { - builder.AppendFormat(Localizer["Menu.HeadShotKillOff"], Close,Red,Cyan,Blue,DarkBlue,LightBlue,Purple,Yellow,Lime,Magenta,Pink,Grey,Green,Orange); - builder.AppendLine("
"); + intromenuon.Remove(playerid); } - }else - { - if (!string.IsNullOrEmpty(Localizer["Menu.HeadShotKillOn"])) + if (!menuon.ContainsKey(playerid)) // if he doesnt have main menu give him { - builder.AppendFormat(Localizer["Menu.HeadShotKillOn"], Close,Red,Cyan,Blue,DarkBlue,LightBlue,Purple,Yellow,Lime,Magenta,Pink,Grey,Green,Orange); - builder.AppendLine("
"); + menuon.Add(playerid, true); } + }, TimerFlags.STOP_ON_MAPCHANGE); + }); + } + //Done Intro Menu + /////////////////////////////////////////// + + if (player == null || !player.IsValid || player.IsBot || player.IsHLTV) continue; + /////////////////////////////////////////// + //Main Menu + if (menuon.ContainsKey(playerid)) + { + PersonData personData = RetrievePersonDataById((int)playerid); //load Cookies to personData + DateTime personDate = DateTime.Now; ////load personData To track Inactive players RemovePlayerCookieOlderThanXDays + + // BoolValue5 is Freeze On Menu if its on then we freeze him on menu on + if(!personData.BoolValue5) + { + if(player.PlayerPawn.Value != null && player.PlayerPawn.Value.IsValid){ + player.PlayerPawn.Value!.MoveType = MoveType_t.MOVETYPE_NONE; + Schema.SetSchemaValue(player.PlayerPawn.Value.Handle, "CBaseEntity", "m_nActualMoveType", 0); + Utilities.SetStateChanged(player.PlayerPawn.Value, "CBaseEntity", "m_MoveType"); } } - if (!string.IsNullOrEmpty(Config.HeadShotHitSoundPath)) + /////////////////////////////////////////// + //setup menu string and bool first + // + List linesList = new List(); + List boolValuesList = new List(); + + linesList.Add(Localizer["Menu.Freeze"]);//name inside menu + by default i like to have it inside the menu + boolValuesList.Add(personData.BoolValue5); //also bool for Freeze On Menu + + if (!string.IsNullOrEmpty(Config.HeadShotKillSoundPath)) //check server if he want Head Shot Kill Sound { - if(personData.BoolValue2) - { - if (!string.IsNullOrEmpty(Localizer["Menu.HeadShotHitOff"])) + //if he want Head Shot Kill Sound we add string + bool to the list to use it after + linesList.Add(Localizer["Menu.HeadShotKill"]); //name inside menu + boolValuesList.Add(personData.BoolValue1); + } + if (!string.IsNullOrEmpty(Config.HeadShotHitSoundPath)) //check server if he want Head Shot Hit Sound + { + //if he want Head Shot Hit Sound we add string + bool to the list to use it after + linesList.Add(Localizer["Menu.HeadShotHit"]);//name inside menu + boolValuesList.Add(personData.BoolValue2); + } + if (!string.IsNullOrEmpty(Config.BodyKillSoundPath)) //check server if he want Body Kill Sound + { + //if he want Body Kill Sound we add string + bool to the list to use it after + linesList.Add(Localizer["Menu.BodyKill"]);//name inside menu + boolValuesList.Add(personData.BoolValue3); + } + if (!string.IsNullOrEmpty(Config.BodyHitSoundPath)) //check server if he want Body Hit Sound + { + //if he want Body Hit Sound we add string + bool to the list to use it after + linesList.Add(Localizer["Menu.BodyHit"]);//name inside menu + boolValuesList.Add(personData.BoolValue4); + } + + string[] lines = linesList.ToArray(); + bool[] boolValues = boolValuesList.ToArray(); + // + //Done Setup Menu + /////////////////////////////////////////// + + /////////////////////////////////////////// + //Player Pressing + if (player.Buttons == 0) //Check If Player Not pressing + { + buttonPressed[playerid] = false; //make buttonPressed to false that means ready for next index (anti Spam) + } + else if (player.Buttons == PlayerButtons.Back && !buttonPressed[playerid])//player going back (S) + buttonPressed false (anti Spam) + { + currentIndexDict[playerid] = (currentIndexDict[playerid] == lines.Length - 1) ? 0 : currentIndexDict[playerid] + 1; //add index +1 + buttonPressed[playerid] = true; //done pressing give him buttonPressed true (anti Spam) + player.ExecuteClientCommand("play sounds/ui/csgo_ui_page_scroll.vsnd_c"); // play sound + } + else if (player.Buttons == PlayerButtons.Forward && !buttonPressed[playerid])//player going Forward (W) + buttonPressed false (anti Spam) + { + currentIndexDict[playerid] = (currentIndexDict[playerid] == 0) ? lines.Length - 1 : currentIndexDict[playerid] - 1; //subtract index -1 + buttonPressed[playerid] = true; //done pressing give him buttonPressed true (anti Spam) + player.ExecuteClientCommand("play sounds/ui/csgo_ui_page_scroll.vsnd_c"); // play sound + }else if ((player.Buttons == PlayerButtons.Moveleft || player.Buttons == PlayerButtons.Moveright) && !buttonPressed[playerid])//player going Left (A) OR Right (D) + buttonPressed false (anti Spam) + { + int currentLineIndex = currentIndexDict[playerid]; //Get CurrentIndex + + string currentLineName = lines[currentLineIndex]; //Convert CurrentIndex From int to string (better than int) + if (currentLineName == Localizer["Menu.Freeze"]) //if CurrentIndex equals Freeze On Menu and press Right or Left + { + personData.BoolValue1 = personData.BoolValue1; + personData.BoolValue2 = personData.BoolValue2; + personData.BoolValue3 = personData.BoolValue3; + personData.BoolValue4 = personData.BoolValue4; + personData.BoolValue5 = !personData.BoolValue5; //this bool for Freeze On Menu oppsite (on / off) + if(!personData.BoolValue5)//if true means off walk (i made oppsite to make less cookies) { - builder.AppendFormat(Localizer["Menu.HeadShotHitOff"], Close,Red,Cyan,Blue,DarkBlue,LightBlue,Purple,Yellow,Lime,Magenta,Pink,Grey,Green,Orange); - builder.AppendLine("
"); + if(player.PlayerPawn.Value != null && player.PlayerPawn.Value.IsValid){ + player.PlayerPawn.Value!.MoveType = MoveType_t.MOVETYPE_NONE; + Schema.SetSchemaValue(player.PlayerPawn.Value.Handle, "CBaseEntity", "m_nActualMoveType", 0); + Utilities.SetStateChanged(player.PlayerPawn.Value, "CBaseEntity", "m_MoveType"); + } + + if (!string.IsNullOrEmpty(Localizer["Chat.FreezeOn"])) //check first if server want chat empty means skip Chat message + { + player.PrintToChat(Localizer["Chat.FreezeOn"]); + } + }else //if false means on Freeze + { + if(player.PlayerPawn.Value != null && player.PlayerPawn.Value.IsValid){ + player.PlayerPawn.Value!.MoveType = MoveType_t.MOVETYPE_WALK; + Schema.SetSchemaValue(player.PlayerPawn.Value.Handle, "CBaseEntity", "m_nActualMoveType", 2); + Utilities.SetStateChanged(player.PlayerPawn.Value, "CBaseEntity", "m_MoveType"); + } + + if (!string.IsNullOrEmpty(Localizer["Chat.FreezeOff"])) + { + player.PrintToChat(Localizer["Chat.FreezeOff"]); + } } - }else + SaveToJsonFile((int)playerid, personData.BoolValue1, personData.BoolValue2, personData.BoolValue3, personData.BoolValue4, personData.BoolValue5, personDate);//save values in cookies + }else if (currentLineName == Localizer["Menu.HeadShotKill"])//The reset same just oppsite + save values in cookies { - if (!string.IsNullOrEmpty(Localizer["Menu.HeadShotHitOn"])) + personData.BoolValue1 = !personData.BoolValue1;//this bool for Head Shot Kill Sound Menu oppsite (on / off) + personData.BoolValue2 = personData.BoolValue2; + personData.BoolValue3 = personData.BoolValue3; + personData.BoolValue4 = personData.BoolValue4; + personData.BoolValue5 = personData.BoolValue5; + + if(!personData.BoolValue1) + { + if (!string.IsNullOrEmpty(Localizer["Chat.HeadShotKillOn"])) + { + player.PrintToChat(Localizer["Chat.HeadShotKillOn"]); + } + }else + { + if (!string.IsNullOrEmpty(Localizer["Chat.HeadShotKillOff"])) + { + player.PrintToChat(Localizer["Chat.HeadShotKillOff"]); + } + } + + SaveToJsonFile((int)playerid, personData.BoolValue1, personData.BoolValue2, personData.BoolValue3, personData.BoolValue4, personData.BoolValue5, personDate); + }else if (currentLineName == Localizer["Menu.HeadShotHit"]) + { + personData.BoolValue1 = personData.BoolValue1; + personData.BoolValue2 = !personData.BoolValue2;//this bool for Head Shot Hit Sound Menu oppsite (on / off) + personData.BoolValue3 = personData.BoolValue3; + personData.BoolValue4 = personData.BoolValue4; + personData.BoolValue5 = personData.BoolValue5; + if(!personData.BoolValue2) + { + if (!string.IsNullOrEmpty(Localizer["Chat.HeadShotHitOn"])) + { + player.PrintToChat(Localizer["Chat.HeadShotHitOn"]); + } + }else + { + if (!string.IsNullOrEmpty(Localizer["Chat.HeadShotHitOff"])) + { + player.PrintToChat(Localizer["Chat.HeadShotHitOff"]); + } + } + SaveToJsonFile((int)playerid, personData.BoolValue1, personData.BoolValue2, personData.BoolValue3, personData.BoolValue4, personData.BoolValue5, personDate); + }else if (currentLineName == Localizer["Menu.BodyKill"]) + { + personData.BoolValue1 = personData.BoolValue1; + personData.BoolValue2 = personData.BoolValue2; + personData.BoolValue3 = !personData.BoolValue3;//this bool for Body Kill Sound Menu oppsite (on / off) + personData.BoolValue4 = personData.BoolValue4; + personData.BoolValue5 = personData.BoolValue5; + if(!personData.BoolValue3) + { + if (!string.IsNullOrEmpty(Localizer["Chat.BodyKillOn"])) + { + player.PrintToChat(Localizer["Chat.BodyKillOn"]); + } + }else { - builder.AppendFormat(Localizer["Menu.HeadShotHitOn"], Close,Red,Cyan,Blue,DarkBlue,LightBlue,Purple,Yellow,Lime,Magenta,Pink,Grey,Green,Orange); - builder.AppendLine("
"); + if (!string.IsNullOrEmpty(Localizer["Chat.BodyKillOff"])) + { + player.PrintToChat(Localizer["Chat.BodyKillOff"]); + } } + SaveToJsonFile((int)playerid, personData.BoolValue1, personData.BoolValue2, personData.BoolValue3, personData.BoolValue4, personData.BoolValue5, personDate); + }else if (currentLineName == Localizer["Menu.BodyHit"]) + { + personData.BoolValue1 = personData.BoolValue1; + personData.BoolValue2 = personData.BoolValue2; + personData.BoolValue3 = personData.BoolValue3; + personData.BoolValue4 = !personData.BoolValue4;//this bool for Body Hit Sound Menu oppsite (on / off) + personData.BoolValue5 = personData.BoolValue5; + if(!personData.BoolValue4) + { + if (!string.IsNullOrEmpty(Localizer["Chat.BodyHitOn"])) + { + player.PrintToChat(Localizer["Chat.BodyHitOn"]); + } + }else + { + if (!string.IsNullOrEmpty(Localizer["Chat.BodyHitOff"])) + { + player.PrintToChat(Localizer["Chat.BodyHitOff"]); + } + } + SaveToJsonFile((int)playerid, personData.BoolValue1, personData.BoolValue2, personData.BoolValue3, personData.BoolValue4, personData.BoolValue5, personDate); } + buttonPressed[playerid] = true;//done pressing give him buttonPressed true (anti Spam) + player.ExecuteClientCommand("play sounds/ui/item_sticker_select.vsnd_c"); // play sound } - if (!string.IsNullOrEmpty(Config.BodyKillSoundPath)) + else if ((long)player.Buttons == 8589934592) //If press Tab { - if(personData.BoolValue3) + if(!personData.BoolValue5) //if he choose menu open freeze we remove freeze because we exting { - if (!string.IsNullOrEmpty(Localizer["Menu.BodyKillOff"])) - { - builder.AppendFormat(Localizer["Menu.BodyKillOff"], Close,Red,Cyan,Blue,DarkBlue,LightBlue,Purple,Yellow,Lime,Magenta,Pink,Grey,Green,Orange); - builder.AppendLine("
"); + if(player.PlayerPawn.Value != null && player.PlayerPawn.Value.IsValid){ + player.PlayerPawn.Value!.MoveType = MoveType_t.MOVETYPE_WALK; + Schema.SetSchemaValue(player.PlayerPawn.Value.Handle, "CBaseEntity", "m_nActualMoveType", 2); + Utilities.SetStateChanged(player.PlayerPawn.Value, "CBaseEntity", "m_MoveType"); } - }else + } + if (!menuclose.ContainsKey(playerid)) //give outro { - if (!string.IsNullOrEmpty(Localizer["Menu.BodyKillOn"])) - { - builder.AppendFormat(Localizer["Menu.BodyKillOn"], Close,Red,Cyan,Blue,DarkBlue,LightBlue,Purple,Yellow,Lime,Magenta,Pink,Grey,Green,Orange); - builder.AppendLine("
"); - } + menuclose.Add(playerid, true); } + + if (menuon.ContainsKey(playerid)) // close main menu open + { + menuon.Remove(playerid); + } + } - if (!string.IsNullOrEmpty(Config.BodyHitSoundPath)) + //Done Player Pressing + /////////////////////////////////////////// + + /////////////////////////////////////////// + //Show Menu With Values + StringBuilder builder = new StringBuilder(); + for (int i = 0; i < lines.Length; i++) { - if(personData.BoolValue4) + + if (i == currentIndexDict[playerid]) // The One Selected { - if (!string.IsNullOrEmpty(Localizer["Menu.BodyHitOff"])) - { - builder.AppendFormat(Localizer["Menu.BodyHitOff"], Close,Red,Cyan,Blue,DarkBlue,LightBlue,Purple,Yellow,Lime,Magenta,Pink,Grey,Green,Orange); - builder.AppendLine("
"); - } - }else + bool status = (i >= 0 && i < boolValues.Length) ? boolValues[i] : false; //check on or is it off + string Imageleft = ""; //picture of left side + string ImageRight = ""; //picture of Right side + string lineHtml = $"{Imageleft} {lines[i]} : {(status ? "Off" : "On")} {ImageRight}
"; //Overall Selected look like + builder.AppendLine(lineHtml); + } + else // Rest of Lines Make it white Color { - if (!string.IsNullOrEmpty(Localizer["Menu.BodyHitOn"])) - { - builder.AppendFormat(Localizer["Menu.BodyHitOn"], Close,Red,Cyan,Blue,DarkBlue,LightBlue,Purple,Yellow,Lime,Magenta,Pink,Grey,Green,Orange); - builder.AppendLine("
"); - } - + builder.AppendLine($"{lines[i]}
"); } } - builder.AppendFormat(Localizer["Menu.Exit"], Close,Red,Cyan,Blue,DarkBlue,LightBlue,Purple,Yellow,Lime,Magenta,Pink,Grey,Green,Orange); + + builder.AppendLine(Localizer["Menu.Bottom"]);//bottom menu + builder.AppendLine(""); var centerhtml = builder.ToString(); player?.PrintToCenterHtml(centerhtml); + //Done Show Menu With Values + /////////////////////////////////////////// + } + //Done Main Menu + /////////////////////////////////////////// + + /////////////////////////////////////////// + //Outro Menu (No needed just incase if you need it) + if (menuclose.ContainsKey(playerid))// Outro + { + StringBuilder builder = new StringBuilder(); + builder.Append(Localizer["Menu.Outro"]); + var centerhtml = builder.ToString(); + player?.PrintToCenterHtml(centerhtml); + Server.NextFrame(() => + { + AddTimer(3.0f, () => + { + if (menuclose.ContainsKey(playerid)) // check if player has outro remove + { + menuclose.Remove(playerid); + } + if (buttonPressed.ContainsKey(playerid)) // check if player has buttonPressed remove + { + buttonPressed.Remove(playerid); + } + if (menuon.ContainsKey(playerid)) // check if player menu open remove + { + menuon.Remove(playerid); + } + }, TimerFlags.STOP_ON_MAPCHANGE); + }); + } + //Done Outro Menu + /////////////////////////////////////////// } } + private HookResult OnPlayerSayPublic(CCSPlayerController? player, CommandInfo info) { if (player == null || !player.IsValid || player.IsBot || player.IsHLTV)return HookResult.Continue; @@ -178,129 +402,43 @@ private HookResult OnPlayerSayPublic(CCSPlayerController? player, CommandInfo in string[] disableCommandsmenu = Config.SoundDisableCommandsMenu.Split(','); string[] disableCommands = Config.SoundDisableCommands.Split(','); - if (!string.IsNullOrEmpty(Config.SoundDisableCommandsMenu) && disableCommandsmenu.Any(cmd => cmd.Equals(trimmedMessage, StringComparison.OrdinalIgnoreCase))) + if (!string.IsNullOrEmpty(Config.SoundDisableCommandsMenu) && disableCommandsmenu.Any(cmd => cmd.Equals(trimmedMessage, StringComparison.OrdinalIgnoreCase))) //Menu Start Here { - if (menuon.ContainsKey(player.UserId!.Value))return HookResult.Continue; - menuon.Add(player.UserId.Value, true); + + if (!intromenuon.ContainsKey(playerid))//check if not have intro (we going intro > Main Menu then stop if exit > outro > Exit) + { + intromenuon.Add(playerid, true); + } + if (!currentIndexDict.ContainsKey(playerid)) //check if he has no index start then we start with 0 index in menu + { + currentIndexDict.Add(playerid, 0); + } + if (!buttonPressed.ContainsKey(playerid)) //track anti spam + { + buttonPressed.Add(playerid, false); + } } - if (!string.IsNullOrEmpty(Config.SoundDisableCommands) && disableCommands.Any(cmd => cmd.Equals(trimmedMessage, StringComparison.OrdinalIgnoreCase))) + if (!string.IsNullOrEmpty(Config.SoundDisableCommands) && disableCommands.Any(cmd => cmd.Equals(trimmedMessage, StringComparison.OrdinalIgnoreCase))) //shortcut stop all sounds with commands Config.SoundDisableCommands { DateTime personDate = DateTime.Now; bool boolValue1 = personData.BoolValue1; bool boolValue2 = personData.BoolValue2; bool boolValue3 = personData.BoolValue3; bool boolValue4 = personData.BoolValue4; + bool boolValue5 = personData.BoolValue5;//we skip freeze menu boolean - boolValue1 = true; - boolValue2 = true; - boolValue3 = true; - boolValue4 = true; + boolValue1 = true;//head shot kill + boolValue2 = true;//head shot Hit + boolValue3 = true;//Body kill + boolValue4 = true;//Body Hit if (!string.IsNullOrEmpty(Localizer["Chat.AllSoundsOff"])) { player.PrintToChat(Localizer["Chat.AllSoundsOff"]); } - SaveToJsonFile((int)playerid, boolValue1, boolValue2, boolValue3, boolValue4, personDate); - } - - - if (menuon.ContainsKey(player.UserId!.Value)) - { - if(!string.IsNullOrEmpty(Config.HeadShotKillSoundPath) && trimmedMessage.Contains("!1")) - { - DateTime personDate = DateTime.Now; - bool boolValue1 = !personData.BoolValue1; - bool boolValue2 = personData.BoolValue2; - bool boolValue3 = personData.BoolValue3; - bool boolValue4 = personData.BoolValue4; - if(personData.BoolValue1) - { - if (!string.IsNullOrEmpty(Localizer["Chat.HeadShotKillOn"])) - { - player.PrintToChat(Localizer["Chat.HeadShotKillOn"]); - } - }else - { - if (!string.IsNullOrEmpty(Localizer["Chat.HeadShotKillOff"])) - { - player.PrintToChat(Localizer["Chat.HeadShotKillOff"]); - } - } - SaveToJsonFile((int)playerid, boolValue1, boolValue2, boolValue3, boolValue4, personDate); - } - if(!string.IsNullOrEmpty(Config.HeadShotHitSoundPath) && trimmedMessage.Contains("!2")) - { - DateTime personDate = DateTime.Now; - bool boolValue1 = personData.BoolValue1; - bool boolValue2 = !personData.BoolValue2; - bool boolValue3 = personData.BoolValue3; - bool boolValue4 = personData.BoolValue4; - if(personData.BoolValue2) - { - if (!string.IsNullOrEmpty(Localizer["Chat.HeadShotHitOn"])) - { - player.PrintToChat(Localizer["Chat.HeadShotHitOn"]); - } - }else - { - if (!string.IsNullOrEmpty(Localizer["Chat.HeadShotHitOff"])) - { - player.PrintToChat(Localizer["Chat.HeadShotHitOff"]); - } - } - SaveToJsonFile((int)playerid, boolValue1, boolValue2, boolValue3, boolValue4, personDate); - } - if(!string.IsNullOrEmpty(Config.BodyKillSoundPath) && trimmedMessage.Contains("!3")) - { - DateTime personDate = DateTime.Now; - bool boolValue1 = personData.BoolValue1; - bool boolValue2 = personData.BoolValue2; - bool boolValue3 = !personData.BoolValue3; - bool boolValue4 = personData.BoolValue4; - if(personData.BoolValue3) - { - if (!string.IsNullOrEmpty(Localizer["Chat.BodyKillOn"])) - { - player.PrintToChat(Localizer["Chat.BodyKillOn"]); - } - }else - { - if (!string.IsNullOrEmpty(Localizer["Chat.BodyKillOff"])) - { - player.PrintToChat(Localizer["Chat.BodyKillOff"]); - } - } - SaveToJsonFile((int)playerid, boolValue1, boolValue2, boolValue3, boolValue4, personDate); - } - if(!string.IsNullOrEmpty(Config.BodyHitSoundPath) && trimmedMessage.Contains("!4")) - { - DateTime personDate = DateTime.Now; - bool boolValue1 = personData.BoolValue1; - bool boolValue2 = personData.BoolValue2; - bool boolValue3 = personData.BoolValue3; - bool boolValue4 = !personData.BoolValue4; - if(personData.BoolValue4) - { - if (!string.IsNullOrEmpty(Localizer["Chat.BodyHitOn"])) - { - player.PrintToChat(Localizer["Chat.BodyHitOn"]); - } - }else - { - if (!string.IsNullOrEmpty(Localizer["Chat.BodyHitOff"])) - { - player.PrintToChat(Localizer["Chat.BodyHitOff"]); - } - } - SaveToJsonFile((int)playerid, boolValue1, boolValue2, boolValue3, boolValue4, personDate); - } - - if(trimmedMessage.Contains("!5")) - { - menuon.Remove(player.UserId.Value); - } + SaveToJsonFile((int)playerid, boolValue1, boolValue2, boolValue3, boolValue4, boolValue5, personDate); } return HookResult.Continue; @@ -331,9 +469,19 @@ private HookResult OnPlayerSayTeam(CCSPlayerController? player, CommandInfo info string[] disableCommands = Config.SoundDisableCommands.Split(','); if (!string.IsNullOrEmpty(Config.SoundDisableCommandsMenu) && disableCommandsmenu.Any(cmd => cmd.Equals(trimmedMessage, StringComparison.OrdinalIgnoreCase))) - { - if (menuon.ContainsKey(player.UserId!.Value))return HookResult.Continue; - menuon.Add(player.UserId.Value, true); + { + if (!menuon.ContainsKey(playerid)) + { + menuon.Add(playerid, true); + } + if (!currentIndexDict.ContainsKey(playerid)) + { + currentIndexDict.Add(playerid, 0); + } + if (!buttonPressed.ContainsKey(playerid)) + { + buttonPressed.Add(playerid, false); + } } if (!string.IsNullOrEmpty(Config.SoundDisableCommands) && disableCommands.Any(cmd => cmd.Equals(trimmedMessage, StringComparison.OrdinalIgnoreCase))) @@ -343,6 +491,7 @@ private HookResult OnPlayerSayTeam(CCSPlayerController? player, CommandInfo info bool boolValue2 = personData.BoolValue2; bool boolValue3 = personData.BoolValue3; bool boolValue4 = personData.BoolValue4; + bool boolValue5 = personData.BoolValue5; boolValue1 = true; boolValue2 = true; @@ -354,11 +503,11 @@ private HookResult OnPlayerSayTeam(CCSPlayerController? player, CommandInfo info player.PrintToChat(Localizer["Chat.AllSoundsOff"]); } - SaveToJsonFile((int)playerid, boolValue1, boolValue2, boolValue3, boolValue4, personDate); + SaveToJsonFile((int)playerid, boolValue1, boolValue2, boolValue3, boolValue4, boolValue5, personDate); } - if (menuon.ContainsKey(player.UserId!.Value)) + if (menuon.ContainsKey(playerid)) { if(!string.IsNullOrEmpty(Config.HeadShotKillSoundPath) && trimmedMessage.Contains("!1")) { @@ -367,20 +516,9 @@ private HookResult OnPlayerSayTeam(CCSPlayerController? player, CommandInfo info bool boolValue2 = personData.BoolValue2; bool boolValue3 = personData.BoolValue3; bool boolValue4 = personData.BoolValue4; - if(personData.BoolValue1) - { - if (!string.IsNullOrEmpty(Localizer["Chat.HeadShotKillOn"])) - { - player.PrintToChat(Localizer["Chat.HeadShotKillOn"]); - } - }else - { - if (!string.IsNullOrEmpty(Localizer["Chat.HeadShotKillOff"])) - { - player.PrintToChat(Localizer["Chat.HeadShotKillOff"]); - } - } - SaveToJsonFile((int)playerid, boolValue1, boolValue2, boolValue3, boolValue4, personDate); + bool boolValue5 = personData.BoolValue5; + + SaveToJsonFile((int)playerid, boolValue1, boolValue2, boolValue3, boolValue4, boolValue5, personDate); } if(!string.IsNullOrEmpty(Config.HeadShotHitSoundPath) && trimmedMessage.Contains("!2")) { @@ -389,20 +527,9 @@ private HookResult OnPlayerSayTeam(CCSPlayerController? player, CommandInfo info bool boolValue2 = !personData.BoolValue2; bool boolValue3 = personData.BoolValue3; bool boolValue4 = personData.BoolValue4; - if(personData.BoolValue2) - { - if (!string.IsNullOrEmpty(Localizer["Chat.HeadShotHitOn"])) - { - player.PrintToChat(Localizer["Chat.HeadShotHitOn"]); - } - }else - { - if (!string.IsNullOrEmpty(Localizer["Chat.HeadShotHitOff"])) - { - player.PrintToChat(Localizer["Chat.HeadShotHitOff"]); - } - } - SaveToJsonFile((int)playerid, boolValue1, boolValue2, boolValue3, boolValue4, personDate); + bool boolValue5 = personData.BoolValue5; + + SaveToJsonFile((int)playerid, boolValue1, boolValue2, boolValue3, boolValue4, boolValue5, personDate); } if(!string.IsNullOrEmpty(Config.BodyKillSoundPath) && trimmedMessage.Contains("!3")) { @@ -411,20 +538,9 @@ private HookResult OnPlayerSayTeam(CCSPlayerController? player, CommandInfo info bool boolValue2 = personData.BoolValue2; bool boolValue3 = !personData.BoolValue3; bool boolValue4 = personData.BoolValue4; - if(personData.BoolValue3) - { - if (!string.IsNullOrEmpty(Localizer["Chat.BodyKillOn"])) - { - player.PrintToChat(Localizer["Chat.BodyKillOn"]); - } - }else - { - if (!string.IsNullOrEmpty(Localizer["Chat.BodyKillOff"])) - { - player.PrintToChat(Localizer["Chat.BodyKillOff"]); - } - } - SaveToJsonFile((int)playerid, boolValue1, boolValue2, boolValue3, boolValue4, personDate); + bool boolValue5 = personData.BoolValue5; + + SaveToJsonFile((int)playerid, boolValue1, boolValue2, boolValue3, boolValue4, boolValue5, personDate); } if(!string.IsNullOrEmpty(Config.BodyHitSoundPath) && trimmedMessage.Contains("!4")) { @@ -433,33 +549,24 @@ private HookResult OnPlayerSayTeam(CCSPlayerController? player, CommandInfo info bool boolValue2 = personData.BoolValue2; bool boolValue3 = personData.BoolValue3; bool boolValue4 = !personData.BoolValue4; - if(personData.BoolValue4) - { - if (!string.IsNullOrEmpty(Localizer["Chat.BodyHitOn"])) - { - player.PrintToChat(Localizer["Chat.BodyHitOn"]); - } - }else - { - if (!string.IsNullOrEmpty(Localizer["Chat.BodyHitOff"])) - { - player.PrintToChat(Localizer["Chat.BodyHitOff"]); - } - } - SaveToJsonFile((int)playerid, boolValue1, boolValue2, boolValue3, boolValue4, personDate); + bool boolValue5 = personData.BoolValue5; + + SaveToJsonFile((int)playerid, boolValue1, boolValue2, boolValue3, boolValue4, boolValue5, personDate); } if(trimmedMessage.Contains("!5")) { - menuon.Remove(player.UserId.Value); + menuon.Remove(playerid); } } return HookResult.Continue; } - - private HookResult OnPlayerDeath(EventPlayerDeath @event, GameEventInfo _) + + //Death Event (Kill HeadShot Or Body Shot) + private HookResult OnPlayerDeath(EventPlayerDeath @event, GameEventInfo info) { + if(@event == null)return HookResult.Continue; var attacker = @event.Attacker; var victim = @event.Userid; if (attacker == null || victim == null || !attacker.IsValid || !victim.IsValid || attacker.IsBot || attacker.IsHLTV)return HookResult.Continue; @@ -521,9 +628,10 @@ private HookResult OnPlayerDeath(EventPlayerDeath @event, GameEventInfo _) } return HookResult.Continue; } - - private HookResult OnPlayerHurt(EventPlayerHurt @event, GameEventInfo _) + //Hurt Event (Hit HeadShot Or Body Shot) + private HookResult OnPlayerHurt(EventPlayerHurt @event, GameEventInfo info) { + if(@event == null)return HookResult.Continue; var attacker = @event.Attacker; var victim = @event.Userid; if (attacker == null || victim == null || !attacker.IsValid || !victim.IsValid || attacker.IsBot || attacker.IsHLTV)return HookResult.Continue; @@ -582,6 +690,9 @@ private HookResult OnPlayerHurt(EventPlayerHurt @event, GameEventInfo _) } return HookResult.Continue; } + + /////////////////////////////////////////////////////////// + //Cookies private class PersonData { public int Id { get; set; } @@ -589,10 +700,11 @@ private class PersonData public bool BoolValue2 { get; set; } public bool BoolValue3 { get; set; } public bool BoolValue4 { get; set; } + public bool BoolValue5 { get; set; } public DateTime Date { get; set; } } - private void SaveToJsonFile(int id, bool boolValue1, bool boolValue2, bool boolValue3, bool boolValue4, DateTime date) + private void SaveToJsonFile(int id, bool boolValue1, bool boolValue2, bool boolValue3, bool boolValue4, bool BoolValue5, DateTime date) { string Fpath = Path.Combine(ModuleDirectory, "../../plugins/Kill_Sound/Cookies/"); string Fpathc = Path.Combine(ModuleDirectory, "../../plugins/Kill_Sound/Cookies/Kill_Sound_Cookies.json"); @@ -624,12 +736,14 @@ private void SaveToJsonFile(int id, bool boolValue1, bool boolValue2, bool boolV existingPerson.BoolValue3 = boolValue3; if (existingPerson.BoolValue4 != boolValue4) existingPerson.BoolValue4 = boolValue4; + if (existingPerson.BoolValue5 != BoolValue5) + existingPerson.BoolValue5 = BoolValue5; existingPerson.Date = date; } else { - PersonData newPerson = new PersonData { Id = id, BoolValue1 = boolValue1, BoolValue2 = boolValue2, BoolValue3 = boolValue3, BoolValue4 = boolValue4, Date = date }; + PersonData newPerson = new PersonData { Id = id, BoolValue1 = boolValue1, BoolValue2 = boolValue2, BoolValue3 = boolValue3, BoolValue4 = boolValue4, BoolValue5 = BoolValue5, Date = date }; allPersonsData.Add(newPerson); } allPersonsData.RemoveAll(p => (DateTime.Now - p.Date).TotalDays > Config.RemovePlayerCookieOlderThanXDays); @@ -686,12 +800,61 @@ private PersonData RetrievePersonDataById(int targetId) } return new PersonData(); } + ///Done Cookies + /////////////////////////////////////////////////////////// + + /////////////////////////////////////////////////////////// + //Clean Up Dictionary List if Disconnect Or Plugin Unload Or MapEnd + private HookResult OnPlayerDisconnect(EventPlayerDisconnect @event, GameEventInfo info) + { + if (@event == null) return HookResult.Continue; + var player = @event.Userid; + if (player == null || !player.IsValid || player.IsBot || player.IsHLTV)return HookResult.Continue; + var playerid = player.SteamID; + + if (intromenuon.ContainsKey(playerid)) + { + intromenuon.Remove(playerid); + } + + if (menuon.ContainsKey(playerid)) + { + menuon.Remove(playerid); + } + + if (menuclose.ContainsKey(playerid)) + { + menuclose.Remove(playerid); + } + + if (currentIndexDict.ContainsKey(playerid)) + { + currentIndexDict.Remove(playerid); + } + + if (buttonPressed.ContainsKey(playerid)) + { + buttonPressed.Remove(playerid); + } + return HookResult.Continue; + } public override void Unload(bool hotReload) { + intromenuon.Clear(); menuon.Clear(); + menuclose.Clear(); + currentIndexDict.Clear(); + buttonPressed.Clear(); } private void OnMapEnd() { + intromenuon.Clear(); menuon.Clear(); + menuclose.Clear(); + currentIndexDict.Clear(); + buttonPressed.Clear(); } + //Done Clean Up Dictionary List + /////////////////////////////////////////////////////////// + } \ No newline at end of file