Skip to content

Commit

Permalink
feature: DiceChangePlayerModel
Browse files Browse the repository at this point in the history
  • Loading branch information
derkalle4 committed Dec 29, 2024
1 parent 86d673c commit 4ccf19b
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 3 deletions.
53 changes: 53 additions & 0 deletions src/RollTheDice+DiceChangePlayerModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Utils;

namespace RollTheDice
{
public partial class RollTheDice : BasePlugin
{
private Dictionary<CCSPlayerController, string> _playersWithChangedPlayerModel = new();

private Dictionary<string, string> 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<string, string>
{
{"_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();
}
}
}
3 changes: 2 additions & 1 deletion src/RollTheDice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ private void InitializeDices()
DiceBigTaserBattery,
DicePlayerCloak,
DiceGiveHealthShot,
DiceNoExplosives
DiceNoExplosives,
DiceChangePlayerModel
};
// initialize dice counter
foreach (var dice in _dices)
Expand Down
4 changes: 3 additions & 1 deletion src/lang/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -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!"
}
4 changes: 3 additions & 1 deletion src/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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!"
}

0 comments on commit 4ccf19b

Please sign in to comment.