K4-Arenas icon indicating copy to clipboard operation
K4-Arenas copied to clipboard

[FEATURE] Get player weapon preferences using API

Open Letaryat opened this issue 6 months ago • 1 comments

If possible it would be very helpful for people who make custom rounds to gather information about player weapon preferences using API instead creating a new database connection and query.

I created something like this and it works fine but maybe there is a other, better way to do so:

        public Dictionary<string, CsItem?> GetPlayerWeaponPreferences(CCSPlayerController player)
        {
            var arenaPlayer = plugin.Arenas?.FindPlayer(player);

            if (arenaPlayer == null)
            {
                return new Dictionary<string, CsItem?>();
            }

            var playerWeapons = new Dictionary<string, CsItem?>()
	    {
                { "Rifle", arenaPlayer.WeaponPreferences[WeaponType.Rifle] },
                { "Sniper", arenaPlayer.WeaponPreferences[WeaponType.Sniper] },
                { "SMG", arenaPlayer.WeaponPreferences[WeaponType.SMG] },
                { "LMG", arenaPlayer.WeaponPreferences[WeaponType.LMG] },
                { "Shotgun", arenaPlayer.WeaponPreferences[WeaponType.Shotgun] },
                { "Pistol", arenaPlayer.WeaponPreferences[WeaponType.Pistol] },
            };

	    return playerWeapons;
        }

Letaryat avatar May 13 '25 05:05 Letaryat