From 4ccf19b2fb1a016c00c023a0033edbc3e0e368eb Mon Sep 17 00:00:00 2001 From: Kalle Date: Sun, 29 Dec 2024 16:38:18 +0100 Subject: [PATCH] feature: DiceChangePlayerModel --- src/RollTheDice+DiceChangePlayerModel.cs | 53 ++++++++++++++++++++++++ src/RollTheDice.cs | 3 +- src/lang/de.json | 4 +- src/lang/en.json | 4 +- 4 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 src/RollTheDice+DiceChangePlayerModel.cs diff --git a/src/RollTheDice+DiceChangePlayerModel.cs b/src/RollTheDice+DiceChangePlayerModel.cs new file mode 100644 index 0000000..a340770 --- /dev/null +++ b/src/RollTheDice+DiceChangePlayerModel.cs @@ -0,0 +1,53 @@ +using CounterStrikeSharp.API.Core; +using CounterStrikeSharp.API.Modules.Utils; + +namespace RollTheDice +{ + public partial class RollTheDice : BasePlugin + { + private Dictionary _playersWithChangedPlayerModel = new(); + + private Dictionary DiceChangePlayerModel(CCSPlayerController player, CCSPlayerPawn playerPawn) + { + string playerModel = playerPawn.CBodyComponent!.SceneNode!.GetSkeletonInstance().ModelState.ModelName; + _playersWithChangedPlayerModel.Add(player, playerModel); + Console.WriteLine(playerModel); + // set new player model + if (playerPawn.TeamNum == (int)CsTeam.Terrorist) + { + playerPawn.SetModel("characters/models/ctm_sas/ctm_sas.vmdl"); + } + else + { + playerPawn.SetModel("characters/models/tm_phoenix/tm_phoenix.vmdl"); + } + return new Dictionary + { + {"_translation_player", "DiceChangePlayerModelPlayer"}, + {"_translation_other", "DiceChangePlayerModel"}, + { "playerName", player.PlayerName } + }; + } + + private void DiceChangePlayerModelUnload() + { + DiceChangePlayerModelReset(); + } + + private void DiceChangePlayerModelReset() + { + // iterate through all players + foreach (var kvp in _playersWithChangedPlayerModel) + { + var player = kvp.Key; + var model = kvp.Value; + if (player == null || player.PlayerPawn == null || !player.PlayerPawn.IsValid || player.PlayerPawn.Value == null || player.LifeState != (byte)LifeState_t.LIFE_ALIVE) continue; + // get player pawn + var playerPawn = player.PlayerPawn.Value!; + // reset player model + playerPawn.SetModel(model); + } + _playersWithChangedPlayerModel.Clear(); + } + } +} diff --git a/src/RollTheDice.cs b/src/RollTheDice.cs index 410a584..52fbfa6 100644 --- a/src/RollTheDice.cs +++ b/src/RollTheDice.cs @@ -132,7 +132,8 @@ private void InitializeDices() DiceBigTaserBattery, DicePlayerCloak, DiceGiveHealthShot, - DiceNoExplosives + DiceNoExplosives, + DiceChangePlayerModel }; // initialize dice counter foreach (var dice in _dices) diff --git a/src/lang/de.json b/src/lang/de.json index aacbb41..31e060d 100644 --- a/src/lang/de.json +++ b/src/lang/de.json @@ -61,5 +61,7 @@ "DiceGiveHealthShotPlayer": "{default}Du hast {amount}x Gesundheitsspritze(n) erhalten!", "DiceGiveHealthShot": "{purple}[WürfelSpiel] {green}{playerName} {default}hat {amount}x Gesundheitsspritze(n) erhalten!", "DiceNoExplosivesPlayer": "{default}Du kannst keine Granaten benutzen!", - "DiceNoExplosives": "{purple}[WürfelSpiel] {green}{playerName} {default}kann keine Granaten benutzen!" + "DiceNoExplosives": "{purple}[WürfelSpiel] {green}{playerName} {default}kann keine Granaten benutzen!", + "DiceChangePlayerModelPlayer": "{default}Du siehst aus wie deine Gegner!", + "DiceChangePlayerModel": "{purple}[WürfelSpiel] {green}{playerName} {default}verkleidet sich als Gegner!" } \ No newline at end of file diff --git a/src/lang/en.json b/src/lang/en.json index eec1d66..dd5acab 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -61,5 +61,7 @@ "DiceGiveHealthShotPlayer": "{default}You got {amount}x health shot(s)!", "DiceGiveHealthShot": "{purple}[RollTheDice] {green}{playerName} {default}got {amount}x health shot(s)!", "DiceNoExplosivesPlayer": "{default}You can't use explosives!", - "DiceNoExplosives": "{purple}[RollTheDice] {green}{playerName} {default}can't use explosives!" + "DiceNoExplosives": "{purple}[RollTheDice] {green}{playerName} {default}can't use explosives!", + "DiceChangePlayerModelPlayer": "{default}You look like your enemies!", + "DiceChangePlayerModel": "{purple}[RollTheDice] {green}{playerName} {default}disguises as an enemy!" } \ No newline at end of file