Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Nereziel committed Nov 14, 2023
1 parent 5a5b120 commit dc7fb18
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 71 deletions.
8 changes: 4 additions & 4 deletions Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ public class WeaponPaintsConfig : BasePluginConfig
public override int Version { get; set; } = 1;

[JsonPropertyName("DatabaseHost")]
public string DatabaseHost { get; set; } = "localhost";
public string DatabaseHost { get; set; } = "";

[JsonPropertyName("DatabasePort")]
public int DatabasePort { get; set; } = 3306;

[JsonPropertyName("DatabaseUser")]
public string DatabaseUser { get; set; } = "dbuser";
public string DatabaseUser { get; set; } = "";

[JsonPropertyName("DatabasePassword")]
public string DatabasePassword { get; set; } = "dbuserpw";
public string DatabasePassword { get; set; } = "";

[JsonPropertyName("DatabaseName")]
public string DatabaseName { get; set; } = "dbname";
public string DatabaseName { get; set; } = "";

[JsonPropertyName("CmdRefreshCooldownSeconds")]
public int CmdRefreshCooldownSeconds { get; set; } = 60;
Expand Down
40 changes: 26 additions & 14 deletions WeaponPaints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
private Dictionary<ulong, Dictionary<nint, int>> gPlayerWeaponPaints = new();
private Dictionary<ulong, Dictionary<nint, int>> gPlayerWeaponSeed = new();
private Dictionary<ulong, Dictionary<nint, float>> gPlayerWeaponWear = new();
private Dictionary<int, string> g_playersKife = new();
private Dictionary<int, string> g_playersKnife = new();
private static readonly Dictionary<string, string> knifeTypes = new()
{
{ "m9", "weapon_knife_m9_bayonet" },
Expand Down Expand Up @@ -77,6 +77,11 @@ public override void Load(bool hotReload)
}
public void OnConfigParsed(WeaponPaintsConfig config)
{
if (config.DatabaseHost.Length < 1 || config.DatabaseName.Length < 1 || config.DatabaseUser.Length < 1)
{
throw new Exception("You need to setup Database credentials in config!");
}

Config = config;
}
// TODO: fix for map which change mp_t_default_melee
Expand Down Expand Up @@ -126,12 +131,13 @@ private void OnClientPutInServer(int playerSlot)
private void OnClientDisconnect(int playerSlot)
{
// TODO: Clean up after player
g_playersKnife.Remove(playerSlot+1);
}

private HookResult OnPlayerSpawn(EventPlayerSpawn @event, GameEventInfo info)
{
var player = @event.Userid;
if (!player.IsValid || !player.PlayerPawn.IsValid)
if (!player.IsValid || !player.PlayerPawn.IsValid || !player.PawnIsAlive)
{
return HookResult.Continue;
}
Expand All @@ -140,18 +146,18 @@ private HookResult OnPlayerSpawn(EventPlayerSpawn @event, GameEventInfo info)
player.GiveNamedItem("weapon_knife");
return HookResult.Continue;
}
if (!PlayerHasKnife(player))

if (!PlayerHasKnife(player))
{
if (g_playersKife.ContainsKey((int)player.EntityIndex!.Value.Value))
if (g_playersKnife.TryGetValue((int)player.EntityIndex!.Value.Value, out var knife))
{
player.GiveNamedItem(g_playersKife[(int)player.EntityIndex!.Value.Value]);
player.GiveNamedItem(knife);
}
else
{
player.GiveNamedItem("weapon_knife");
}
}
}

