mirror of
https://github.com/Nereziel/cs2-WeaponPaints.git
synced 2026-02-17 18:39:07 +00:00
Compare commits
20 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
da86756092 | ||
|
|
a3306b5f8f | ||
|
|
379c2f797c | ||
|
|
fc42190701 | ||
|
|
643beaad46 | ||
|
|
6d44e582be | ||
|
|
813a9abcc8 | ||
|
|
b0790729be | ||
|
|
74a6dff114 | ||
|
|
e37f111f1b | ||
|
|
5e6286b667 | ||
|
|
ed4da98a50 | ||
|
|
c825febeac | ||
|
|
1e5c2a439f | ||
|
|
21eccfb6d9 | ||
|
|
a6b193cd13 | ||
|
|
b992433d44 | ||
|
|
06559af230 | ||
|
|
dfe6b200d8 | ||
|
|
3edcb5e52f |
207
Commands.cs
207
Commands.cs
@@ -1,12 +1,71 @@
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using CounterStrikeSharp.API.Modules.Commands;
|
||||
using CounterStrikeSharp.API.Modules.Entities;
|
||||
using CounterStrikeSharp.API.Modules.Menu;
|
||||
|
||||
namespace WeaponPaints
|
||||
{
|
||||
public partial class WeaponPaints
|
||||
{
|
||||
private void OnCommandRefresh(CCSPlayerController? player, CommandInfo command)
|
||||
{
|
||||
if (!Config.Additional.CommandWpEnabled || !Config.Additional.SkinEnabled || !g_bCommandsAllowed) return;
|
||||
if (!Utility.IsPlayerValid(player)) return;
|
||||
if (player == null || player.Index <= 0) return;
|
||||
int playerIndex = (int)player!.Index;
|
||||
|
||||
PlayerInfo playerInfo = new PlayerInfo
|
||||
{
|
||||
UserId = player.UserId,
|
||||
Index = (int)player.Index,
|
||||
SteamId = player?.AuthorizedSteamID?.SteamId64.ToString(),
|
||||
Name = player?.PlayerName,
|
||||
IpAddress = player?.IpAddress?.Split(":")[0]
|
||||
};
|
||||
|
||||
if (playerIndex != 0 && DateTime.UtcNow >= commandCooldown[playerIndex].AddSeconds(Config.CmdRefreshCooldownSeconds))
|
||||
{
|
||||
commandCooldown[playerIndex] = DateTime.UtcNow;
|
||||
if (weaponSync != null)
|
||||
Task.Run(async () => await weaponSync.GetWeaponPaintsFromDatabase(playerInfo));
|
||||
if (Config.Additional.KnifeEnabled)
|
||||
{
|
||||
if (weaponSync != null)
|
||||
Task.Run(async () => await weaponSync.GetKnifeFromDatabase(playerInfo));
|
||||
|
||||
RefreshWeapons(player);
|
||||
}
|
||||
if (!string.IsNullOrEmpty(Localizer["wp_command_refresh_done"]))
|
||||
{
|
||||
player!.Print(Localizer["wp_command_refresh_done"]);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(Localizer["wp_command_cooldown"]))
|
||||
{
|
||||
player!.Print(Localizer["wp_command_cooldown"]);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnCommandWS(CCSPlayerController? player, CommandInfo command)
|
||||
{
|
||||
if (!Config.Additional.SkinEnabled) return;
|
||||
if (!Utility.IsPlayerValid(player)) return;
|
||||
|
||||
if (!string.IsNullOrEmpty(Localizer["wp_info_website"]))
|
||||
{
|
||||
player!.Print(Localizer["wp_info_website", Config.Website]);
|
||||
}
|
||||
if (!string.IsNullOrEmpty(Localizer["wp_info_refresh"]))
|
||||
{
|
||||
player!.Print(Localizer["wp_info_refresh"]);
|
||||
}
|
||||
if (!Config.Additional.KnifeEnabled) return;
|
||||
if (!string.IsNullOrEmpty(Localizer["wp_info_knife"]))
|
||||
{
|
||||
player!.Print(Localizer["wp_info_knife"]);
|
||||
}
|
||||
}
|
||||
|
||||
private void RegisterCommands()
|
||||
{
|
||||
AddCommand($"css_{Config.Additional.CommandSkin}", "Skins info", (player, info) =>
|
||||
@@ -29,6 +88,7 @@ namespace WeaponPaints
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void SetupKnifeMenu()
|
||||
{
|
||||
if (!Config.Additional.KnifeEnabled || !g_bCommandsAllowed) return;
|
||||
@@ -37,43 +97,44 @@ namespace WeaponPaints
|
||||
.Where(pair => pair.Key.StartsWith("weapon_knife") || pair.Key.StartsWith("weapon_bayonet"))
|
||||
.ToDictionary(pair => pair.Key, pair => pair.Value);
|
||||
|
||||
var giveItemMenu = new ChatMenu(Utility.ReplaceTags($" {Config.Messages.KnifeMenuTitle}"));
|
||||
var giveItemMenu = new ChatMenu(Localizer["wp_knife_menu_title"]);
|
||||
var handleGive = (CCSPlayerController? player, ChatMenuOption option) =>
|
||||
{
|
||||
if (Utility.IsPlayerValid(player))
|
||||
{
|
||||
if (player == null) return;
|
||||
var knifeName = option.Text;
|
||||
var knifeKey = knivesOnly.FirstOrDefault(x => x.Value == knifeName).Key;
|
||||
if (!string.IsNullOrEmpty(knifeKey))
|
||||
{
|
||||
string temp = "";
|
||||
|
||||
if (!string.IsNullOrEmpty(Config.Messages.ChosenKnifeMenu))
|
||||
if (!string.IsNullOrEmpty(Localizer["wp_knife_menu_select"]))
|
||||
{
|
||||
temp = $" {Config.Prefix} {Config.Messages.ChosenKnifeMenu}".Replace("{KNIFE}", knifeName);
|
||||
player!.PrintToChat(Utility.ReplaceTags(temp));
|
||||
player!.Print(Localizer["wp_knife_menu_select", knifeName]);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(Config.Messages.ChosenKnifeMenuKill) && Config.Additional.CommandKillEnabled)
|
||||
if (!string.IsNullOrEmpty(Localizer["wp_knife_menu_kill"]) && Config.Additional.CommandKillEnabled)
|
||||
{
|
||||
temp = $" {Config.Prefix} {Config.Messages.ChosenKnifeMenuKill}";
|
||||
player!.PrintToChat(Utility.ReplaceTags(temp));
|
||||
player!.Print(Localizer["wp_knife_menu_kill"]);
|
||||
}
|
||||
|
||||
PlayerInfo playerInfo = new PlayerInfo
|
||||
{
|
||||
UserId = player.UserId,
|
||||
Index = (int)player.Index,
|
||||
SteamId = player?.AuthorizedSteamID?.SteamId64.ToString(),
|
||||
Name = player?.PlayerName,
|
||||
IpAddress = player?.IpAddress?.Split(":")[0]
|
||||
};
|
||||
|
||||
g_playersKnife[(int)player!.Index] = knifeKey;
|
||||
|
||||
if (player!.PawnIsAlive && g_bCommandsAllowed)
|
||||
{
|
||||
//g_changedKnife.Add((int)player.Index);
|
||||
RefreshWeapons(player);
|
||||
//RefreshPlayerKnife(player);
|
||||
|
||||
/*
|
||||
AddTimer(1.0f, () => GiveKnifeToPlayer(player));
|
||||
*/
|
||||
}
|
||||
|
||||
if (weaponSync != null)
|
||||
Task.Run(() => weaponSync.SyncKnifeToDatabase((int)player.Index, knifeKey));
|
||||
Task.Run(async () => await weaponSync.SyncKnifeToDatabase(playerInfo, knifeKey));
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -86,16 +147,15 @@ namespace WeaponPaints
|
||||
if (!Utility.IsPlayerValid(player) || !g_bCommandsAllowed) return;
|
||||
int playerIndex = (int)player!.Index;
|
||||
|
||||
if (commandCooldown != null && DateTime.UtcNow >= commandCooldown[playerIndex].AddSeconds(Config.CmdRefreshCooldownSeconds) && playerIndex > 0 && playerIndex < commandCooldown.Length)
|
||||
if (commandCooldown != null && DateTime.UtcNow >= commandCooldown[playerIndex].AddSeconds(Config.CmdRefreshCooldownSeconds))
|
||||
{
|
||||
commandCooldown[playerIndex] = DateTime.UtcNow;
|
||||
ChatMenus.OpenMenu(player, giveItemMenu);
|
||||
return;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(Config.Messages.CooldownRefreshCommand))
|
||||
if (!string.IsNullOrEmpty(Localizer["wp_command_cooldown"]))
|
||||
{
|
||||
string temp = $" {Config.Prefix} {Config.Messages.CooldownRefreshCommand}";
|
||||
player.PrintToChat(Utility.ReplaceTags(temp));
|
||||
player!.Print(Localizer["wp_command_cooldown"]);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -103,7 +163,7 @@ namespace WeaponPaints
|
||||
private void SetupSkinsMenu()
|
||||
{
|
||||
var classNamesByWeapon = weaponList.ToDictionary(kvp => kvp.Value, kvp => kvp.Key);
|
||||
var weaponSelectionMenu = new ChatMenu(Utility.ReplaceTags($" {Config.Messages.WeaponMenuTitle}"));
|
||||
var weaponSelectionMenu = new ChatMenu(Localizer["wp_skin_menu_weapon_title"]);
|
||||
|
||||
// Function to handle skin selection for a specific weapon
|
||||
var handleWeaponSelection = (CCSPlayerController? player, ChatMenuOption option) =>
|
||||
@@ -121,7 +181,7 @@ namespace WeaponPaints
|
||||
weaponName?.ToString() == selectedWeaponClassname
|
||||
)?.ToList();
|
||||
|
||||
var skinSubMenu = new ChatMenu(Utility.ReplaceTags($" {Config.Messages.SkinMenuTitle}").Replace("{WEAPON}", selectedWeapon));
|
||||
var skinSubMenu = new ChatMenu(Localizer["wp_skin_menu_skin_title", selectedWeapon]);
|
||||
|
||||
// Function to handle skin selection for the chosen weapon
|
||||
var handleSkinSelection = (CCSPlayerController? p, ChatMenuOption opt) =>
|
||||
@@ -130,7 +190,9 @@ namespace WeaponPaints
|
||||
|
||||
playerIndex = (int)p.Index;
|
||||
|
||||
var steamId = new SteamID(p.SteamID);
|
||||
if (p.AuthorizedSteamID == null) return;
|
||||
|
||||
string steamId = p.AuthorizedSteamID.SteamId64.ToString();
|
||||
var firstSkin = skinsList?.FirstOrDefault(skin =>
|
||||
{
|
||||
if (skin != null && skin.TryGetValue("weapon_name", out var weaponName))
|
||||
@@ -148,8 +210,7 @@ namespace WeaponPaints
|
||||
int.TryParse(weaponDefIndexObj.ToString(), out var weaponDefIndex) &&
|
||||
int.TryParse(selectedPaintID, out var paintID))
|
||||
{
|
||||
string temp = $" {Config.Prefix} {Config.Messages.ChosenSkinMenu}".Replace("{SKIN}", selectedSkin);
|
||||
p.PrintToChat(Utility.ReplaceTags(temp));
|
||||
p!.Print(Localizer["f", selectedSkin]);
|
||||
|
||||
if (!gPlayerWeaponsInfo[playerIndex].ContainsKey(weaponDefIndex))
|
||||
{
|
||||
@@ -157,16 +218,22 @@ namespace WeaponPaints
|
||||
}
|
||||
|
||||
gPlayerWeaponsInfo[playerIndex][weaponDefIndex].Paint = paintID;
|
||||
gPlayerWeaponsInfo[playerIndex][weaponDefIndex].Wear = 0.0f;
|
||||
gPlayerWeaponsInfo[playerIndex][weaponDefIndex].Wear = 0.01f;
|
||||
gPlayerWeaponsInfo[playerIndex][weaponDefIndex].Seed = 0;
|
||||
|
||||
PlayerInfo playerInfo = new PlayerInfo
|
||||
{
|
||||
UserId = player.UserId,
|
||||
Index = (int)player.Index,
|
||||
SteamId = player?.AuthorizedSteamID?.SteamId64.ToString(),
|
||||
Name = player?.PlayerName,
|
||||
IpAddress = player?.IpAddress?.Split(":")[0]
|
||||
};
|
||||
|
||||
if (!Config.GlobalShare)
|
||||
{
|
||||
if (weaponSync == null) return;
|
||||
Task.Run(async () =>
|
||||
{
|
||||
await weaponSync.SyncWeaponPaintsToDatabase(p);
|
||||
});
|
||||
if (weaponSync != null)
|
||||
Task.Run(async () => await weaponSync.SyncWeaponPaintsToDatabase(playerInfo));
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -212,81 +279,11 @@ namespace WeaponPaints
|
||||
ChatMenus.OpenMenu(player, weaponSelectionMenu);
|
||||
return;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(Config.Messages.CooldownRefreshCommand))
|
||||
if (!string.IsNullOrEmpty(Localizer["wp_command_cooldown"]))
|
||||
{
|
||||
string temp = $"{Config.Prefix} {Config.Messages.CooldownRefreshCommand}";
|
||||
player.PrintToChat(Utility.ReplaceTags(temp));
|
||||
player!.Print(Localizer["wp_command_cooldown"]);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
private void OnCommandRefresh(CCSPlayerController? player, CommandInfo command)
|
||||
{
|
||||
if (!Config.Additional.CommandWpEnabled || !Config.Additional.SkinEnabled || !g_bCommandsAllowed) return;
|
||||
if (!Utility.IsPlayerValid(player)) return;
|
||||
string temp = "";
|
||||
if (player == null || player.Index <= 0) return;
|
||||
int playerIndex = (int)player!.Index;
|
||||
if (playerIndex != 0 && DateTime.UtcNow >= commandCooldown[playerIndex].AddSeconds(Config.CmdRefreshCooldownSeconds))
|
||||
{
|
||||
commandCooldown[playerIndex] = DateTime.UtcNow;
|
||||
if (weaponSync != null)
|
||||
Task.Run(async () => await weaponSync.GetWeaponPaintsFromDatabase(playerIndex));
|
||||
if (Config.Additional.KnifeEnabled)
|
||||
{
|
||||
/*if (PlayerHasKnife(player))
|
||||
RefreshPlayerKnife(player);
|
||||
/*
|
||||
AddTimer(1.0f, () =>
|
||||
{
|
||||
GiveKnifeToPlayer(player);
|
||||
});
|
||||
*/
|
||||
if (weaponSync != null)
|
||||
Task.Run(async () => await weaponSync.GetKnifeFromDatabase(playerIndex));
|
||||
/*
|
||||
RemoveKnifeFromPlayer(player);
|
||||
AddTimer(0.2f, () => GiveKnifeToPlayer(player));
|
||||
*/
|
||||
|
||||
RefreshWeapons(player);
|
||||
}
|
||||
if (!string.IsNullOrEmpty(Config.Messages.SuccessRefreshCommand))
|
||||
{
|
||||
temp = $" {Config.Prefix} {Config.Messages.SuccessRefreshCommand}";
|
||||
player.PrintToChat(Utility.ReplaceTags(temp));
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(Config.Messages.CooldownRefreshCommand))
|
||||
{
|
||||
temp = $" {Config.Prefix} {Config.Messages.CooldownRefreshCommand}";
|
||||
player.PrintToChat(Utility.ReplaceTags(temp));
|
||||
}
|
||||
}
|
||||
private void OnCommandWS(CCSPlayerController? player, CommandInfo command)
|
||||
{
|
||||
if (!Config.Additional.SkinEnabled) return;
|
||||
if (!Utility.IsPlayerValid(player)) return;
|
||||
|
||||
string temp;
|
||||
if (!string.IsNullOrEmpty(Config.Messages.WebsiteMessageCommand))
|
||||
{
|
||||
temp = $" {Config.Prefix} {Config.Messages.WebsiteMessageCommand}";
|
||||
player!.PrintToChat(Utility.ReplaceTags(temp));
|
||||
}
|
||||
if (!string.IsNullOrEmpty(Config.Messages.SynchronizeMessageCommand))
|
||||
{
|
||||
temp = $" {Config.Prefix} {Config.Messages.SynchronizeMessageCommand}";
|
||||
player!.PrintToChat(Utility.ReplaceTags(temp));
|
||||
}
|
||||
if (!Config.Additional.KnifeEnabled) return;
|
||||
if (!string.IsNullOrEmpty(Config.Messages.KnifeMessageCommand))
|
||||
{
|
||||
temp = $" {Config.Prefix} {Config.Messages.KnifeMessageCommand}";
|
||||
player!.PrintToChat(Utility.ReplaceTags(temp));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
31
Config.cs
31
Config.cs
@@ -3,32 +3,6 @@ using System.Text.Json.Serialization;
|
||||
|
||||
namespace WeaponPaints
|
||||
{
|
||||
public class Messages
|
||||
{
|
||||
[JsonPropertyName("WebsiteMessageCommand")]
|
||||
public string WebsiteMessageCommand { get; set; } = "Visit {WEBSITE} where you can change skins.";
|
||||
[JsonPropertyName("SynchronizeMessageCommand")]
|
||||
public string SynchronizeMessageCommand { get; set; } = "Type !wp to synchronize chosen skins.";
|
||||
[JsonPropertyName("KnifeMessageCommand")]
|
||||
public string KnifeMessageCommand { get; set; } = "Type !knife to open knife menu.";
|
||||
[JsonPropertyName("CooldownRefreshCommand")]
|
||||
public string CooldownRefreshCommand { get; set; } = "You can't refresh weapon paints right now.";
|
||||
[JsonPropertyName("SuccessRefreshCommand")]
|
||||
public string SuccessRefreshCommand { get; set; } = "Refreshing weapon paints.";
|
||||
[JsonPropertyName("ChosenKnifeMenu")]
|
||||
public string ChosenKnifeMenu { get; set; } = "You have chosen {KNIFE} as your knife.";
|
||||
[JsonPropertyName("ChosenSkinMenu")]
|
||||
public string ChosenSkinMenu { get; set; } = "You have chosen {SKIN} as your skin.";
|
||||
[JsonPropertyName("ChosenKnifeMenuKill")]
|
||||
public string ChosenKnifeMenuKill { get; set; } = "To correctly apply skin for knife, you need to type !kill.";
|
||||
[JsonPropertyName("KnifeMenuTitle")]
|
||||
public string KnifeMenuTitle { get; set; } = "Knife Menu.";
|
||||
[JsonPropertyName("WeaponMenuTitle")]
|
||||
public string WeaponMenuTitle { get; set; } = "Weapon Menu.";
|
||||
[JsonPropertyName("SkinMenuTitle")]
|
||||
public string SkinMenuTitle { get; set; } = "Select skin for {WEAPON}";
|
||||
}
|
||||
|
||||
public class Additional
|
||||
{
|
||||
[JsonPropertyName("SkinVisibilityFix")]
|
||||
@@ -66,6 +40,8 @@ namespace WeaponPaints
|
||||
|
||||
[JsonPropertyName("GiveRandomSkin")]
|
||||
public bool GiveRandomSkin { get; set; } = false;
|
||||
[JsonPropertyName("GiveKnifeAfterRemove")]
|
||||
public bool GiveKnifeAfterRemove { get; set; } = false;
|
||||
}
|
||||
|
||||
public class WeaponPaintsConfig : BasePluginConfig
|
||||
@@ -99,9 +75,6 @@ namespace WeaponPaints
|
||||
[JsonPropertyName("Website")]
|
||||
public string Website { get; set; } = "example.com/skins";
|
||||
|
||||
[JsonPropertyName("Messages")]
|
||||
public Messages Messages { get; set; } = new Messages();
|
||||
|
||||
[JsonPropertyName("Additional")]
|
||||
public Additional Additional { get; set; } = new Additional();
|
||||
}
|
||||
|
||||
463
Events.cs
463
Events.cs
@@ -6,20 +6,284 @@ namespace WeaponPaints
|
||||
{
|
||||
public partial class WeaponPaints
|
||||
{
|
||||
private void RegisterEvents()
|
||||
private void OnClientAuthorized(int playerSlot, SteamID steamID)
|
||||
{
|
||||
RegisterListener<Listeners.OnEntitySpawned>(OnEntitySpawned);
|
||||
int playerIndex = playerSlot + 1;
|
||||
|
||||
CCSPlayerController? player = Utilities.GetPlayerFromIndex(playerIndex);
|
||||
|
||||
PlayerInfo playerInfo = new PlayerInfo
|
||||
{
|
||||
UserId = player.UserId,
|
||||
Index = (int)player.Index,
|
||||
SteamId = player?.AuthorizedSteamID?.SteamId64.ToString(),
|
||||
Name = player?.PlayerName,
|
||||
IpAddress = player?.IpAddress?.Split(":")[0]
|
||||
};
|
||||
|
||||
if (player == null || !player.IsValid || player.IsBot || player.IsHLTV || weaponSync == null) return;
|
||||
|
||||
Task.Run(async () =>
|
||||
{
|
||||
if (Config.Additional.SkinEnabled)
|
||||
await weaponSync.GetKnifeFromDatabase(playerInfo);
|
||||
});
|
||||
|
||||
//if (Config.Additional.KnifeEnabled && weaponSync != null)
|
||||
//_ = weaponSync.GetKnifeFromDatabase(playerIndex);
|
||||
}
|
||||
|
||||
private void OnClientDisconnect(int playerSlot)
|
||||
{
|
||||
CCSPlayerController player = Utilities.GetPlayerFromSlot(playerSlot);
|
||||
|
||||
if (player == null || !player.IsValid || player.IsBot || player.IsHLTV) return;
|
||||
|
||||
if (Config.Additional.KnifeEnabled)
|
||||
g_playersKnife.Remove((int)player.Index);
|
||||
if (Config.Additional.SkinEnabled)
|
||||
gPlayerWeaponsInfo.Remove((int)player.Index);
|
||||
}
|
||||
|
||||
private void OnEntityCreated(CEntityInstance entity)
|
||||
{
|
||||
if (!Config.Additional.SkinEnabled) return;
|
||||
var designerName = entity.DesignerName;
|
||||
if (!weaponList.ContainsKey(designerName)) return;
|
||||
bool isKnife = false;
|
||||
var weapon = new CBasePlayerWeapon(entity.Handle);
|
||||
|
||||
if (designerName.Contains("knife") || designerName.Contains("bayonet"))
|
||||
{
|
||||
isKnife = true;
|
||||
}
|
||||
|
||||
Server.NextFrame(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!weapon.IsValid) return;
|
||||
if (weapon.OwnerEntity.Value == null) return;
|
||||
if (weapon.OwnerEntity.Index <= 0) return;
|
||||
int weaponOwner = (int)weapon.OwnerEntity.Index;
|
||||
var pawn = new CBasePlayerPawn(NativeAPI.GetEntityFromIndex(weaponOwner));
|
||||
if (!pawn.IsValid) return;
|
||||
|
||||
var playerIndex = (int)pawn.Controller.Index;
|
||||
var player = Utilities.GetPlayerFromIndex(playerIndex);
|
||||
if (!Utility.IsPlayerValid(player)) return;
|
||||
|
||||
ChangeWeaponAttributes(weapon, player, isKnife);
|
||||
}
|
||||
catch (Exception) { }
|
||||
});
|
||||
}
|
||||
|
||||
private HookResult OnEventItemPurchasePost(EventItemPurchase @event, GameEventInfo info)
|
||||
{
|
||||
CCSPlayerController? player = @event.Userid;
|
||||
|
||||
if (player == null || !player.IsValid) return HookResult.Continue;
|
||||
|
||||
if (Config.Additional.SkinVisibilityFix)
|
||||
AddTimer(0.2f, () => RefreshSkins(player));
|
||||
|
||||
return HookResult.Continue;
|
||||
}
|
||||
|
||||
private HookResult OnItemPickup(EventItemPickup @event, GameEventInfo info)
|
||||
{
|
||||
if (@event.Defindex == 42 || @event.Defindex == 59)
|
||||
{
|
||||
Server.PrintToChatAll("test1");
|
||||
|
||||
CCSPlayerController? player = @event.Userid;
|
||||
if (player == null || !player.IsValid || !g_knifePickupCount.ContainsKey((int)player.Index) || player.IsBot || !g_playersKnife.ContainsKey((int)player.Index))
|
||||
return HookResult.Continue;
|
||||
|
||||
Server.PrintToChatAll("test2");
|
||||
|
||||
|
||||
if (g_knifePickupCount[(int)player.Index] >= 2) return HookResult.Continue;
|
||||
Server.PrintToChatAll("test3");
|
||||
|
||||
|
||||
if (g_playersKnife.ContainsKey((int)player.Index)
|
||||
&&
|
||||
g_playersKnife[(int)player.Index] != "weapon_knife")
|
||||
{
|
||||
Server.PrintToChatAll("usuwam noz");
|
||||
g_knifePickupCount[(int)player.Index]++;
|
||||
|
||||
RemovePlayerKnife(player, true);
|
||||
|
||||
if (!PlayerHasKnife(player) && Config.Additional.GiveKnifeAfterRemove)
|
||||
AddTimer(0.3f, () => GiveKnifeToPlayer(player));
|
||||
}
|
||||
}
|
||||
return HookResult.Continue;
|
||||
}
|
||||
|
||||
public HookResult OnPickup(CEntityIOOutput output, string name, CEntityInstance activator, CEntityInstance caller, CVariant value, float delay)
|
||||
{
|
||||
CCSPlayerController? player = Utilities.GetEntityFromIndex<CCSPlayerPawn>((int)activator.Index).OriginalController.Value;
|
||||
|
||||
if (player == null || player.IsBot || player.IsHLTV)
|
||||
return HookResult.Continue;
|
||||
|
||||
if (player == null || !player.IsValid || player.AuthorizedSteamID == null ||
|
||||
!g_knifePickupCount.ContainsKey((int)player.Index) || !g_playersKnife.ContainsKey((int)player.Index))
|
||||
return HookResult.Continue;
|
||||
|
||||
CBasePlayerWeapon weapon = new(caller.Handle);
|
||||
|
||||
if (weapon.AttributeManager.Item.ItemDefinitionIndex != 42 && weapon.AttributeManager.Item.ItemDefinitionIndex != 59)
|
||||
return HookResult.Continue;
|
||||
|
||||
if (g_knifePickupCount[(int)player.Index] >= 2) return HookResult.Continue;
|
||||
|
||||
if (g_playersKnife[(int)player.Index] != "weapon_knife")
|
||||
{
|
||||
g_knifePickupCount[(int)player.Index]++;
|
||||
weapon.Remove();
|
||||
if (!PlayerHasKnife(player) && Config.Additional.GiveKnifeAfterRemove)
|
||||
AddTimer(0.2f, () => GiveKnifeToPlayer(player));
|
||||
}
|
||||
|
||||
return HookResult.Continue;
|
||||
}
|
||||
|
||||
|
||||
private void OnMapStart(string mapName)
|
||||
{
|
||||
if (!Config.Additional.KnifeEnabled) return;
|
||||
// TODO
|
||||
// needed for now
|
||||
AddTimer(2.0f, () =>
|
||||
{
|
||||
|
||||
NativeAPI.IssueServerCommand("mp_t_default_melee \"\"");
|
||||
NativeAPI.IssueServerCommand("mp_ct_default_melee \"\"");
|
||||
NativeAPI.IssueServerCommand("mp_equipment_reset_rounds 0");
|
||||
|
||||
if (Config.GlobalShare)
|
||||
GlobalShareConnect();
|
||||
|
||||
weaponSync = new WeaponSynchronization(DatabaseConnectionString, Config, GlobalShareApi, GlobalShareServerId);
|
||||
});
|
||||
|
||||
g_hTimerCheckSkinsData = AddTimer(10.0f, () =>
|
||||
{
|
||||
List<CCSPlayerController> players = Utilities.GetPlayers();
|
||||
|
||||
foreach (CCSPlayerController player in players)
|
||||
{
|
||||
if (player.IsBot || player.IsHLTV || player.AuthorizedSteamID == null) continue;
|
||||
if (gPlayerWeaponsInfo.ContainsKey((int)player.Index)) continue;
|
||||
|
||||
PlayerInfo playerInfo = new PlayerInfo
|
||||
{
|
||||
UserId = player.UserId,
|
||||
Index = (int)player.Index,
|
||||
SteamId = player?.AuthorizedSteamID?.SteamId64.ToString(),
|
||||
Name = player?.PlayerName,
|
||||
IpAddress = player?.IpAddress?.Split(":")[0]
|
||||
};
|
||||
|
||||
if (Config.Additional.SkinEnabled && weaponSync != null)
|
||||
_ = weaponSync.GetWeaponPaintsFromDatabase(playerInfo);
|
||||
if (Config.Additional.KnifeEnabled && weaponSync != null)
|
||||
_ = weaponSync.GetKnifeFromDatabase(playerInfo);
|
||||
}
|
||||
}, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE | CounterStrikeSharp.API.Modules.Timers.TimerFlags.REPEAT);
|
||||
}
|
||||
|
||||
private HookResult OnPlayerConnectFull(EventPlayerConnectFull @event, GameEventInfo info)
|
||||
{
|
||||
CCSPlayerController? player = @event.Userid;
|
||||
|
||||
if (player == null || !player.IsValid || player.IsBot || player.IsHLTV || weaponSync == null) return HookResult.Continue;
|
||||
|
||||
PlayerInfo playerInfo = new PlayerInfo
|
||||
{
|
||||
UserId = player.UserId,
|
||||
Index = (int)player.Index,
|
||||
SteamId = player?.AuthorizedSteamID?.SteamId64.ToString(),
|
||||
Name = player?.PlayerName,
|
||||
IpAddress = player?.IpAddress?.Split(":")[0]
|
||||
};
|
||||
|
||||
if (!gPlayerWeaponsInfo.ContainsKey((int)player!.Index))
|
||||
{
|
||||
Console.WriteLine($"[WeaponPaints] Retrying to retrieve player {player.PlayerName} skins");
|
||||
Task.Run(async () =>
|
||||
{
|
||||
if (Config.Additional.SkinEnabled)
|
||||
await weaponSync.GetWeaponPaintsFromDatabase(playerInfo);
|
||||
if (Config.Additional.KnifeEnabled)
|
||||
await weaponSync.GetKnifeFromDatabase(playerInfo);
|
||||
});
|
||||
}
|
||||
|
||||
return HookResult.Continue;
|
||||
}
|
||||
|
||||
private HookResult OnPlayerSpawn(EventPlayerSpawn @event, GameEventInfo info)
|
||||
{
|
||||
CCSPlayerController? player = @event.Userid;
|
||||
if (player == null || !player.IsValid || player.IsBot)
|
||||
{
|
||||
return HookResult.Continue;
|
||||
}
|
||||
|
||||
if (Config.Additional.KnifeEnabled)
|
||||
{
|
||||
g_knifePickupCount[(int)player.Index] = 0;
|
||||
AddTimer(0.1f, () => GiveKnifeToPlayer(player));
|
||||
}
|
||||
|
||||
if (Config.Additional.SkinVisibilityFix)
|
||||
{
|
||||
AddTimer(0.3f, () => RefreshSkins(player));
|
||||
}
|
||||
|
||||
return HookResult.Continue;
|
||||
}
|
||||
|
||||
private HookResult OnRoundEnd(EventRoundEnd @event, GameEventInfo info)
|
||||
{
|
||||
g_bCommandsAllowed = false;
|
||||
return HookResult.Continue;
|
||||
}
|
||||
|
||||
private HookResult OnRoundStart(EventRoundStart @event, GameEventInfo info)
|
||||
{
|
||||
NativeAPI.IssueServerCommand("mp_t_default_melee \"\"");
|
||||
NativeAPI.IssueServerCommand("mp_ct_default_melee \"\"");
|
||||
NativeAPI.IssueServerCommand("mp_equipment_reset_rounds 0");
|
||||
|
||||
g_bCommandsAllowed = true;
|
||||
|
||||
return HookResult.Continue;
|
||||
}
|
||||
|
||||
private void RegisterListeners()
|
||||
{
|
||||
RegisterListener<Listeners.OnEntityCreated>(OnEntityCreated);
|
||||
RegisterListener<Listeners.OnClientAuthorized>(OnClientAuthorized);
|
||||
RegisterListener<Listeners.OnClientDisconnect>(OnClientDisconnect);
|
||||
RegisterListener<Listeners.OnMapStart>(OnMapStart);
|
||||
//RegisterEventHandler<EventPlayerConnectFull>(OnPlayerConnectFull);
|
||||
|
||||
RegisterEventHandler<EventPlayerConnectFull>(OnPlayerConnectFull);
|
||||
RegisterEventHandler<EventPlayerSpawn>(OnPlayerSpawn);
|
||||
RegisterEventHandler<EventRoundStart>(OnRoundStart, HookMode.Pre);
|
||||
RegisterEventHandler<EventRoundEnd>(OnRoundEnd);
|
||||
RegisterEventHandler<EventItemPurchase>(OnEventItemPurchasePost);
|
||||
RegisterEventHandler<EventItemPickup>(OnItemPickup);
|
||||
//RegisterEventHandler<EventItemPickup>(OnItemPickup);
|
||||
HookEntityOutput("weapon_knife", "OnPlayerPickup", OnPickup, HookMode.Pre);
|
||||
}
|
||||
|
||||
/* WORKAROUND FOR CLIENTS WITHOUT STEAMID ON AUTHORIZATION */
|
||||
/*private HookResult OnPlayerConnectFull(EventPlayerConnectFull @event, GameEventInfo info)
|
||||
{
|
||||
CCSPlayerController? player = @event.Userid;
|
||||
@@ -41,194 +305,5 @@ namespace WeaponPaints
|
||||
return HookResult.Continue;
|
||||
}
|
||||
*/
|
||||
private void OnMapStart(string mapName)
|
||||
{
|
||||
if (!Config.Additional.KnifeEnabled) return;
|
||||
// TODO
|
||||
// needed for now
|
||||
AddTimer(2.0f, () =>
|
||||
{
|
||||
NativeAPI.IssueServerCommand("mp_t_default_melee \"\"");
|
||||
NativeAPI.IssueServerCommand("mp_ct_default_melee \"\"");
|
||||
NativeAPI.IssueServerCommand("mp_equipment_reset_rounds 0");
|
||||
|
||||
if (Config.GlobalShare)
|
||||
GlobalShareConnect();
|
||||
});
|
||||
}
|
||||
|
||||
private void OnClientAuthorized(int playerSlot, SteamID steamID)
|
||||
{
|
||||
int playerIndex = playerSlot + 1;
|
||||
|
||||
CCSPlayerController? player = Utilities.GetPlayerFromIndex(playerIndex);
|
||||
|
||||
if (player == null || !player.IsValid || player.IsHLTV) return;
|
||||
|
||||
if (Config.Additional.SkinEnabled && weaponSync != null)
|
||||
_ = weaponSync.GetWeaponPaintsFromDatabase(playerIndex);
|
||||
if (Config.Additional.KnifeEnabled && weaponSync != null)
|
||||
_ = weaponSync.GetKnifeFromDatabase(playerIndex);
|
||||
|
||||
/*
|
||||
Task.Run(async () =>
|
||||
{
|
||||
if (Config.Additional.SkinEnabled && weaponSync != null)
|
||||
await weaponSync.GetWeaponPaintsFromDatabase(playerIndex);
|
||||
if (Config.Additional.KnifeEnabled && weaponSync != null)
|
||||
await weaponSync.GetKnifeFromDatabase(playerIndex);
|
||||
});
|
||||
*/
|
||||
}
|
||||
|
||||
private void OnClientDisconnect(int playerSlot)
|
||||
{
|
||||
CCSPlayerController player = Utilities.GetPlayerFromSlot(playerSlot);
|
||||
|
||||
if (player == null || !player.IsValid || player.IsHLTV) return;
|
||||
|
||||
if (Config.Additional.KnifeEnabled)
|
||||
g_playersKnife.Remove((int)player.Index);
|
||||
if (Config.Additional.SkinEnabled)
|
||||
gPlayerWeaponsInfo.Remove((int)player.Index);
|
||||
}
|
||||
|
||||
private HookResult OnPlayerSpawn(EventPlayerSpawn @event, GameEventInfo info)
|
||||
{
|
||||
CCSPlayerController? player = @event.Userid;
|
||||
if (player == null || !player.IsValid || !player.PlayerPawn.IsValid)
|
||||
{
|
||||
return HookResult.Continue;
|
||||
}
|
||||
|
||||
if (Config.Additional.KnifeEnabled)
|
||||
{
|
||||
g_knifePickupCount[(int)player.Index] = 0;
|
||||
if (!PlayerHasKnife(player))
|
||||
GiveKnifeToPlayer(player);
|
||||
}
|
||||
|
||||
if (Config.Additional.SkinVisibilityFix)
|
||||
{
|
||||
AddTimer(0.3f, () => RefreshSkins(player));
|
||||
}
|
||||
|
||||
return HookResult.Continue;
|
||||
}
|
||||
private HookResult OnRoundStart(EventRoundStart @event, GameEventInfo info)
|
||||
{
|
||||
NativeAPI.IssueServerCommand("mp_t_default_melee \"\"");
|
||||
NativeAPI.IssueServerCommand("mp_ct_default_melee \"\"");
|
||||
NativeAPI.IssueServerCommand("mp_equipment_reset_rounds 0");
|
||||
|
||||
g_bCommandsAllowed = true;
|
||||
|
||||
return HookResult.Continue;
|
||||
}
|
||||
|
||||
private HookResult OnRoundEnd(EventRoundEnd @event, GameEventInfo info)
|
||||
{
|
||||
g_bCommandsAllowed = false;
|
||||
return HookResult.Continue;
|
||||
}
|
||||
|
||||
private HookResult OnItemPickup(EventItemPickup @event, GameEventInfo info)
|
||||
{
|
||||
if (@event.Defindex == 42 || @event.Defindex == 59)
|
||||
{
|
||||
CCSPlayerController? player = @event.Userid;
|
||||
if (!Utility.IsPlayerValid(player) || !player.PawnIsAlive || g_knifePickupCount[(int)player.Index] >= 2) return HookResult.Continue;
|
||||
|
||||
if (g_playersKnife.ContainsKey((int)player.Index)
|
||||
&&
|
||||
g_playersKnife[(int)player.Index] != "weapon_knife")
|
||||
{
|
||||
g_knifePickupCount[(int)player.Index]++;
|
||||
|
||||
RemovePlayerKnife(player, true);
|
||||
AddTimer(0.3f, ()=> GiveKnifeToPlayer(player));
|
||||
|
||||
//RefreshPlayerKnife(player);
|
||||
/*
|
||||
if (!PlayerHasKnife(player))
|
||||
GiveKnifeToPlayer(player);
|
||||
|
||||
if (Config.Additional.SkinVisibilityFix)
|
||||
{
|
||||
AddTimer(0.25f, () => RefreshSkins(player));
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
return HookResult.Continue;
|
||||
}
|
||||
|
||||
private void OnEntitySpawned(CEntityInstance entity)
|
||||
{
|
||||
if (!Config.Additional.SkinEnabled) return;
|
||||
var designerName = entity.DesignerName;
|
||||
if (!weaponList.ContainsKey(designerName)) return;
|
||||
bool isKnife = false;
|
||||
var weapon = new CBasePlayerWeapon(entity.Handle);
|
||||
|
||||
if (designerName.Contains("knife") || designerName.Contains("bayonet"))
|
||||
{
|
||||
isKnife = true;
|
||||
}
|
||||
Server.NextFrame(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
if (!weapon.IsValid) return;
|
||||
if (weapon.OwnerEntity.Value == null) return;
|
||||
/*
|
||||
if (weapon.OwnerEntity.Index > 0)
|
||||
{
|
||||
for (int i = 1; i <= Server.MaxPlayers; i++)
|
||||
{
|
||||
CCSPlayerController? ghostPlayer = Utilities.GetPlayerFromIndex(i);
|
||||
if (!Utility.IsPlayerValid(ghostPlayer)) continue;
|
||||
if (g_changedKnife.Contains((int)ghostPlayer.Index))
|
||||
{
|
||||
ChangeWeaponAttributes(weapon, ghostPlayer, isKnife);
|
||||
g_changedKnife.Remove((int)ghostPlayer.Index);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
if (weapon.OwnerEntity.Index <= 0) return;
|
||||
int weaponOwner = (int)weapon.OwnerEntity.Index;
|
||||
var pawn = new CBasePlayerPawn(NativeAPI.GetEntityFromIndex(weaponOwner));
|
||||
if (!pawn.IsValid) return;
|
||||
|
||||
var playerIndex = (int)pawn.Controller.Index;
|
||||
var player = Utilities.GetPlayerFromIndex(playerIndex);
|
||||
if (!Utility.IsPlayerValid(player)) return;
|
||||
|
||||
// TODO: Remove knife crashes here, needs another solution
|
||||
/*if (isKnife && g_playersKnife[(int)player.EntityIndex!.Value.Value] != "weapon_knife" && (weapon.AttributeManager.Item.ItemDefinitionIndex == 42 || weapon.AttributeManager.Item.ItemDefinitionIndex == 59))
|
||||
{
|
||||
RemoveKnifeFromPlayer(player);
|
||||
return;
|
||||
}*/
|
||||
ChangeWeaponAttributes(weapon, player, isKnife);
|
||||
}
|
||||
catch (Exception) { }
|
||||
});
|
||||
}
|
||||
private HookResult OnEventItemPurchasePost(EventItemPurchase @event, GameEventInfo info)
|
||||
{
|
||||
CCSPlayerController? player = @event.Userid;
|
||||
|
||||
if (player == null || !player.IsValid) return HookResult.Continue;
|
||||
|
||||
if (Config.Additional.SkinVisibilityFix)
|
||||
AddTimer(0.2f, () => RefreshSkins(player));
|
||||
|
||||
return HookResult.Continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
14
PlayerExtensions.cs
Normal file
14
PlayerExtensions.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using System.Text;
|
||||
|
||||
namespace WeaponPaints;
|
||||
|
||||
public static class PlayerExtensions
|
||||
{
|
||||
public static void Print(this CCSPlayerController controller, string message)
|
||||
{
|
||||
StringBuilder _message = new(WeaponPaints._localizer["wp_prefix"]);
|
||||
_message.Append(message);
|
||||
controller.PrintToChat(_message.ToString());
|
||||
}
|
||||
}
|
||||
11
PlayerInfo.cs
Normal file
11
PlayerInfo.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace WeaponPaints
|
||||
{
|
||||
public class PlayerInfo
|
||||
{
|
||||
public int Index { get; set; }
|
||||
public int? UserId { get; set; }
|
||||
public string? SteamId { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public string? IpAddress { get; set; }
|
||||
}
|
||||
}
|
||||
1
PluginServices.cs
Normal file
1
PluginServices.cs
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
11
README.md
11
README.md
@@ -24,7 +24,7 @@ Unfinished, unoptimized and not fully functional ugly demo weapon paints plugin
|
||||
|
||||
## Plugin Configuration
|
||||
<details>
|
||||
<summary>Spoiler warning</summary>
|
||||
<summary>Click to expand</summary>
|
||||
<code><pre>{
|
||||
"Version": 4, // Don't touch
|
||||
"DatabaseHost": "", // MySQL host (required if GlobalShare = false)
|
||||
@@ -43,8 +43,11 @@ Unfinished, unoptimized and not fully functional ugly demo weapon paints plugin
|
||||
"CooldownRefreshCommand": "You can\u0027t refresh weapon paints right now.", // Cooldown information (!wp command) Set to empty to disable
|
||||
"SuccessRefreshCommand": "Refreshing weapon paints.", // Information about refreshing skins (!wp command) Set to empty to disable
|
||||
"ChosenKnifeMenu": "You have chosen {KNIFE} as your knife.", // Information about choosen knife (!knife command) Set to empty to disable
|
||||
"ChosenSkinMenu": "You have chosen {SKIN} as your skin.", // Information about choosen skin (!skins command) Set to empty to disable
|
||||
"ChosenKnifeMenuKill": "To correctly apply skin for knife, you need to type !kill.", // Information about suicide after knife selection (!knife command) Set to empty to disable
|
||||
"KnifeMenuTitle": "Knife Menu." // Menu title (!knife menu)
|
||||
"KnifeMenuTitle": "Knife Menu.", // Menu title (!knife menu)
|
||||
"WeaponMenuTitle": "Weapon Menu.", // Menu title (!skins menu)
|
||||
"SkinMenuTitle": "Select skin for {WEAPON}" // Menu title (!skins menu, after weapon select)
|
||||
},
|
||||
"Additional": {
|
||||
"SkinVisibilityFix": true, // Enable or disable fix for skin visibility
|
||||
@@ -54,9 +57,11 @@ Unfinished, unoptimized and not fully functional ugly demo weapon paints plugin
|
||||
"CommandKillEnabled": true, // Enable or disable kill command
|
||||
"CommandKnife": "knife", // Name of knife menu command, u can change to for e.g, knives
|
||||
"CommandSkin": "ws", // Name of skin information command, u can change to for e.g, skins
|
||||
"CommandSkinSelection": "skins", // Name of skins menu command, u can change to for e.g, weapons
|
||||
"CommandRefresh": "wp", // Name of skin refreshing command, u can change to for e.g, refreshskins
|
||||
"CommandKill": "kill", // Name of kill command, u can change to for e.g, suicide
|
||||
"GiveRandomKnife": false // Give random knife to players if they didn't choose
|
||||
"GiveRandomKnife": false, // Give random knife to players if they didn't choose
|
||||
"GiveRandomSkins": false // Give random skins to players if they didn't choose
|
||||
},
|
||||
|
||||
"ConfigVersion": 4 // Don't touch
|
||||
|
||||
102
Utility.cs
102
Utility.cs
@@ -5,6 +5,7 @@ using MySqlConnector;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using System.Reflection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace WeaponPaints
|
||||
{
|
||||
@@ -12,11 +13,6 @@ namespace WeaponPaints
|
||||
{
|
||||
internal static WeaponPaintsConfig? Config { get; set; }
|
||||
|
||||
internal static bool IsPlayerValid(CCSPlayerController? player)
|
||||
{
|
||||
return (player != null && player.IsValid && !player.IsBot && !player.IsHLTV && player.SteamID.ToString() != "0");
|
||||
}
|
||||
|
||||
internal static string BuildDatabaseConnectionString()
|
||||
{
|
||||
if (Config == null) return string.Empty;
|
||||
@@ -32,25 +28,6 @@ namespace WeaponPaints
|
||||
return builder.ConnectionString;
|
||||
}
|
||||
|
||||
internal static void TestDatabaseConnection()
|
||||
{
|
||||
try
|
||||
{
|
||||
using var connection = new MySqlConnection(BuildDatabaseConnectionString());
|
||||
connection.Open();
|
||||
|
||||
if (connection.State != System.Data.ConnectionState.Open)
|
||||
{
|
||||
throw new Exception("[WeaponPaints] Unable connect to database!");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception("[WeaponPaints] Unknown mysql exception! " + ex.Message);
|
||||
}
|
||||
CheckDatabaseTables();
|
||||
}
|
||||
|
||||
internal static async void CheckDatabaseTables()
|
||||
{
|
||||
try
|
||||
@@ -62,7 +39,7 @@ namespace WeaponPaints
|
||||
|
||||
try
|
||||
{
|
||||
string createTable1 = "CREATE TABLE IF NOT EXISTS `wp_player_skins` (`steamid` varchar(64) NOT NULL, `weapon_defindex` int(6) NOT NULL, `weapon_paint_id` int(6) NOT NULL, `weapon_wear` float NOT NULL DEFAULT 0.0001, `weapon_seed` int(16) NOT NULL DEFAULT 0) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci";
|
||||
string createTable1 = "CREATE TABLE IF NOT EXISTS `wp_player_skins` (`steamid` varchar(64) NOT NULL, `weapon_defindex` int(6) NOT NULL, `weapon_paint_id` int(6) NOT NULL, `weapon_wear` float NOT NULL DEFAULT 0.000001, `weapon_seed` int(16) NOT NULL DEFAULT 0) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci";
|
||||
string createTable2 = "CREATE TABLE IF NOT EXISTS `wp_player_knife` (`steamid` varchar(64) NOT NULL, `knife` varchar(64) NOT NULL, UNIQUE (`steamid`)) ENGINE = InnoDB";
|
||||
|
||||
await connection.ExecuteAsync(createTable1, transaction: transaction);
|
||||
@@ -81,6 +58,11 @@ namespace WeaponPaints
|
||||
throw new Exception("[WeaponPaints] Unknown mysql exception! " + ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
internal static bool IsPlayerValid(CCSPlayerController? player)
|
||||
{
|
||||
return (player != null && player.IsValid && !player.IsBot && !player.IsHLTV && player.AuthorizedSteamID != null);
|
||||
}
|
||||
internal static void LoadSkinsFromFile(string filePath)
|
||||
{
|
||||
if (File.Exists(filePath))
|
||||
@@ -95,6 +77,14 @@ namespace WeaponPaints
|
||||
}
|
||||
}
|
||||
|
||||
internal static void Log(string message)
|
||||
{
|
||||
Console.BackgroundColor = ConsoleColor.DarkGray;
|
||||
Console.ForegroundColor = ConsoleColor.Cyan;
|
||||
Console.WriteLine("[WeaponPaints] " + message);
|
||||
Console.ResetColor();
|
||||
}
|
||||
|
||||
internal static string ReplaceTags(string message)
|
||||
{
|
||||
if (message.Contains('{'))
|
||||
@@ -118,13 +108,46 @@ namespace WeaponPaints
|
||||
return message;
|
||||
}
|
||||
|
||||
internal static void Log(string message)
|
||||
internal static async Task CheckVersion(string version, ILogger logger)
|
||||
{
|
||||
Console.BackgroundColor = ConsoleColor.DarkGray;
|
||||
Console.ForegroundColor = ConsoleColor.Cyan;
|
||||
Console.WriteLine("[WeaponPaints] " + message);
|
||||
Console.ResetColor();
|
||||
using (HttpClient client = new HttpClient())
|
||||
{
|
||||
try
|
||||
{
|
||||
HttpResponseMessage response = await client.GetAsync("https://raw.githubusercontent.com/Nereziel/cs2-WeaponPaints/main/VERSION");
|
||||
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
string remoteVersion = await response.Content.ReadAsStringAsync();
|
||||
remoteVersion = remoteVersion.Trim();
|
||||
|
||||
int comparisonResult = string.Compare(version, remoteVersion);
|
||||
|
||||
if (comparisonResult < 0)
|
||||
{
|
||||
logger.LogWarning("Plugin is outdated! Check https://github.com/Nereziel/cs2-WeaponPaints");
|
||||
}
|
||||
else if (comparisonResult > 0)
|
||||
{
|
||||
logger.LogInformation("Probably dev version detected");
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.LogInformation("Plugin is up to date");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.LogWarning("Failed to check version");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal static void ShowAd(string moduleVersion)
|
||||
{
|
||||
Console.WriteLine(" ");
|
||||
@@ -139,5 +162,24 @@ namespace WeaponPaints
|
||||
Console.WriteLine(" >> GitHub: https://github.com/Nereziel/cs2-WeaponPaints");
|
||||
Console.WriteLine(" ");
|
||||
}
|
||||
|
||||
internal static void TestDatabaseConnection()
|
||||
{
|
||||
try
|
||||
{
|
||||
using var connection = new MySqlConnection(BuildDatabaseConnectionString());
|
||||
connection.Open();
|
||||
|
||||
if (connection.State != System.Data.ConnectionState.Open)
|
||||
{
|
||||
throw new Exception("[WeaponPaints] Unable connect to database!");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception("[WeaponPaints] Unknown mysql exception! " + ex.Message);
|
||||
}
|
||||
CheckDatabaseTables();
|
||||
}
|
||||
}
|
||||
}
|
||||
138
WeaponAction.cs
138
WeaponAction.cs
@@ -2,6 +2,7 @@
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using CounterStrikeSharp.API.Modules.Memory;
|
||||
using CounterStrikeSharp.API.Modules.Utils;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace WeaponPaints
|
||||
{
|
||||
@@ -19,6 +20,11 @@ namespace WeaponPaints
|
||||
|
||||
int weaponDefIndex = weapon.AttributeManager.Item.ItemDefinitionIndex;
|
||||
|
||||
if (isKnife)
|
||||
{
|
||||
weapon.AttributeManager.Item.EntityQuality = 3;
|
||||
}
|
||||
|
||||
if (_config.Additional.GiveRandomSkin &&
|
||||
!gPlayerWeaponsInfo[playerIndex].ContainsKey(weaponDefIndex))
|
||||
{
|
||||
@@ -28,7 +34,7 @@ namespace WeaponPaints
|
||||
weapon.AttributeManager.Item.ItemIDHigh = weapon.AttributeManager.Item.ItemIDLow >> 32;
|
||||
weapon.FallbackPaintKit = GetRandomPaint(weaponDefIndex);
|
||||
weapon.FallbackSeed = 0;
|
||||
weapon.FallbackWear = 0.0f;
|
||||
weapon.FallbackWear = 0.000001f;
|
||||
if (!isKnife && weapon.CBodyComponent != null && weapon.CBodyComponent.SceneNode != null)
|
||||
{
|
||||
var skeleton = GetSkeletonInstance(weapon.CBodyComponent.SceneNode);
|
||||
@@ -52,6 +58,7 @@ namespace WeaponPaints
|
||||
skeleton.ModelState.MeshGroupMask = 2;
|
||||
}
|
||||
}
|
||||
|
||||
internal static void GiveKnifeToPlayer(CCSPlayerController? player)
|
||||
{
|
||||
if (!_config.Additional.KnifeEnabled || player == null || !player.IsValid) return;
|
||||
@@ -75,50 +82,32 @@ namespace WeaponPaints
|
||||
player.GiveNamedItem(defaultKnife);
|
||||
}
|
||||
}
|
||||
internal void RemovePlayerKnife(CCSPlayerController? player, bool force = false)
|
||||
|
||||
internal static bool PlayerHasKnife(CCSPlayerController? player)
|
||||
{
|
||||
if (player == null || !player.IsValid || player.PlayerPawn.Value == null || !player.PawnIsAlive) return;
|
||||
if (player.PlayerPawn.Value.WeaponServices == null || player.PlayerPawn.Value.ItemServices == null) return;
|
||||
if (!_config.Additional.KnifeEnabled) return false;
|
||||
|
||||
var weapons = player.PlayerPawn.Value.WeaponServices.MyWeapons;
|
||||
if (weapons != null && weapons.Count > 0)
|
||||
if (player == null || !player.IsValid || player.PlayerPawn == null || !player.PlayerPawn.IsValid || !player.PawnIsAlive)
|
||||
{
|
||||
CCSPlayer_ItemServices service = new CCSPlayer_ItemServices(player.PlayerPawn.Value.ItemServices.Handle);
|
||||
//var dropWeapon = VirtualFunction.CreateVoid<nint, nint>(service.Handle, GameData.GetOffset("CCSPlayer_ItemServices_DropActivePlayerWeapon"));
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (var weapon in weapons)
|
||||
if (player.PlayerPawn?.Value == null || player.PlayerPawn?.Value.WeaponServices == null || player.PlayerPawn?.Value.ItemServices == null)
|
||||
return false;
|
||||
|
||||
var weapons = player.PlayerPawn.Value.WeaponServices?.MyWeapons;
|
||||
if (weapons == null) return false;
|
||||
foreach (var weapon in weapons)
|
||||
{
|
||||
if (weapon != null && weapon.IsValid && weapon.Value != null && weapon.Value.IsValid)
|
||||
{
|
||||
if (weapon != null && weapon.IsValid && weapon.Value != null && weapon.Value.IsValid)
|
||||
if (weapon.Value.DesignerName.Contains("knife") || weapon.Value.DesignerName.Contains("bayonet"))
|
||||
{
|
||||
//if (weapon.Value.AttributeManager.Item.ItemDefinitionIndex == 42 || weapon.Value.AttributeManager.Item.ItemDefinitionIndex == 59)
|
||||
if (weapon.Value.DesignerName.Contains("knife") || weapon.Value.DesignerName.Contains("bayonet"))
|
||||
{
|
||||
if (!force)
|
||||
{
|
||||
if ((int)weapon.Index <= 0) return;
|
||||
int weaponEntityIndex = (int)weapon.Index;
|
||||
NativeAPI.IssueClientCommand((int)player.Index - 1, "slot3");
|
||||
AddTimer(0.35f, () => service.DropActivePlayerWeapon(weapon.Value));
|
||||
|
||||
AddTimer(1.0f, () =>
|
||||
{
|
||||
CEntityInstance? knife = Utilities.GetEntityFromIndex<CEntityInstance>(weaponEntityIndex);
|
||||
if (knife != null && knife.IsValid)
|
||||
{
|
||||
knife.Remove();
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
weapon.Value.Remove();
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
internal void RefreshPlayerKnife(CCSPlayerController? player)
|
||||
@@ -197,7 +186,6 @@ namespace WeaponPaints
|
||||
if (weapons != null && weapons.Count > 0)
|
||||
{
|
||||
CCSPlayer_ItemServices service = new(player.PlayerPawn.Value.ItemServices.Handle);
|
||||
//var dropWeapon = VirtualFunction.CreateVoid<nint, nint>(service.Handle, GameData.GetOffset("CCSPlayer_ItemServices_DropActivePlayerWeapon"));
|
||||
|
||||
foreach (var weapon in weapons)
|
||||
{
|
||||
@@ -214,13 +202,15 @@ namespace WeaponPaints
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!weaponDefindex.ContainsKey(weapon.Value.AttributeManager.Item.ItemDefinitionIndex)) continue;
|
||||
int clip1, reservedAmmo;
|
||||
|
||||
clip1 = weapon.Value.Clip1;
|
||||
reservedAmmo = weapon.Value.ReserveAmmo[0];
|
||||
|
||||
weapon.Value.Remove();
|
||||
CBasePlayerWeapon newWeapon = new(player.GiveNamedItem(weapon.Value.DesignerName));
|
||||
string weaponByDefindex = weaponDefindex[weapon.Value.AttributeManager.Item.ItemDefinitionIndex];
|
||||
CBasePlayerWeapon newWeapon = new(player.GiveNamedItem(weaponByDefindex));
|
||||
|
||||
Server.NextFrame(() =>
|
||||
{
|
||||
@@ -237,6 +227,7 @@ namespace WeaponPaints
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogWarning("Refreshing weapons exception");
|
||||
Console.WriteLine("[WeaponPaints] Refreshing weapons exception");
|
||||
Console.WriteLine(ex.Message);
|
||||
}
|
||||
@@ -247,45 +238,57 @@ namespace WeaponPaints
|
||||
}
|
||||
}
|
||||
|
||||
internal static bool PlayerHasKnife(CCSPlayerController? player)
|
||||
internal void RemovePlayerKnife(CCSPlayerController? player, bool force = false)
|
||||
{
|
||||
if (!_config.Additional.KnifeEnabled) return false;
|
||||
|
||||
if (player == null || !player.IsValid)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (player.PlayerPawn.Value == null || player.PlayerPawn.Value.WeaponServices == null || player.PlayerPawn.Value.ItemServices == null)
|
||||
return false;
|
||||
if (player == null || !player.IsValid || player.PlayerPawn.Value == null || !player.PawnIsAlive) return;
|
||||
if (player.PlayerPawn.Value.WeaponServices == null || player.PlayerPawn.Value.ItemServices == null) return;
|
||||
|
||||
var weapons = player.PlayerPawn.Value.WeaponServices.MyWeapons;
|
||||
if (weapons == null || weapons.Count <= 0) return false;
|
||||
foreach (var weapon in weapons)
|
||||
if (weapons != null && weapons.Count > 0)
|
||||
{
|
||||
if (weapon != null && weapon.IsValid && weapon.Value != null && weapon.Value.IsValid)
|
||||
CCSPlayer_ItemServices service = new CCSPlayer_ItemServices(player.PlayerPawn.Value.ItemServices.Handle);
|
||||
//var dropWeapon = VirtualFunction.CreateVoid<nint, nint>(service.Handle, GameData.GetOffset("CCSPlayer_ItemServices_DropActivePlayerWeapon"));
|
||||
|
||||
foreach (var weapon in weapons)
|
||||
{
|
||||
if (weapon.Value.DesignerName.Contains("knife") || weapon.Value.DesignerName.Contains("bayonet"))
|
||||
if (weapon != null && weapon.IsValid && weapon.Value != null && weapon.Value.IsValid)
|
||||
{
|
||||
return true;
|
||||
//if (weapon.Value.AttributeManager.Item.ItemDefinitionIndex == 42 || weapon.Value.AttributeManager.Item.ItemDefinitionIndex == 59)
|
||||
if (weapon.Value.DesignerName.Contains("knife") || weapon.Value.DesignerName.Contains("bayonet"))
|
||||
{
|
||||
if (!force)
|
||||
{
|
||||
if ((int)weapon.Index <= 0) return;
|
||||
int weaponEntityIndex = (int)weapon.Index;
|
||||
NativeAPI.IssueClientCommand((int)player.Index - 1, "slot3");
|
||||
AddTimer(0.35f, () => service.DropActivePlayerWeapon(weapon.Value));
|
||||
|
||||
AddTimer(1.0f, () =>
|
||||
{
|
||||
CEntityInstance? knife = Utilities.GetEntityFromIndex<CEntityInstance>(weaponEntityIndex);
|
||||
if (knife != null && knife.IsValid)
|
||||
{
|
||||
knife.Remove();
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
weapon.Value.Remove();
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static CSkeletonInstance GetSkeletonInstance(CGameSceneNode node)
|
||||
{
|
||||
Func<nint, nint> GetSkeletonInstance = VirtualFunction.Create<nint, nint>(node.Handle, 8);
|
||||
return new CSkeletonInstance(GetSkeletonInstance(node.Handle));
|
||||
}
|
||||
|
||||
private static int GetRandomPaint(int defindex)
|
||||
{
|
||||
Random rnd = new Random();
|
||||
|
||||
if (WeaponPaints.skinsList != null)
|
||||
if (skinsList != null)
|
||||
{
|
||||
Random rnd = new Random();
|
||||
// Filter weapons by the provided defindex
|
||||
var filteredWeapons = skinsList.FindAll(w => w["weapon_defindex"]?.ToString() == defindex.ToString());
|
||||
|
||||
@@ -300,10 +303,15 @@ namespace WeaponPaints
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static CSkeletonInstance GetSkeletonInstance(CGameSceneNode node)
|
||||
{
|
||||
Func<nint, nint> GetSkeletonInstance = VirtualFunction.Create<nint, nint>(node.Handle, 8);
|
||||
return new CSkeletonInstance(GetSkeletonInstance(node.Handle));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,4 +6,4 @@
|
||||
public int Seed { get; set; }
|
||||
public float Wear { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
176
WeaponPaints.cs
176
WeaponPaints.cs
@@ -3,38 +3,14 @@ using CounterStrikeSharp.API.Core;
|
||||
using CounterStrikeSharp.API.Core.Attributes;
|
||||
using CounterStrikeSharp.API.Modules.Cvars;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Localization;
|
||||
|
||||
namespace WeaponPaints;
|
||||
[MinimumApiVersion(82)]
|
||||
|
||||
[MinimumApiVersion(121)]
|
||||
public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
||||
{
|
||||
public override string ModuleName => "WeaponPaints";
|
||||
public override string ModuleDescription => "Skin and knife selector, standalone and web-based";
|
||||
public override string ModuleAuthor => "Nereziel & daffyy";
|
||||
public override string ModuleVersion => "1.3b";
|
||||
public WeaponPaintsConfig Config { get; set; } = new();
|
||||
internal static WeaponPaintsConfig _config = new WeaponPaintsConfig();
|
||||
|
||||
internal static WeaponSynchronization? weaponSync;
|
||||
|
||||
/*
|
||||
private Dictionary<int, Dictionary<int, int>> gPlayerWeaponPaints = new();
|
||||
private Dictionary<int, Dictionary<int, int>> gPlayerWeaponSeed = new();
|
||||
private Dictionary<int, Dictionary<int, float>> gPlayerWeaponWear = new();
|
||||
*/
|
||||
private string DatabaseConnectionString = string.Empty;
|
||||
|
||||
internal Uri GlobalShareApi = new Uri("https://weaponpaints.fun/api.php");
|
||||
internal int GlobalShareServerId = 0;
|
||||
|
||||
private DateTime[] commandCooldown = new DateTime[Server.MaxPlayers];
|
||||
internal static Dictionary<int, Dictionary<int, WeaponInfo>> gPlayerWeaponsInfo = new Dictionary<int, Dictionary<int, WeaponInfo>>();
|
||||
internal static Dictionary<int, int> g_knifePickupCount = new Dictionary<int, int>();
|
||||
internal static Dictionary<int, string> g_playersKnife = new();
|
||||
//internal static List<int> g_changedKnife = new();
|
||||
internal bool g_bCommandsAllowed = true;
|
||||
|
||||
internal static List<JObject> skinsList = new List<JObject>();
|
||||
internal static readonly Dictionary<string, string> weaponList = new()
|
||||
{
|
||||
{"weapon_deagle", "Desert Eagle"},
|
||||
@@ -93,6 +69,89 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
|
||||
{ "weapon_knife_skeleton", "Skeleton Knife" }
|
||||
};
|
||||
|
||||
internal static WeaponPaintsConfig _config = new WeaponPaintsConfig();
|
||||
internal static IStringLocalizer? _localizer;
|
||||
internal static Dictionary<int, int> g_knifePickupCount = new Dictionary<int, int>();
|
||||
internal static Dictionary<int, string> g_playersKnife = new();
|
||||
internal static Dictionary<int, Dictionary<int, WeaponInfo>> gPlayerWeaponsInfo = new Dictionary<int, Dictionary<int, WeaponInfo>>();
|
||||
internal static List<JObject> skinsList = new List<JObject>();
|
||||
internal static WeaponSynchronization? weaponSync;
|
||||
//internal static List<int> g_changedKnife = new();
|
||||
internal bool g_bCommandsAllowed = true;
|
||||
|
||||
internal Uri GlobalShareApi = new("https://weaponpaints.fun/api.php");
|
||||
internal int GlobalShareServerId = 0;
|
||||
private DateTime[] commandCooldown = new DateTime[Server.MaxPlayers];
|
||||
private string DatabaseConnectionString = string.Empty;
|
||||
private CounterStrikeSharp.API.Modules.Timers.Timer? g_hTimerCheckSkinsData = null;
|
||||
public static Dictionary<int, string> weaponDefindex { get; } = new Dictionary<int, string>
|
||||
{
|
||||
{ 1, "weapon_deagle" },
|
||||
{ 2, "weapon_elite" },
|
||||
{ 3, "weapon_fiveseven" },
|
||||
{ 4, "weapon_glock" },
|
||||
{ 7, "weapon_ak47" },
|
||||
{ 8, "weapon_aug" },
|
||||
{ 9, "weapon_awp" },
|
||||
{ 10, "weapon_famas" },
|
||||
{ 11, "weapon_g3sg1" },
|
||||
{ 13, "weapon_galilar" },
|
||||
{ 14, "weapon_m249" },
|
||||
{ 16, "weapon_m4a1" },
|
||||
{ 17, "weapon_mac10" },
|
||||
{ 19, "weapon_p90" },
|
||||
{ 23, "weapon_mp5sd" },
|
||||
{ 24, "weapon_ump45" },
|
||||
{ 25, "weapon_xm1014" },
|
||||
{ 26, "weapon_bizon" },
|
||||
{ 27, "weapon_mag7" },
|
||||
{ 28, "weapon_negev" },
|
||||
{ 29, "weapon_sawedoff" },
|
||||
{ 30, "weapon_tec9" },
|
||||
{ 32, "weapon_hkp2000" },
|
||||
{ 33, "weapon_mp7" },
|
||||
{ 34, "weapon_mp9" },
|
||||
{ 35, "weapon_nova" },
|
||||
{ 36, "weapon_p250" },
|
||||
{ 38, "weapon_scar20" },
|
||||
{ 39, "weapon_sg556" },
|
||||
{ 40, "weapon_ssg08" },
|
||||
{ 60, "weapon_m4a1_silencer" },
|
||||
{ 61, "weapon_usp_silencer" },
|
||||
{ 63, "weapon_cz75a" },
|
||||
{ 64, "weapon_revolver" },
|
||||
{ 500, "weapon_bayonet" },
|
||||
{ 503, "weapon_knife_css" },
|
||||
{ 505, "weapon_knife_flip" },
|
||||
{ 506, "weapon_knife_gut" },
|
||||
{ 507, "weapon_knife_karambit" },
|
||||
{ 508, "weapon_knife_m9_bayonet" },
|
||||
{ 509, "weapon_knife_tactical" },
|
||||
{ 512, "weapon_knife_falchion" },
|
||||
{ 514, "weapon_knife_survival_bowie" },
|
||||
{ 515, "weapon_knife_butterfly" },
|
||||
{ 516, "weapon_knife_push" },
|
||||
{ 517, "weapon_knife_cord" },
|
||||
{ 518, "weapon_knife_canis" },
|
||||
{ 519, "weapon_knife_ursus" },
|
||||
{ 520, "weapon_knife_gypsy_jackknife" },
|
||||
{ 521, "weapon_knife_outdoor" },
|
||||
{ 522, "weapon_knife_stiletto" },
|
||||
{ 523, "weapon_knife_widowmaker" },
|
||||
{ 525, "weapon_knife_skeleton" }
|
||||
};
|
||||
|
||||
public WeaponPaintsConfig Config { get; set; } = new();
|
||||
public override string ModuleAuthor => "Nereziel & daffyy";
|
||||
public override string ModuleDescription => "Skin and knife selector, standalone and web-based";
|
||||
public override string ModuleName => "WeaponPaints";
|
||||
public override string ModuleVersion => "1.3g";
|
||||
|
||||
public static WeaponPaintsConfig GetWeaponPaintsConfig()
|
||||
{
|
||||
return _config;
|
||||
}
|
||||
|
||||
public override void Load(bool hotReload)
|
||||
{
|
||||
if (!Config.GlobalShare)
|
||||
@@ -101,22 +160,37 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
|
||||
Utility.TestDatabaseConnection();
|
||||
}
|
||||
|
||||
weaponSync = new WeaponSynchronization(DatabaseConnectionString, Config, GlobalShareApi, GlobalShareServerId);
|
||||
|
||||
if (hotReload)
|
||||
{
|
||||
OnMapStart(string.Empty);
|
||||
Task.Run(async () =>
|
||||
{
|
||||
for (int i = 1; i <= Server.MaxPlayers; i++)
|
||||
{
|
||||
if (Config.Additional.SkinEnabled && weaponSync != null)
|
||||
await weaponSync.GetWeaponPaintsFromDatabase(i);
|
||||
|
||||
if (Config.Additional.KnifeEnabled && weaponSync != null)
|
||||
await weaponSync.GetKnifeFromDatabase(i);
|
||||
}
|
||||
});
|
||||
List<CCSPlayerController> players = Utilities.GetPlayers();
|
||||
|
||||
foreach (CCSPlayerController player in players)
|
||||
{
|
||||
if (player == null || !player.IsValid || player.IsBot || player.IsHLTV || player.AuthorizedSteamID == null) continue;
|
||||
if (gPlayerWeaponsInfo.ContainsKey((int)player.Index)) continue;
|
||||
|
||||
PlayerInfo playerInfo = new PlayerInfo
|
||||
{
|
||||
UserId = player.UserId,
|
||||
Index = (int)player.Index,
|
||||
SteamId = player?.AuthorizedSteamID?.SteamId64.ToString(),
|
||||
Name = player?.PlayerName,
|
||||
IpAddress = player?.IpAddress?.Split(":")[0]
|
||||
};
|
||||
|
||||
if (Config.Additional.SkinEnabled && weaponSync != null)
|
||||
_ = weaponSync.GetWeaponPaintsFromDatabase(playerInfo);
|
||||
if (Config.Additional.KnifeEnabled && weaponSync != null)
|
||||
_ = weaponSync.GetKnifeFromDatabase(playerInfo);
|
||||
|
||||
g_knifePickupCount[(int)player!.Index] = 0;
|
||||
}
|
||||
/*
|
||||
RegisterListeners();
|
||||
RegisterCommands();
|
||||
*/
|
||||
}
|
||||
|
||||
if (Config.Additional.KnifeEnabled)
|
||||
@@ -124,7 +198,7 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
|
||||
if (Config.Additional.SkinEnabled)
|
||||
SetupSkinsMenu();
|
||||
|
||||
RegisterEvents();
|
||||
RegisterListeners();
|
||||
RegisterCommands();
|
||||
|
||||
Utility.LoadSkinsFromFile(ModuleDirectory + "/skins.json");
|
||||
@@ -136,29 +210,20 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
|
||||
{
|
||||
if (config.DatabaseHost.Length < 1 || config.DatabaseName.Length < 1 || config.DatabaseUser.Length < 1)
|
||||
{
|
||||
Logger.LogError("You need to setup Database credentials in config!");
|
||||
throw new Exception("[WeaponPaints] You need to setup Database credentials in config!");
|
||||
}
|
||||
}
|
||||
|
||||
Config = config;
|
||||
_config = config;
|
||||
_localizer = Localizer;
|
||||
|
||||
Utility.Config = config;
|
||||
Utility.ShowAd(ModuleVersion);
|
||||
Task.Run(async () => await Utility.CheckVersion(ModuleVersion, Logger));
|
||||
}
|
||||
|
||||
public static WeaponPaintsConfig GetWeaponPaintsConfig()
|
||||
{
|
||||
return _config;
|
||||
}
|
||||
|
||||
// TODO: fix for map which change mp_t_default_melee
|
||||
/*private HookResult OnRoundPreStart(EventRoundPrestart @event, GameEventInfo info)
|
||||
{
|
||||
NativeAPI.IssueServerCommand("mp_t_default_melee \"\"");
|
||||
NativeAPI.IssueServerCommand("mp_ct_default_melee \"\"");
|
||||
return HookResult.Continue;
|
||||
}
|
||||
*/
|
||||
public override void Unload(bool hotReload)
|
||||
{
|
||||
base.Unload(hotReload);
|
||||
@@ -192,9 +257,12 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.LogError("Unable to retrieve serverid from GlobalShare!");
|
||||
throw new Exception("[WeaponPaints] Unable to retrieve serverid from GlobalShare!");
|
||||
}
|
||||
}
|
||||
|
||||
Logger.LogInformation("GlobalShare ONLINE!");
|
||||
Console.WriteLine("[WeaponPaints] GlobalShare ONLINE");
|
||||
}
|
||||
}
|
||||
@@ -5,12 +5,17 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.84" />
|
||||
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.121" />
|
||||
<PackageReference Include="Dapper" Version="2.1.24" />
|
||||
<PackageReference Include="MySqlConnector" Version="2.3.1" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="lang\**\*.*" CopyToOutputDirectory="PreserveNewest" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
using CounterStrikeSharp.API;
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using CounterStrikeSharp.API.Modules.Entities;
|
||||
using Dapper;
|
||||
using Dapper;
|
||||
using MySqlConnector;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
@@ -9,13 +6,11 @@ namespace WeaponPaints
|
||||
{
|
||||
internal class WeaponSynchronization
|
||||
{
|
||||
private readonly string _databaseConnectionString;
|
||||
private readonly WeaponPaintsConfig _config;
|
||||
|
||||
private readonly string _databaseConnectionString;
|
||||
private readonly Uri _globalShareApi;
|
||||
private readonly int _globalShareServerId;
|
||||
|
||||
|
||||
internal WeaponSynchronization(string databaseConnectionString, WeaponPaintsConfig config, Uri globalShareApi, int globalShareServerId)
|
||||
{
|
||||
_databaseConnectionString = databaseConnectionString;
|
||||
@@ -24,23 +19,21 @@ namespace WeaponPaints
|
||||
_globalShareServerId = globalShareServerId;
|
||||
}
|
||||
|
||||
internal async Task GetKnifeFromDatabase(int playerIndex)
|
||||
internal async Task GetKnifeFromDatabase(PlayerInfo player)
|
||||
{
|
||||
if (!_config.Additional.KnifeEnabled) return;
|
||||
if (player.SteamId == null || player.Index == 0) return;
|
||||
try
|
||||
{
|
||||
CCSPlayerController player = Utilities.GetPlayerFromIndex(playerIndex);
|
||||
if (!Utility.IsPlayerValid(player)) return;
|
||||
var steamId = new SteamID(player.SteamID);
|
||||
|
||||
if (_config.GlobalShare)
|
||||
{
|
||||
var values = new Dictionary<string, string>
|
||||
{
|
||||
{ "server_id", _globalShareServerId.ToString() },
|
||||
{ "steamid", steamId.SteamId64.ToString() },
|
||||
{ "steamid", player.SteamId },
|
||||
{ "knife", "1" }
|
||||
};
|
||||
|
||||
UriBuilder builder = new UriBuilder(_globalShareApi);
|
||||
builder.Query = string.Join("&", values.Select(p => $"{Uri.EscapeDataString(p.Key)}={Uri.EscapeDataString(p.Value)}"));
|
||||
|
||||
@@ -55,13 +48,12 @@ namespace WeaponPaints
|
||||
string result = await response.Content.ReadAsStringAsync();
|
||||
if (!string.IsNullOrEmpty(result))
|
||||
{
|
||||
WeaponPaints.g_playersKnife[playerIndex] = result;
|
||||
WeaponPaints.g_playersKnife[player.Index] = result;
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -75,10 +67,11 @@ namespace WeaponPaints
|
||||
{
|
||||
await connection.OpenAsync();
|
||||
string query = "SELECT `knife` FROM `wp_player_knife` WHERE `steamid` = @steamid";
|
||||
string? PlayerKnife = await connection.QueryFirstOrDefaultAsync<string>(query, new { steamid = steamId.SteamId64.ToString() });
|
||||
string? PlayerKnife = await connection.QueryFirstOrDefaultAsync<string>(query, new { steamid = player.SteamId });
|
||||
|
||||
if (PlayerKnife != null)
|
||||
{
|
||||
WeaponPaints.g_playersKnife[playerIndex] = PlayerKnife;
|
||||
WeaponPaints.g_playersKnife[player.Index] = PlayerKnife;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -86,7 +79,6 @@ namespace WeaponPaints
|
||||
}
|
||||
await connection.CloseAsync();
|
||||
}
|
||||
//Log($"{player.PlayerName} has this knife -> {g_playersKnife[playerIndex]}");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -95,40 +87,14 @@ namespace WeaponPaints
|
||||
}
|
||||
}
|
||||
|
||||
internal async Task SyncKnifeToDatabase(int playerIndex, string knife)
|
||||
{
|
||||
if (!_config.Additional.KnifeEnabled) return;
|
||||
try
|
||||
{
|
||||
CCSPlayerController player = Utilities.GetPlayerFromIndex(playerIndex);
|
||||
if (player == null || !player.IsValid) return;
|
||||
var steamId = new SteamID(player.SteamID);
|
||||
|
||||
using var connection = new MySqlConnection(_databaseConnectionString);
|
||||
await connection.OpenAsync();
|
||||
string query = "INSERT INTO `wp_player_knife` (`steamid`, `knife`) VALUES(@steamid, @newKnife) ON DUPLICATE KEY UPDATE `knife` = @newKnife";
|
||||
await connection.ExecuteAsync(query, new { steamid = steamId.SteamId64.ToString(), newKnife = knife });
|
||||
await connection.CloseAsync();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Utility.Log(e.Message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
internal async Task GetWeaponPaintsFromDatabase(int playerIndex)
|
||||
internal async Task GetWeaponPaintsFromDatabase(PlayerInfo player)
|
||||
{
|
||||
if (!_config.Additional.SkinEnabled) return;
|
||||
if (player.SteamId == null || player.Index == 0) return;
|
||||
|
||||
CCSPlayerController player = Utilities.GetPlayerFromIndex(playerIndex);
|
||||
if (!Utility.IsPlayerValid(player)) return;
|
||||
|
||||
var steamId = new SteamID(player.SteamID);
|
||||
|
||||
if (!WeaponPaints.gPlayerWeaponsInfo.TryGetValue(playerIndex, out _))
|
||||
if (!WeaponPaints.gPlayerWeaponsInfo.TryGetValue(player.Index, out _))
|
||||
{
|
||||
WeaponPaints.gPlayerWeaponsInfo[playerIndex] = new Dictionary<int, WeaponInfo>();
|
||||
WeaponPaints.gPlayerWeaponsInfo[player.Index] = new Dictionary<int, WeaponInfo>();
|
||||
}
|
||||
try
|
||||
{
|
||||
@@ -137,7 +103,7 @@ namespace WeaponPaints
|
||||
var values = new Dictionary<string, string>
|
||||
{
|
||||
{ "server_id", _globalShareServerId.ToString() },
|
||||
{ "steamid", steamId.SteamId64.ToString() },
|
||||
{ "steamid", player.SteamId },
|
||||
{ "skins", "1" }
|
||||
};
|
||||
UriBuilder builder = new UriBuilder(_globalShareApi);
|
||||
@@ -166,16 +132,11 @@ namespace WeaponPaints
|
||||
{
|
||||
WeaponInfo weaponInfo = new WeaponInfo
|
||||
{
|
||||
Paint = weaponPaintId.Value, // Example paint value
|
||||
Seed = weaponSeed.Value, // Example seed value
|
||||
Wear = weaponWear.Value // Example wear value
|
||||
Paint = weaponPaintId.Value,
|
||||
Seed = weaponSeed.Value,
|
||||
Wear = weaponWear.Value
|
||||
};
|
||||
WeaponPaints.gPlayerWeaponsInfo[playerIndex][weaponDefIndex.Value] = weaponInfo;
|
||||
/*
|
||||
gPlayerWeaponPaints[playerIndex][weaponDefIndex.Value] = weaponPaintId.Value;
|
||||
gPlayerWeaponWear[playerIndex][weaponDefIndex.Value] = weaponWear.Value;
|
||||
gPlayerWeaponSeed[playerIndex][weaponDefIndex.Value] = weaponSeed.Value;
|
||||
*/
|
||||
WeaponPaints.gPlayerWeaponsInfo[player.Index][weaponDefIndex.Value] = weaponInfo;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -193,7 +154,7 @@ namespace WeaponPaints
|
||||
await connection.OpenAsync();
|
||||
|
||||
string query = "SELECT * FROM `wp_player_skins` WHERE `steamid` = @steamid";
|
||||
IEnumerable<dynamic> PlayerSkins = await connection.QueryAsync<dynamic>(query, new { steamid = steamId.SteamId64.ToString() });
|
||||
IEnumerable<dynamic> PlayerSkins = await connection.QueryAsync<dynamic>(query, new { steamid = player.SteamId });
|
||||
|
||||
if (PlayerSkins != null && PlayerSkins.AsList().Count > 0)
|
||||
{
|
||||
@@ -210,7 +171,7 @@ namespace WeaponPaints
|
||||
Seed = weaponSeed,
|
||||
Wear = weaponWear
|
||||
};
|
||||
WeaponPaints.gPlayerWeaponsInfo[playerIndex][weaponDefIndex] = weaponInfo;
|
||||
WeaponPaints.gPlayerWeaponsInfo[player.Index][weaponDefIndex] = weaponInfo;
|
||||
});
|
||||
}
|
||||
else
|
||||
@@ -227,20 +188,36 @@ namespace WeaponPaints
|
||||
}
|
||||
}
|
||||
|
||||
internal async Task SyncWeaponPaintsToDatabase(CCSPlayerController? player)
|
||||
internal async Task SyncKnifeToDatabase(PlayerInfo player, string knife)
|
||||
{
|
||||
if (player == null || !Utility.IsPlayerValid(player)) return;
|
||||
if (!_config.Additional.KnifeEnabled) return;
|
||||
try
|
||||
{
|
||||
if (player.SteamId == null || player.Index == 0) return;
|
||||
|
||||
int playerIndex = (int)player.Index;
|
||||
string steamId = new SteamID(player.SteamID).SteamId64.ToString();
|
||||
using var connection = new MySqlConnection(_databaseConnectionString);
|
||||
await connection.OpenAsync();
|
||||
string query = "INSERT INTO `wp_player_knife` (`steamid`, `knife`) VALUES(@steamid, @newKnife) ON DUPLICATE KEY UPDATE `knife` = @newKnife";
|
||||
await connection.ExecuteAsync(query, new { steamid = player.SteamId, newKnife = knife });
|
||||
await connection.CloseAsync();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Utility.Log(e.Message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
internal async Task SyncWeaponPaintsToDatabase(PlayerInfo player)
|
||||
{
|
||||
if (player == null || player.Index <= 0 || player.SteamId == null) return;
|
||||
|
||||
using var connection = new MySqlConnection(_databaseConnectionString);
|
||||
await connection.OpenAsync();
|
||||
|
||||
if (!WeaponPaints.gPlayerWeaponsInfo.ContainsKey(playerIndex))
|
||||
if (!WeaponPaints.gPlayerWeaponsInfo.ContainsKey(player.Index))
|
||||
return;
|
||||
|
||||
foreach (var weaponInfoPair in WeaponPaints.gPlayerWeaponsInfo[playerIndex])
|
||||
foreach (var weaponInfoPair in WeaponPaints.gPlayerWeaponsInfo[player.Index])
|
||||
{
|
||||
int weaponDefIndex = weaponInfoPair.Key;
|
||||
WeaponInfo weaponInfo = weaponInfoPair.Value;
|
||||
@@ -253,7 +230,7 @@ namespace WeaponPaints
|
||||
"`weapon_wear` = @wear, `weapon_seed` = @seed WHERE `steamid` = @steamid " +
|
||||
"AND `weapon_defindex` = @weaponDefIndex";
|
||||
|
||||
var updateParams = new { paintId, wear, seed, steamid = steamId, weaponDefIndex };
|
||||
var updateParams = new { paintId, wear, seed, steamid = player.SteamId, weaponDefIndex };
|
||||
int rowsAffected = await connection.ExecuteAsync(updateSql, updateParams);
|
||||
|
||||
if (rowsAffected == 0)
|
||||
@@ -268,4 +245,4 @@ namespace WeaponPaints
|
||||
await connection.CloseAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
14
lang/en.json
Normal file
14
lang/en.json
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"wp_prefix": "{lightblue}[WeaponPaints] {default}",
|
||||
"wp_info_website": "Visit {lime}{0}{default} where you can change skins",
|
||||
"wp_info_refresh": "Type {lime}!wp{default} to synchronize chosen skins",
|
||||
"wp_info_knife": "Type {lime}!knife{default} to open knife menu",
|
||||
"wp_command_cooldown": "{lightred}You can't refresh weapon paints right now",
|
||||
"wp_command_refresh_done": "{lime}Refreshing weapon paints",
|
||||
"wp_knife_menu_select": "You have chosen {lime}{0}{default} as your knife",
|
||||
"wp_knife_menu_kill": "To correctly apply skin for knife, you need to type {lime}!kill{default}",
|
||||
"wp_knife_menu_title": "Knife Menu",
|
||||
"wp_skin_menu_weapon_title": "Weapon Menu",
|
||||
"wp_skin_menu_skin_title": "Select skin for {lime}{0}{default}",
|
||||
"wp_skin_menu_select": "You have chosen {lime}{0}{default} as your skin"
|
||||
}
|
||||
14
lang/lv.json
Normal file
14
lang/lv.json
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"wp_prefix": "{lightblue}[Ieroču Ādiņas] {default}",
|
||||
"wp_info_website": "Apmeklē {lime}{0}{default} kur tu vari nomainīt skinus",
|
||||
"wp_info_refresh": "Raksti {lime}!wp{default} lai sinhronizētu izvēlētos skinus",
|
||||
"wp_info_knife": "Raksti {lime}!knife{default} lai atvērtu nažu izvēlni",
|
||||
"wp_command_cooldown": "{lightred} Tu šobrīd nevari atjaunot ieroču skinus...",
|
||||
"wp_command_refresh_done": "{lime}Izvēlētie skini tiek atjaunoti",
|
||||
"wp_knife_menu_select": "Tu esi izvēlējies {lime}{0}{default} nazi",
|
||||
"wp_knife_menu_kill": "Lai pareizi atjaunotu naža skinu, ieraksti čatā {lime}!kill{default}",
|
||||
"wp_knife_menu_title": "Nažu Izvēlne",
|
||||
"wp_skin_menu_weapon_title": "Ieroču Izvēlne",
|
||||
"wp_skin_menu_skin_title": "Izvēlies skinu ierocim: {lime}{0}{default}",
|
||||
"wp_skin_menu_select": "Tu esi izvēlējies {lime}{0}{default} kā savu skinu"
|
||||
}
|
||||
14
lang/pl.json
Normal file
14
lang/pl.json
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"wp_prefix": "{lightblue}[WeaponPaints] {default}",
|
||||
"wp_info_website": "Odwiedź {lime}{0}{default} gdzie będziesz mógł ustawić skiny",
|
||||
"wp_info_refresh": "Wpisz {lime}!wp{default} aby zsynchronizować swoje skiny",
|
||||
"wp_info_knife": "Wpisz {lime}!knife{default} aby wy<77>wietlić menu no<6E>y",
|
||||
"wp_command_cooldown": "{lightred}Odczekaj chwilę przed wykonaniem tej komendy...",
|
||||
"wp_command_refresh_done": "{lime}Pomyslnie zsynchronizowano twoje skiny",
|
||||
"wp_knife_menu_select": "Wybrałeś {lime}{0}{default} jako swój nóż",
|
||||
"wp_knife_menu_kill": "Do prawidłowego zastosowania noża użyj {lime}!kill{default}",
|
||||
"wp_knife_menu_title": "Menu noży",
|
||||
"wp_skin_menu_weapon_title": "Menu broni",
|
||||
"wp_skin_menu_skin_title": "Wybierz skin dla {lime}{0}{default}",
|
||||
"wp_skin_menu_select": "Wybrałeś {lime}{0}{default} jako swój skin"
|
||||
}
|
||||
14
lang/ru.json
Normal file
14
lang/ru.json
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"wp_prefix": "{lightblue}[WeaponPaints] {default}",
|
||||
"wp_info_website": "Посетите сайт {lime}{0},{default} чтобы выбрать скин",
|
||||
"wp_info_refresh": "Наберите в чат {lime}!wp{default} для синхронизации выбранных скинов",
|
||||
"wp_info_knife": "Наберите в чат {lime}!knife,{default} чтобы выбрать нож",
|
||||
"wp_command_cooldown": "{lightred}Вы не можете выбрать оружие прямо сейчас",
|
||||
"wp_command_refresh_done": "{lime}Обновление скинов для оружия",
|
||||
"wp_knife_menu_select": "Вы выбрали {lime}{0}{default} скин для ножа",
|
||||
"wp_knife_menu_kill": "Чтобы правильно применить скин для ножа, набери в чат {lime}!kill{default}",
|
||||
"wp_knife_menu_title": "Меню ножей",
|
||||
"wp_skin_menu_weapon_title": "Меню оружия",
|
||||
"wp_skin_menu_skin_title": "Выберите скин для {lime}{0}{default}",
|
||||
"wp_skin_menu_select": "Вы выбрали {lime}{0}{default} скина для оружия"
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
<?php
|
||||
$weapons = array (
|
||||
"weapon_deagle" => 1,
|
||||
"weapon_elite" => 2,
|
||||
"weapon_fiveseven" => 3,
|
||||
"weapon_glock" => 4,
|
||||
"weapon_ak47" => 7,
|
||||
"weapon_aug" => 8,
|
||||
"weapon_awp" => 9,
|
||||
"weapon_famas" => 10,
|
||||
"weapon_g3sg1" => 10,
|
||||
"weapon_galilar" => 13,
|
||||
"weapon_m249" => 14,
|
||||
"weapon_m4a1" => 16,
|
||||
"weapon_mac10" => 17,
|
||||
"weapon_p90" => 19,
|
||||
"weapon_mp5sd" => 23,
|
||||
"weapon_ump45" => 24,
|
||||
"weapon_xm1014" => 25,
|
||||
"weapon_bizon" => 26,
|
||||
"weapon_mag7" => 27,
|
||||
"weapon_negev" => 28,
|
||||
"weapon_sawedoff" => 29,
|
||||
"weapon_tec9" => 30,
|
||||
"weapon_hkp2000" => 32,
|
||||
"weapon_mp7" => 33,
|
||||
"weapon_mp9" => 34,
|
||||
"weapon_nova" => 35,
|
||||
"weapon_p250" => 36,
|
||||
"weapon_scar20" => 38,
|
||||
"weapon_sg556" => 39,
|
||||
"weapon_ssg08" => 40,
|
||||
"weapon_m4a1_silencer" => 60,
|
||||
"weapon_usp_silencer" => 61,
|
||||
"weapon_cz75a" => 63,
|
||||
"weapon_revolver" => 64,
|
||||
"weapon_bayonet" => 500,
|
||||
"weapon_knife_css" => 503,
|
||||
"weapon_knife_flip" => 505,
|
||||
"weapon_knife_gut" => 506,
|
||||
"weapon_knife_karambit" => 507,
|
||||
"weapon_knife_m9_bayonet" => 508,
|
||||
"weapon_knife_tactical" => 509,
|
||||
"weapon_knife_falchion" => 512,
|
||||
"weapon_knife_survival_bowie"=> 514,
|
||||
"weapon_knife_butterfly" => 515,
|
||||
"weapon_knife_push" => 516,
|
||||
"weapon_knife_cord" => 517,
|
||||
"weapon_knife_canis" => 518,
|
||||
"weapon_knife_ursus" => 519,
|
||||
"weapon_knife_gypsy_jackknife" => 520,
|
||||
"weapon_knife_outdoor" => 521,
|
||||
"weapon_knife_stiletto" => 522,
|
||||
"weapon_knife_widowmaker" => 523,
|
||||
"weapon_knife_skeleton" => 525);
|
||||
$json = json_decode(file_get_contents('skins.json'));
|
||||
echo "<pre>";
|
||||
foreach($json as $skin)
|
||||
{
|
||||
if(!str_contains($skin->weapon->id, "weapon_")) continue;
|
||||
$name = $skin->name;
|
||||
$name = str_replace("'","\'",$name);
|
||||
$weapon = $skin->weapon->id;
|
||||
$image = $skin->image;
|
||||
$paint = $skin->paint_index;
|
||||
echo "('{$weapon}', {$weapons[$weapon]}, {$paint}, '{$image}', '{$name}')";
|
||||
echo ",<br>";
|
||||
|
||||
}
|
||||
//print_r($json);
|
||||
echo "</pre>";
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user