Update WeaponPaints.cs

This commit is contained in:
Nereziel
2023-11-07 22:56:13 +01:00
parent 78d1b7d89a
commit 44d0ed5999

View File

@@ -1,5 +1,6 @@
using CounterStrikeSharp.API.Core; using CounterStrikeSharp.API;
using MySqlConnector; using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Entities;
using Nexd.MySQL; using Nexd.MySQL;
namespace WeaponPaints; namespace WeaponPaints;
@@ -8,7 +9,7 @@ public class WeaponPaints : BasePlugin
public override string ModuleName => "WeaponPaints"; public override string ModuleName => "WeaponPaints";
public override string ModuleDescription => "Connector for web-based player chosen wepaon paints."; public override string ModuleDescription => "Connector for web-based player chosen wepaon paints.";
public override string ModuleAuthor => "Nereziel"; public override string ModuleAuthor => "Nereziel";
public override string ModuleVersion => "0.2"; public override string ModuleVersion => "0.3";
MySqlDb? MySql = null; MySqlDb? MySql = null;
public override void Load(bool hotReload) public override void Load(bool hotReload)
@@ -27,27 +28,17 @@ public class WeaponPaints : BasePlugin
var weapon = new CBasePlayerWeapon(entity.Handle); var weapon = new CBasePlayerWeapon(entity.Handle);
if (!weapon.IsValid) return; if (!weapon.IsValid) return;
if (weapon.AttributeManager.Item.AccountID < 0) return; var pawn = new CBasePlayerPawn(NativeAPI.GetEntityFromIndex((int)weapon.OwnerEntity.Value.EntityIndex!.Value.Value));
var playerIndex = (int)pawn.Controller.Value.EntityIndex!.Value.Value;
//Log($"AccountID {weapon.AttributeManager.Item.AccountID}");
//Log($"playerSteam {playerId}"); int weaponPaint = GetPlayersWeaponPaint(playerIndex, weapon.AttributeManager.Item.ItemDefinitionIndex);
var playerId = ConvertToSteam64(weapon.AttributeManager.Item.AccountID);
int weaponPaint = GetPlayersWeaponPaint(playerId.ToString(), weapon.AttributeManager.Item.ItemDefinitionIndex);
if (playerId == 0) return;
if (weaponPaint == 0) return; if (weaponPaint == 0) return;
weapon.AttributeManager.Item.AccountID = unchecked((uint)271098320);
weapon.AttributeManager.Item.ItemIDLow = unchecked((uint)-1); weapon.AttributeManager.Item.ItemIDLow = unchecked((uint)-1);
weapon.AttributeManager.Item.ItemIDHigh = unchecked((uint)-1); weapon.AttributeManager.Item.ItemIDHigh = unchecked((uint)-1);
weapon.FallbackPaintKit = weaponPaint; weapon.FallbackPaintKit = weaponPaint;
weapon.FallbackSeed = 0; weapon.FallbackSeed = 0;
weapon.FallbackWear = 0.0001f; weapon.FallbackWear = 0.0001f;
} }
private Int64 ConvertToSteam64(uint id)
{
uint account_type = id % 2;
uint account_id = (id - account_type) / 2;
return 76561197960265728L + (account_id * 2) + account_type;
}
private static void Log(string message) private static void Log(string message)
{ {
Console.BackgroundColor = ConsoleColor.DarkGray; Console.BackgroundColor = ConsoleColor.DarkGray;
@@ -55,12 +46,18 @@ public class WeaponPaints : BasePlugin
Console.WriteLine(message); Console.WriteLine(message);
Console.ResetColor(); Console.ResetColor();
} }
public int GetPlayersWeaponPaint(string steamId, int weaponDefIndex) public int GetPlayersWeaponPaint(int playerSlot, int weaponDefIndex)
{ {
try try
{ {
CCSPlayerController player = Utilities.GetPlayerFromSlot(playerSlot);
if (player == null || !player.IsValid)
return 0;
var steamId = new SteamID(player.SteamID);
MySqlQueryCondition conditions = new MySqlQueryCondition() MySqlQueryCondition conditions = new MySqlQueryCondition()
.Add("steamid", "=", steamId) .Add("steamid", "=", steamId.SteamId64.ToString())
.Add("weapon_defindex", "=", weaponDefIndex); .Add("weapon_defindex", "=", weaponDefIndex);
MySqlQueryResult result = MySql!.Table("wp_player_skins").Where(conditions).Select(); MySqlQueryResult result = MySql!.Table("wp_player_skins").Where(conditions).Select();