return HookResult.Continue;
}
Expand All @@ -178,7 +184,7 @@ private void OnEntitySpawned(CEntityInstance entity)
var player = Utilities.GetPlayerFromIndex(playerIndex);
if (player == null || !player.IsValid || player.IsBot) return;
// TODO: Remove knife crashes here, needs another solution
/*if (isKnife && g_playersKife[(int)player.EntityIndex!.Value.Value] != "weapon_knife" && (weapon.AttributeManager.Item.ItemDefinitionIndex == 42 || weapon.AttributeManager.Item.ItemDefinitionIndex == 59))
/*if (isKnife && g_playersKnife[(int)player.EntityIndex!.Value.Value] != "weapon_knife" && (weapon.AttributeManager.Item.ItemDefinitionIndex == 42 || weapon.AttributeManager.Item.ItemDefinitionIndex == 59))
{
RemoveKnifeFromPlayer(player);
return;
Expand All @@ -203,7 +209,7 @@ private void OnEntitySpawned(CEntityInstance entity)
public void RemoveKnifeFromPlayer(CCSPlayerController player)
{
if (!player.PawnIsAlive) return;
if (!g_playersKife.ContainsKey((int)player.EntityIndex!.Value.Value)) return;
if (!g_playersKnife.ContainsKey((int)player.EntityIndex!.Value.Value)) return;
var weapons = player.PlayerPawn.Value.WeaponServices!.MyWeapons;
foreach (var weapon in weapons)
{
Expand All @@ -213,7 +219,7 @@ public void RemoveKnifeFromPlayer(CCSPlayerController player)
if (weapon.Value.DesignerName.Contains("knife"))
{
weapon.Value.Remove();
player.GiveNamedItem(g_playersKife[(int)player.EntityIndex!.Value.Value]);
player.GiveNamedItem(g_playersKnife[(int)player.EntityIndex!.Value.Value]);
break;
}
}
Expand Down Expand Up @@ -243,7 +249,7 @@ private void SetupMenus()
if (knifeTypes.TryGetValue(option.Text, out var knife))
{
Task.Run(() => SyncKnifeToDatabase((int)player.EntityIndex!.Value.Value, knife));
g_playersKife[(int)player.EntityIndex!.Value.Value] = knifeTypes[option.Text];
g_playersKnife[(int)player.EntityIndex!.Value.Value] = knifeTypes[option.Text];
player.PrintToChat($"You have chosen {option.Text} as your knife.");
RemoveKnifeFromPlayer(player);
}
Expand Down Expand Up @@ -293,7 +299,7 @@ private async Task GetWeaponPaintsFromDatabase(int playerIndex)
.Add("steamid", "=", steamId.SteamId64.ToString());

MySqlQueryResult result = await MySql!.Table("wp_player_skins").Where(conditions).SelectAsync();

if (result.Rows < 1) return;
result.ToList().ForEach(pair =>
{
int WeaponDefIndex = result.Get<int>(pair.Key, "weapon_defindex");
Expand Down Expand Up @@ -337,12 +343,18 @@ private async Task GetKnifeFromDatabase(int playerIndex)

MySqlQueryResult result = await MySql!.Table("wp_player_knife").Where(conditions).SelectAsync();

if (result.Rows < 1)
{
//g_playersKnife[playerIndex] = "weapon_knife";
return;
}

string knife = result.Get<string>(0, "knife");
if (knife != null)
{
g_playersKife[playerIndex] = knife;
g_playersKnife[playerIndex] = knife;
}
//Log($"{player.PlayerName} has this knife -> {g_playersKife[playerIndex]}");
//Log($"{player.PlayerName} has this knife -> {g_playersKnife[playerIndex]}");
}
catch (Exception e)
{
Expand Down
106 changes: 53 additions & 53 deletions website/database.sql
Original file line number Diff line number Diff line change
Expand Up @@ -63,59 +63,59 @@ COMMIT;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

INSERT INTO `wp_weapons_paints` (`weapon_name`, `weapon_defindex`, `paint`, `image`, `paint_name`) VALUES
('weapon_bizon',26,0,'https://overcore.eu/wska/img/weapon/weapon_bizon.png','PP-Bizon | Default'),
('weapon_mac10',17,0,'https://overcore.eu/wska/img/weapon/weapon_mac10.png','Mac-10 | Default'),
('weapon_mp9',34,0,'https://overcore.eu/wska/img/weapon/weapon_mp9.png','MP9 | Default'),
('weapon_p90',19,0,'https://overcore.eu/wska/img/weapon/weapon_p90.png','P90 | Default'),
('weapon_ump45',24,0,'https://overcore.eu/wska/img/weapon/weapon_ump45.png','UMP | Default'),
('weapon_ak47',7,0,'https://overcore.eu/wska/img/weapon/weapon_ak47.png','AK-47 | Default'),
('weapon_aug',8,0,'https://overcore.eu/wska/img/weapon/weapon_aug.png','AUG | Default'),
('weapon_famas',10,0,'https://overcore.eu/wska/img/weapon/weapon_famas.png','Famas | Default'),
('weapon_galilar',13,0,'https://overcore.eu/wska/img/weapon/weapon_galilar.png','Galil | Default'),
('weapon_m4a1',16,0,'https://overcore.eu/wska/img/weapon/weapon_m4a1.png','M4A4 | Default'),
('weapon_m4a1_silencer',60,0,'https://overcore.eu/wska/img/weapon/weapon_m4a1_silencer.png','M4A1-S | Default'),
('weapon_sg556',39,0,'https://overcore.eu/wska/img/weapon/weapon_sg556.png','SG 556 | Default'),
('weapon_awp',9,0,'https://overcore.eu/wska/img/weapon/weapon_awp.png','AWP | Default'),
('weapon_g3sg1',11,0,'https://overcore.eu/wska/img/weapon/weapon_g3sg1.png','G3SG1 | Default'),
('weapon_scar20',38,0,'https://overcore.eu/wska/img/weapon/weapon_scar20.png','Scar 20 | Default'),
('weapon_ssg08',40,0,'https://overcore.eu/wska/img/weapon/weapon_ssg08.png','SSG 08 | Default'),
('weapon_mag7',27,0,'https://overcore.eu/wska/img/weapon/weapon_mag7.png','Mag-7 | Default'),
('weapon_nova',35,0,'https://overcore.eu/wska/img/weapon/weapon_nova.png','Nova | Default'),
('weapon_sawedoff',29,0,'https://overcore.eu/wska/img/weapon/weapon_sawedoff.png','Sawed off | Default'),
('weapon_xm1014',25,0,'https://overcore.eu/wska/img/weapon/weapon_xm1014.png','XM 1014 | Default'),
('weapon_m249',14,0,'https://overcore.eu/wska/img/weapon/weapon_m249.png','M249 | Default'),
('weapon_negev',28,0,'https://overcore.eu/wska/img/weapon/weapon_negev.png','Negev | Default'),
('weapon_deagle',1,0,'https://overcore.eu/wska/img/weapon/weapon_deagle.png','Desert Eagle | Default'),
('weapon_elite',2,0,'https://overcore.eu/wska/img/weapon/weapon_elite.png','Dual Elites | Default'),
('weapon_fiveseven',3,0,'https://overcore.eu/wska/img/weapon/weapon_fiveseven.png','Five Seven | Default'),
('weapon_glock',4,0,'https://overcore.eu/wska/img/weapon/weapon_glock.png','Glock | Default'),
('weapon_hkp2000',32,0,'https://overcore.eu/wska/img/weapon/weapon_hkp2000.png','P2000 | Default'),
('weapon_tec9',30,0,'https://overcore.eu/wska/img/weapon/weapon_tec9.png','Tec-9 | Default'),
('weapon_usp_silencer',61,0,'https://overcore.eu/wska/img/weapon/weapon_usp_silencer.png','USP-S | Default'),
('weapon_cz75a',63,0,'https://overcore.eu/wska/img/weapon/weapon_cz75a.png','CZ-75 | Default'),
('weapon_p250',36,0,'https://overcore.eu/wska/img/weapon/weapon_p250.png','P250 | Default'),
('weapon_mp5sd',23,0,'https://overcore.eu/wska/img/weapon/weapon_mp5sd.png','MP5-SD | Default'),
('weapon_mp7',33,0,'https://overcore.eu/wska/img/weapon/weapon_mp7.png','MP7 | Default'),
('weapon_revolver',64,0,'https://overcore.eu/wska/img/weapon/weapon_revolver.png','Revolver | Default'),
('weapon_bayonet',500,0,'https://overcore.eu/wska/img/weapon/weapon_bayonet.png','★ Bayonet| Default'),
('weapon_knife_css',503,0,'https://overcore.eu/wska/img/weapon/weapon_knife_css.png','★ Classic Knife | Default'),
('weapon_knife_flip',505,0,'https://overcore.eu/wska/img/weapon/weapon_knife_flip.png','★ Flip Knife | Default'),
('weapon_knife_gut',506,0,'https://overcore.eu/wska/img/weapon/weapon_knife_gut.png','★ Gut Knife | Default'),
('weapon_knife_karambit',507,0,'https://overcore.eu/wska/img/weapon/weapon_knife_karambit.png','★ Karambit | Default'),
('weapon_knife_m9_bayonet',508,0,'https://overcore.eu/wska/img/weapon/weapon_knife_m9_bayonet.png','★ M9 Bayonet | Default'),
('weapon_knife_tactical',509,0,'https://overcore.eu/wska/img/weapon/weapon_knife_tactical.png','★ Huntsman Knife | Default'),
('weapon_knife_falchion',512,0,'https://overcore.eu/wska/img/weapon/weapon_knife_falchion.png','★ Falchion Knife | Default'),
('weapon_knife_survival_bowie',514,0,'https://overcore.eu/wska/img/weapon/weapon_knife_survival_bowie.png','★ Bowie Knife | Default'),
('weapon_knife_butterfly',515,0,'https://overcore.eu/wska/img/weapon/weapon_knife_butterfly.png','★ Butterfly Knife | Default'),
('weapon_knife_push',516,0,'https://overcore.eu/wska/img/weapon/weapon_knife_push.png','★ Shadow Daggers | Default'),
('weapon_knife_cord',517,0,'https://overcore.eu/wska/img/weapon/weapon_knife_cord.png','★ Paracord Knife | Default'),
('weapon_knife_canis',518,0,'https://overcore.eu/wska/img/weapon/weapon_knife_canis.png','★ Survival Knife | Default'),
('weapon_knife_ursus',519,0,'https://overcore.eu/wska/img/weapon/weapon_knife_ursus.png','★ Ursus Knife | Default'),
('weapon_knife_gypsy_jackknife',520,0,'https://overcore.eu/wska/img/weapon/weapon_knife_gypsy_jackknife.png','★ Navaja Knife | Default'),
('weapon_knife_outdoor',521,0,'https://overcore.eu/wska/img/weapon/weapon_knife_outdoor.png','★ Nomad Knife | Default'),
('weapon_knife_stiletto',522,0,'https://overcore.eu/wska/img/weapon/weapon_knife_stiletto.png','★ Stiletto Knife | Default'),
('weapon_knife_widowmaker',523,0,'https://overcore.eu/wska/img/weapon/weapon_knife_widowmaker.png','★ Talon Knife | Default'),
('weapon_knife_skeleton',525,0,'https://overcore.eu/wska/img/weapon/weapon_knife_skeleton.png','★ Skeleton Knife | Default');
('weapon_bizon',26,0,'img/weapon/weapon_bizon.png','PP-Bizon | Default'),
('weapon_mac10',17,0,'img/weapon/weapon_mac10.png','Mac-10 | Default'),
('weapon_mp9',34,0,'img/weapon/weapon_mp9.png','MP9 | Default'),
('weapon_p90',19,0,'img/weapon/weapon_p90.png','P90 | Default'),
('weapon_ump45',24,0,'img/weapon/weapon_ump45.png','UMP | Default'),
('weapon_ak47',7,0,'img/weapon/weapon_ak47.png','AK-47 | Default'),
('weapon_aug',8,0,'img/weapon/weapon_aug.png','AUG | Default'),
('weapon_famas',10,0,'img/weapon/weapon_famas.png','Famas | Default'),
('weapon_galilar',13,0,'img/weapon/weapon_galilar.png','Galil | Default'),
('weapon_m4a1',16,0,'img/weapon/weapon_m4a1.png','M4A4 | Default'),
('weapon_m4a1_silencer',60,0,'img/weapon/weapon_m4a1_silencer.png','M4A1-S | Default'),
('weapon_sg556',39,0,'img/weapon/weapon_sg556.png','SG 556 | Default'),
('weapon_awp',9,0,'img/weapon/weapon_awp.png','AWP | Default'),
('weapon_g3sg1',11,0,'img/weapon/weapon_g3sg1.png','G3SG1 | Default'),
('weapon_scar20',38,0,'img/weapon/weapon_scar20.png','Scar 20 | Default'),
('weapon_ssg08',40,0,'img/weapon/weapon_ssg08.png','SSG 08 | Default'),
('weapon_mag7',27,0,'img/weapon/weapon_mag7.png','Mag-7 | Default'),
('weapon_nova',35,0,'img/weapon/weapon_nova.png','Nova | Default'),
('weapon_sawedoff',29,0,'img/weapon/weapon_sawedoff.png','Sawed off | Default'),
('weapon_xm1014',25,0,'img/weapon/weapon_xm1014.png','XM 1014 | Default'),
('weapon_m249',14,0,'img/weapon/weapon_m249.png','M249 | Default'),
('weapon_negev',28,0,'img/weapon/weapon_negev.png','Negev | Default'),
('weapon_deagle',1,0,'img/weapon/weapon_deagle.png','Desert Eagle | Default'),
('weapon_elite',2,0,'img/weapon/weapon_elite.png','Dual Elites | Default'),
('weapon_fiveseven',3,0,'img/weapon/weapon_fiveseven.png','Five Seven | Default'),
('weapon_glock',4,0,'img/weapon/weapon_glock.png','Glock | Default'),
('weapon_hkp2000',32,0,'img/weapon/weapon_hkp2000.png','P2000 | Default'),
('weapon_tec9',30,0,'img/weapon/weapon_tec9.png','Tec-9 | Default'),
('weapon_usp_silencer',61,0,'img/weapon/weapon_usp_silencer.png','USP-S | Default'),
('weapon_cz75a',63,0,'img/weapon/weapon_cz75a.png','CZ-75 | Default'),
('weapon_p250',36,0,'img/weapon/weapon_p250.png','P250 | Default'),
('weapon_mp5sd',23,0,'img/weapon/weapon_mp5sd.png','MP5-SD | Default'),
('weapon_mp7',33,0,'img/weapon/weapon_mp7.png','MP7 | Default'),
('weapon_revolver',64,0,'img/weapon/weapon_revolver.png','Revolver | Default'),
('weapon_bayonet',500,0,'img/weapon/weapon_bayonet.png','★ Bayonet| Default'),
('weapon_knife_css',503,0,'img/weapon/weapon_knife_css.png','★ Classic Knife | Default'),
('weapon_knife_flip',505,0,'img/weapon/weapon_knife_flip.png','★ Flip Knife | Default'),
('weapon_knife_gut',506,0,'img/weapon/weapon_knife_gut.png','★ Gut Knife | Default'),
('weapon_knife_karambit',507,0,'img/weapon/weapon_knife_karambit.png','★ Karambit | Default'),
('weapon_knife_m9_bayonet',508,0,'img/weapon/weapon_knife_m9_bayonet.png','★ M9 Bayonet | Default'),
('weapon_knife_tactical',509,0,'img/weapon/weapon_knife_tactical.png','★ Huntsman Knife | Default'),
('weapon_knife_falchion',512,0,'img/weapon/weapon_knife_falchion.png','★ Falchion Knife | Default'),
('weapon_knife_survival_bowie',514,0,'img/weapon/weapon_knife_survival_bowie.png','★ Bowie Knife | Default'),
('weapon_knife_butterfly',515,0,'img/weapon/weapon_knife_butterfly.png','★ Butterfly Knife | Default'),
('weapon_knife_push',516,0,'img/weapon/weapon_knife_push.png','★ Shadow Daggers | Default'),
('weapon_knife_cord',517,0,'img/weapon/weapon_knife_cord.png','★ Paracord Knife | Default'),
('weapon_knife_canis',518,0,'img/weapon/weapon_knife_canis.png','★ Survival Knife | Default'),
('weapon_knife_ursus',519,0,'img/weapon/weapon_knife_ursus.png','★ Ursus Knife | Default'),
('weapon_knife_gypsy_jackknife',520,0,'img/weapon/weapon_knife_gypsy_jackknife.png','★ Navaja Knife | Default'),
('weapon_knife_outdoor',521,0,'img/weapon/weapon_knife_outdoor.png','★ Nomad Knife | Default'),
('weapon_knife_stiletto',522,0,'img/weapon/weapon_knife_stiletto.png','★ Stiletto Knife | Default'),
('weapon_knife_widowmaker',523,0,'img/weapon/weapon_knife_widowmaker.png','★ Talon Knife | Default'),
('weapon_knife_skeleton',525,0,'img/weapon/weapon_knife_skeleton.png','★ Skeleton Knife | Default');

INSERT INTO `wp_weapons_paints` (`weapon_name`, `weapon_defindex`, `paint`, `image`, `paint_name`) VALUES
('weapon_deagle', 1, 17, 'https://raw.githubusercontent.com/ByMykel/CSGO-API/4fdf048a2b6c21494df4fe915f5fdea5accc6a61/public/images/econ/default_generated/weapon_deagle_hy_ddpat_urb_light.png', 'Desert Eagle | Urban DDPAT'),
Expand Down

0 comments on commit dc7fb18

Please sign in to comment.