Jump to content

Check if player has weapon


Recommended Posts

- How to check if player is carrying a specific weapon
- How to check how much ammo he is carrying


Hello, i hope that this is the right subforum for my problem.

I am trying to make an armory where players can take and put weapons/ammo. The "take" is working fine, but I don't find a way to check (on server-side) if a player carries the weapon he wants to put in and how much ammo he is carrying, so when a player wants to put a weapon in the armory, i don't know if hes actually carrying the weapon.

In the wiki i have found:

  • Player::getWeaponAmmo (not working with weapon hash, always returns 0)
  • Player::weaponAmmo (don't know how to use)
  • Player::weapons (don't know how to use)
  • Player::allWeapons (returns "{}")


(i'm not a native english speaker, so please have indulgence)

Edited by paccoderpster
Link to comment
Share on other sites

Send the request event to the client, get the data, then bounce back to the server with the data. Use these natives;

mp.game.invoke("0x8DECB02F88F428BC", mp.players.local.handle, mp.game.joaat("weapon_SpecialCarbine"), 0); //Check specific weapon

mp.game.invoke("0x015A522136D7F951", mp.players.local.handle, mp.game.joaat("weapon_SpecialCarbine")); //Check ammo count on weapon

  • Like 1
Link to comment
Share on other sites

  • 3 weeks later...

I'm trying to save players' weapons on DC and load them when player reconnects. Tested this way, however, it doesn't seem to work reliably: for some weapons it works, but for most, it doesn't. For instance, for pistol it works perfectly, but for the same SpecialCarbine it returns 0's. While I hold SpecialCarbine in hand and test it for specialcarbine_mk2, it returns correct ammo count.

I've tried using hashes plainly, same result. I don't think I'm messing anything up though.

Any other way to save player weapons?



Link to comment
Share on other sites

Found a list of weaponSlots, cycling through them, checking for weapon and then checking for ammo with natives, then parsing the same in the list. Works somewhat ok, but again, not for all weapons. Seems like weaponslot list isn't up to date - missing newer weapons. Cannot seem to find a better one though.

Tried gettings the slot ids with  GET_WEAPONTYPE_SLOT(Hash weaponHash) but it returns 0s for most of the newer weapons. Ridiculous.

const localPlayer = mp.players.local;
const weaponSlots = new Set([1993361168,1277010230,932043479,690654591,1459198205,195782970,-438797331,896793492,495159329,-1155528315,-515636489,-871913299,-1352759032,-542958961,1682645887,-859470162,-2125426402,2067210266,-538172856,1783244476,439844898,-24829327,1949306232,-1941230881,-1033554448,320513715,-695165975,-281028447,-686713772,347509793,1769089473,189935548,248801358,386596758,-157212362,436985596,-47957369, 575938238]);

function getWeaponTypeInSlot (weaponSlot) {
	return mp.game.invoke('0xEFFED78E9011134D', localPlayer.handle, weaponSlot);

function getAmmoWeapon (weaponhash) {
	return mp.game.invoke('0x015A522136D7F951', localPlayer.handle, weaponhash);

function getAllWeapons() {
    const weapons = {};
    weaponSlots.forEach(weaponSlot => {
        const weapon = getWeaponTypeInSlot(weaponSlot);
        if (weapon !== 0) {
            weapons[weapon] = { ammo: getAmmoWeapon(weapon) };
    return weapons;


Edited by togn
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...