-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathDefaultSkins.cs
134 lines (119 loc) · 4.75 KB
/
DefaultSkins.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Attributes.Registration;
using CounterStrikeSharp.API.Modules.Utils;
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Modules.Commands;
namespace DefaultSkins;
public class DefaultSkins : BasePlugin
{
public override string ModuleName => "CMod Default Skins";
public override string ModuleAuthor => "Christopher Teljstedt @ Challengermode";
public override string ModuleVersion => "0.0.3";
public static readonly string ModelPathCtmHeavy = "characters\\models\\ctm_heavy\\ctm_heavy.vmdl";
public static readonly string ModelPathCtmSas = "characters\\models\\ctm_sas\\ctm_sas.vmdl";
public static readonly string ModelPathTmHeavy = "characters\\models\\tm_phoenix_heavy\\tm_phoenix_heavy.vmdl";
public static readonly string ModelPathTmPhoenix = "characters\\models\\tm_phoenix\\tm_phoenix.vmdl";
public bool EnableDefaultSkins { get; set; } = false;
public bool HeavySkins { get; set; } = false;
public override void Load(bool hotReload)
{
RegisterListener<Listeners.OnMapStart>(map =>
{
Server.PrecacheModel(ModelPathCtmHeavy);
Server.PrecacheModel(ModelPathCtmSas);
Server.PrecacheModel(ModelPathTmHeavy);
Server.PrecacheModel(ModelPathTmPhoenix);
});
RegisterEventHandler<EventPlayerSpawn>(OnPlayerSpawnEvent);
RegisterListener<Listeners.OnMapEnd>(() => Unload(true));
Console.WriteLine($"{ModuleName} version {ModuleVersion} by {ModuleAuthor} is loaded.");
}
[ConsoleCommand("cm_default_skins", "Enable / disable default skins mod")]
public void OnEnableDefaultSkins(CCSPlayerController? player, CommandInfo command)
{
try
{
if (command.ArgCount < 2)
{
Console.WriteLine("Missing argument for cm_default_skins");
return;
}
if (!int.TryParse(command.GetArg(1), out int enable))
{
Console.WriteLine("Invalid argument for cm_default_skins: {0}", command.GetArg(1));
return;
}
EnableDefaultSkins = Convert.ToBoolean(enable);
Console.WriteLine("version: {0}, enabled: {1}", ModuleVersion, EnableDefaultSkins);
}
catch (Exception ex)
{
Console.WriteLine("Error processing rcon command", ex.Message);
}
}
[ConsoleCommand("cm_heavy_models", "Enable / disable heavy model skins")]
public void OnHeavyModels(CCSPlayerController? player, CommandInfo command)
{
try
{
if (command.ArgCount < 2)
{
Console.WriteLine("Missing argument for cm_heavy_models");
return;
}
if (!int.TryParse(command.GetArg(1), out int enable))
{
Console.WriteLine("Invalid argument for cm_heavy_models: {0}", command.GetArg(1));
return;
}
HeavySkins = Convert.ToBoolean(enable);
}
catch (Exception ex)
{
Console.WriteLine("Error processing rcon command", ex.Message);
}
}
[GameEventHandler]
public HookResult OnPlayerSpawnEvent(EventPlayerSpawn @event, GameEventInfo info)
{
if(@event == null || !EnableDefaultSkins)
{
return HookResult.Continue;
}
CCSPlayerController player = @event.Userid;
if (player == null
|| !player.IsValid
|| player.PlayerPawn == null
|| !player.PlayerPawn.IsValid
|| player.PlayerPawn.Value == null
|| !player.PlayerPawn.Value.IsValid)
{
return HookResult.Continue;
}
try
{
// TODO: Server crash if player connects, mp_swapteams and reconnect
CsTeam team = player.PendingTeamNum != player.TeamNum ? (CsTeam)player.PendingTeamNum : (CsTeam)player.TeamNum;
if ((CsTeam)player.TeamNum == CsTeam.CounterTerrorist)
{
SetModelNextServerFrame(player.PlayerPawn.Value, HeavySkins ? ModelPathCtmHeavy : ModelPathCtmSas);
}
if ((CsTeam)player.TeamNum == CsTeam.Terrorist)
{
SetModelNextServerFrame(player.PlayerPawn.Value, HeavySkins ? ModelPathTmHeavy : ModelPathTmPhoenix);
}
}
catch (Exception ex)
{
Console.WriteLine("Could not set player model: {0}", ex);
}
return HookResult.Continue;
}
public static void SetModelNextServerFrame(CCSPlayerPawn playerPawn, string model)
{
Server.NextFrame(() =>
{
playerPawn.SetModel(model);
});
}
}