Get_ammo_in_clip

http://cf.chucklesnetwork.com/items/4/8/7/3/original/not-sure-if-bug-or-feature.jpg

GET_AMMO_IN_CLIP
// 0x2E1202248937775C 0x73C100C3
// GetAmmoInClip
BOOL GET_AMMO_IN_CLIP(Ped ped, Hash weaponHash, int* ammo);

Ok, so first off, it’s a bool, not an int:

Secondly, no matter what value you put in the ‘int* ammo’ parameter, it always returns true. So I figure one of the following has happened:

  1. Someone has named it incorrectly
  2. It’s just broken
  3. It works just fine, I’m using it incorrectly, and probably need more sleep.

For the record, I’m trying to get the number of bellets left in the ped’s magazine.

Thank you.

local bool, ammo = GetAmmoInClip(GetPlayerPed(PlayerId()), hashhere)

Idk if that will work but I have seen some of these natives have 2 return values.

Ps. Make sure to fill out the hash for the weapon you wanna check. I am on my pjone so not the best place to try and write it out.

Secondly, no matter what value you put in the ‘int* ammo’ parameter, it always returns true

Yes because it is a pointer to an int value. LUA convert pointers to a return value (since LUA support multiple return types as shown by @xander1998).

I guess the bool value is false when the player doesn’t have that particular weapon.

Moved to Discussion

1 Like

Yup, I have, but thanks. @xander1998

Ok, so can I get what I’m looking for from this native? @Syntasu

RegisterCommand("ammo", function(source, args, raw)
    local selectedWeapon = GetSelectedPedWeapon(GetPlayerPed(PlayerId()))
    print("Selected Weapon: " .. selectedWeapon)

    local bool, ammo = GetAmmoInClip(GetPlayerPed(PlayerId()), selectedWeapon)

    print("Ammo: " .. ammo)
end)

Works fine for me.

But it’s a bool, how can it return an int?

local bool, ammo

It is returning 2 values not just 1.

Ha, strange. I printed it as a string and it only return a bool: 1, not a table.

I’ll give that a try, thanks.

Its not a table. It retuns a boolean and an integer

take a closer look…

local HasWeapon, AmmoInClip = GetAmmoInClip(GetPlayerPed(PlayerId()), selectedWeapon)

Two variables (HasWeapon and AmmoInClip)

GetAmmoInClip(Ped, WeaponHash) will return two values, not in a table, for example like this 1, 32

1 Like

As others have pointed out, this function returns two value instead of one. This is because the function would normally put the value into the pointer you pass it (the int *ammo) but, Lua has no concepts of pointers. Instead, the developers make these functions return the value instead.

Note: These are not tables. They are their own values being returned by the functions.

To learn more about returning multiple values in Lua, you can read here.

Wanting to know more about pointers? There’s a Wikipedia entry or an entry on turorialspoint.

Yeah, I think LUA puts it perfectly:

An unconventional, but quite convenient feature of Lua is that functions may return multiple results.

Never seen anything like it :yum:

Thanks guys.