diff --git a/Store/src/config/config.cs b/Store/src/config/config.cs index 7bba235..ca6f48c 100644 --- a/Store/src/config/config.cs +++ b/Store/src/config/config.cs @@ -68,4 +68,4 @@ public class Config_Setting [JsonPropertyName("Menu")] public Config_Menu Menu { get; set; } = new Config_Menu(); [JsonPropertyName("Settings")] public Config_Setting Settings { get; set; } = new Config_Setting(); [JsonPropertyName("Items")] public Dictionary>> Items { get; set; } = []; -} +} \ No newline at end of file diff --git a/Store/src/item/items/playerskin.cs b/Store/src/item/items/playerskin.cs index 4d39280..08e1b76 100644 --- a/Store/src/item/items/playerskin.cs +++ b/Store/src/item/items/playerskin.cs @@ -53,7 +53,10 @@ public static bool OnEquip(CCSPlayerController player, Dictionary + var modelData = GetModel(player, player.TeamNum); + + if (modelData.HasValue) { - ChangeModel(player, player.TeamNum); - }); + player.ChangeModelDelay(modelData.Value.modelname, modelData.Value.disableleg, player.TeamNum); + } return HookResult.Continue; } @@ -114,7 +125,12 @@ public static HookResult OnPlayerTeam(EventPlayerTeam @event, GameEventInfo info if (@event.Team == 2 || @event.Team == 3) { - ChangeModel(player, player.TeamNum); + var modelDatas = GetModel(player, @event.Team); + + if (modelDatas.HasValue) + { + player.PlayerPawn.Value!.ChangeModel(modelDatas.Value.modelname, modelDatas.Value.disableleg); + } } return HookResult.Continue; @@ -125,32 +141,6 @@ public static HookResult OnRoundStart(EventRoundStart @event, GameEventInfo info ForceModelDefault = false; return HookResult.Continue; } - public static void SetDefaultModel(CCSPlayerController player) - { - string[] modelsArray = player.Team == CsTeam.CounterTerrorist ? Instance.Config.DefaultModels.CT : Instance.Config.DefaultModels.T; - int maxIndex = modelsArray.Length; - - if (maxIndex > 0) - { - int randomnumber = Instance.Random.Next(0, maxIndex - 1); - - string model = modelsArray[randomnumber]; - - SetPlayerModel(player, model, Instance.Config.Settings.DefaultModelDisableLeg, player.TeamNum); - } - } - private static void SetPlayerModel(CCSPlayerController player, string model, bool disable_leg, int slotNumber) - { - float apply_delay = float.Max(Instance.Config.Settings.ApplyPlayerskinDelay, 0.1f); - - Instance.AddTimer(apply_delay, () => - { - if (player.IsValid && player.TeamNum == slotNumber && player.PawnIsAlive) - { - player.PlayerPawn.Value?.ChangeModel(model, disable_leg); - } - }, TimerFlags.STOP_ON_MAPCHANGE); - } private static void Command_Model0(CCSPlayerController? player, CommandInfo info) { @@ -163,7 +153,12 @@ private static void Command_Model0(CCSPlayerController? player, CommandInfo info foreach (CCSPlayerController target in Utilities.GetPlayers()) { - SetDefaultModel(target); + var modelDatas = GetDefaultModel(target); + + if (modelDatas.HasValue) + { + target.PlayerPawn.Value!.ChangeModel(modelDatas.Value.modelname, modelDatas.Value.disableleg); + } } Server.PrintToChatAll(Instance.Config.Tag + Instance.Localizer["css_model0", player?.PlayerName ?? Instance.Localizer["Console"]]); @@ -182,18 +177,11 @@ private static void Command_Model1(CCSPlayerController? player, CommandInfo info foreach (CCSPlayerController target in Utilities.GetPlayers()) { - Store_Equipment? item = Instance.GlobalStorePlayerEquipments.FirstOrDefault(p => p.SteamID == target.SteamID && p.Type == "playerskin" && p.Slot == target.TeamNum); + var modelDatas = GetModel(target, target.TeamNum); - if (item != null) + if (modelDatas.HasValue) { - Dictionary? itemdata = Item.GetItem(item.Type, item.UniqueId); - - if (itemdata == null) - { - continue; - } - - SetPlayerModel(target, item.UniqueId, itemdata["disable_leg"] is "true" or "1", item.Slot); + target.PlayerPawn.Value!.ChangeModel(modelDatas.Value.modelname, modelDatas.Value.disableleg); } } @@ -202,24 +190,46 @@ private static void Command_Model1(CCSPlayerController? player, CommandInfo info ForceModelDefault = false; } - private static void ChangeModel(CCSPlayerController player, int teamnum) + private static (string modelname, bool disableleg)? GetModel(CCSPlayerController player, int teamnum) { Store_Equipment? item = Instance.GlobalStorePlayerEquipments.FirstOrDefault(p => p.SteamID == player.SteamID && p.Type == "playerskin" && p.Slot == teamnum); if (item == null || ForceModelDefault) { - SetDefaultModel(player); + return GetDefaultModel(player); } else { - Dictionary? itemdata = Item.GetItem(item.Type, item.UniqueId); + return GetStoreModel(player, item); + } + } - if (itemdata == null) - { - return; - } + private static (string modelname, bool disableleg)? GetDefaultModel(CCSPlayerController player) + { + string[] modelsArray = player.Team == CsTeam.CounterTerrorist ? Instance.Config.DefaultModels.CT : Instance.Config.DefaultModels.T; + int maxIndex = modelsArray.Length; - SetPlayerModel(player, item.UniqueId, itemdata["disable_leg"] is "true" or "1", item.Slot); + if (maxIndex > 0) + { + int randomnumber = Instance.Random.Next(0, maxIndex - 1); + + string model = modelsArray[randomnumber]; + + return (model, Instance.Config.Settings.DefaultModelDisableLeg); + } + + return null; + } + + private static (string modelname, bool disableleg)? GetStoreModel(CCSPlayerController player, Store_Equipment item) + { + Dictionary? itemdata = Item.GetItem(item.Type, item.UniqueId); + + if (itemdata == null) + { + return null; } + + return (item.UniqueId, itemdata["disable_leg"] is "true" or "1"); } -} +} \ No newline at end of file diff --git a/Store/src/playerutils/playerutils.cs b/Store/src/playerutils/playerutils.cs index 91eb7e4..0001ba1 100644 --- a/Store/src/playerutils/playerutils.cs +++ b/Store/src/playerutils/playerutils.cs @@ -1,6 +1,7 @@ using CounterStrikeSharp.API; using CounterStrikeSharp.API.Core; using CounterStrikeSharp.API.Core.Translations; +using CounterStrikeSharp.API.Modules.Timers; using System.Drawing; using System.Text; using static Store.Store; @@ -18,6 +19,20 @@ static public void PrintToChatMessage(this CCSPlayerController player, string me player.PrintToChat(builder.ToString()); } } + + static public void ChangeModelDelay(this CCSPlayerController player, string model, bool disableleg, int slotNumber) + { + float apply_delay = float.Max(Instance.Config.Settings.ApplyPlayerskinDelay, 0.1f); + + Instance.AddTimer(apply_delay, () => + { + if (player.IsValid && player.TeamNum == slotNumber && player.PawnIsAlive) + { + player.PlayerPawn.Value?.ChangeModel(model, disableleg); + } + }, TimerFlags.STOP_ON_MAPCHANGE); + } + static public void ChangeModel(this CCSPlayerPawn pawn, string model, bool disableleg) { if (model == string.Empty)