mirror of
https://github.com/Nereziel/cs2-WeaponPaints.git
synced 2026-02-25 12:52:17 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e1f24abd5d | ||
|
|
646050fb72 | ||
|
|
87dadb9c62 |
@@ -91,7 +91,6 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
|||||||
};
|
};
|
||||||
public override void Load(bool hotReload)
|
public override void Load(bool hotReload)
|
||||||
{
|
{
|
||||||
SetGlobalExceptionHandler();
|
|
||||||
if (!Config.GlobalShare)
|
if (!Config.GlobalShare)
|
||||||
{
|
{
|
||||||
BuildDatabaseConnectionString();
|
BuildDatabaseConnectionString();
|
||||||
@@ -113,10 +112,11 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
|||||||
{
|
{
|
||||||
for (int i = 1; i <= Server.MaxPlayers; i++)
|
for (int i = 1; i <= Server.MaxPlayers; i++)
|
||||||
{
|
{
|
||||||
if (Config.Additional.KnifeEnabled)
|
|
||||||
await GetKnifeFromDatabase(i);
|
|
||||||
if (Config.Additional.SkinEnabled)
|
if (Config.Additional.SkinEnabled)
|
||||||
await GetWeaponPaintsFromDatabase(i);
|
await GetWeaponPaintsFromDatabase(i);
|
||||||
|
|
||||||
|
if (Config.Additional.KnifeEnabled)
|
||||||
|
await GetKnifeFromDatabase(i);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -218,21 +218,8 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
|||||||
*/
|
*/
|
||||||
public override void Unload(bool hotReload)
|
public override void Unload(bool hotReload)
|
||||||
{
|
{
|
||||||
RemoveGlobalExceptionHandler();
|
|
||||||
base.Unload(hotReload);
|
base.Unload(hotReload);
|
||||||
}
|
}
|
||||||
private void GlobalExceptionHandler(object? sender, FirstChanceExceptionEventArgs @event)
|
|
||||||
{
|
|
||||||
Log(@event.Exception.ToString());
|
|
||||||
}
|
|
||||||
private void SetGlobalExceptionHandler()
|
|
||||||
{
|
|
||||||
AppDomain.CurrentDomain.FirstChanceException += this.GlobalExceptionHandler;
|
|
||||||
}
|
|
||||||
private void RemoveGlobalExceptionHandler()
|
|
||||||
{
|
|
||||||
AppDomain.CurrentDomain.FirstChanceException -= this.GlobalExceptionHandler;
|
|
||||||
}
|
|
||||||
private void RegisterCommands()
|
private void RegisterCommands()
|
||||||
{
|
{
|
||||||
AddCommand($"css_{Config.Additional.CommandSkin}", "Skins info", (player, info) => { if (player == null) return; OnCommandWS(player, info); });
|
AddCommand($"css_{Config.Additional.CommandSkin}", "Skins info", (player, info) => { if (player == null) return; OnCommandWS(player, info); });
|
||||||
@@ -340,15 +327,8 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
|||||||
|
|
||||||
if (Config.Additional.KnifeEnabled)
|
if (Config.Additional.KnifeEnabled)
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
if (!PlayerHasKnife(player))
|
if (!PlayerHasKnife(player))
|
||||||
GiveKnifeToPlayer(player);
|
GiveKnifeToPlayer(player);
|
||||||
*/
|
|
||||||
RemoveKnifeFromPlayer(player);
|
|
||||||
AddTimer(0.2f, () =>
|
|
||||||
{
|
|
||||||
GiveKnifeToPlayer(player);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return HookResult.Continue;
|
return HookResult.Continue;
|
||||||
@@ -376,10 +356,17 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
|||||||
g_playersKnife[(int)player.EntityIndex!.Value.Value] != "weapon_knife")
|
g_playersKnife[(int)player.EntityIndex!.Value.Value] != "weapon_knife")
|
||||||
{
|
{
|
||||||
RemoveKnifeFromPlayer(player);
|
RemoveKnifeFromPlayer(player);
|
||||||
AddTimer(0.2f, () =>
|
|
||||||
|
AddTimer(0.1f, () =>
|
||||||
{
|
{
|
||||||
GiveKnifeToPlayer(player);
|
if (!PlayerHasKnife(player))
|
||||||
|
GiveKnifeToPlayer(player);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (Config.Additional.SkinVisibilityFix)
|
||||||
|
{
|
||||||
|
AddTimer(0.25f, () => RefreshSkins(player));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return HookResult.Continue;
|
return HookResult.Continue;
|
||||||
@@ -472,25 +459,23 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
|||||||
}
|
}
|
||||||
private void GiveKnifeToPlayer(CCSPlayerController? player)
|
private void GiveKnifeToPlayer(CCSPlayerController? player)
|
||||||
{
|
{
|
||||||
if (!Config.Additional.KnifeEnabled) return;
|
if (!Config.Additional.KnifeEnabled || player == null || !player.IsValid) return;
|
||||||
if (player == null || !player.IsValid || !player.PawnIsAlive) return;
|
|
||||||
|
|
||||||
if (g_playersKnife.TryGetValue((int)player.EntityIndex!.Value.Value, out var knife))
|
if (g_playersKnife.TryGetValue((int)player.EntityIndex!.Value.Value, out var knife))
|
||||||
{
|
{
|
||||||
player.GiveNamedItem(knife);
|
player.GiveNamedItem(knife);
|
||||||
}
|
}
|
||||||
|
else if (Config.Additional.GiveRandomKnife)
|
||||||
|
{
|
||||||
|
Random random = new Random();
|
||||||
|
int index = random.Next(knifeTypes.Count);
|
||||||
|
var randomKnife = knifeTypes.Values.ElementAt(index);
|
||||||
|
player.GiveNamedItem(randomKnife);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (Config.Additional.GiveRandomKnife)
|
var defaultKnife = (CsTeam)player.TeamNum == CsTeam.Terrorist ? "weapon_knife_t" : "weapon_knife";
|
||||||
{
|
player.GiveNamedItem(defaultKnife);
|
||||||
Random random = new Random();
|
|
||||||
int index = random.Next(knifeTypes.Count);
|
|
||||||
player.GiveNamedItem(knifeTypes.Values.ElementAt(index));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
player.GiveNamedItem((CsTeam)player.TeamNum == CsTeam.Terrorist ? "weapon_knife_t" : "weapon_knife");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void RemoveKnifeFromPlayer(CCSPlayerController? player)
|
private void RemoveKnifeFromPlayer(CCSPlayerController? player)
|
||||||
|
|||||||
Reference in New Issue
Block a user