Jump to content

[HELP]getWeaponAmmo and getWeaponClipAmmo not working


Recommended Posts

Hi guys! I want to make script that tell me how much ammo left in my gun , but the getweaponAmmo is not working :/ 

The script: 

function ammoRender ()
 local ammo = getWeaponAmmo(theWeapon)
 local clip = getWeaponClipAmmo(theWeapon)
 
 dxDrawText(ammo .. "|" .. clip, 1600/oX*x, 100/oY*y, _, _, _, 2/oX*x, "pricedown", "left", "top")
end
addEventHandler("onClientRender", root, ammoRender)

Link to comment

I'm really unsure if that would work, but you could try: 

If it doesn't work, try with local theWeapon = getPlayerWeapon ( source )

function ammoRender ()
 local ammo = getWeaponAmmo(theWeapon)
 local clip = getWeaponClipAmmo(theWeapon)
 
 dxDrawText(''..ammo .. '|' ..clip..'', 1600/oX*x, 100/oY*y, _, _, _, 2/oX*x, "pricedown", "left", "top")
end
addEventHandler("onClientRender", root, ammoRender

 

Edited by Galactix
Link to comment
1 hour ago, DarkMagic said:

Not working :/ Debugscript said :[ERROR]script\client.lua:382:attempt to call local 'clip' (a boolean value)

The wiki says getWeaponClipAmmo is used for custom weapons, but doesn't seem to work with weapons from GTA:SA. I suggest you make a table with all the weapon IDs and their clip with a variable that would get the clip number and show it on the screen.

1 hour ago, DarkMagic said:

Not working :/ Debugscript said :[ERROR]script\client.lua:382:attempt to call local 'clip' (a boolean value)

The wiki says getWeaponClipAmmo is used for custom weapons, but doesn't seem to work with weapons from GTA:SA. I suggest you make a table with all the weapon IDs and their clip with a variable that would get the clip number and show it on the screen.

 

To get an idea of this, it would look like: 

local weaponClip = {
[22] = {17}, --colt
 [23] = {17}, --silenced
  [24] = {7}, --deagle
   [25] = {1}, --shotgun
    [26] = {2}, --sawed-off
     [27] = {7}, --spaz
   [28] = {50}, --uzi
    [29] = {30}, --mp5
     [30] = {30}, --ak47
   [31] = {50}, --m4
    [32] = {50}, --tec9
     [33] = {1}, --rifle
   [34] = {1}, --sniper rifle
  	[37] = {50} --flamethrower
    [38] = {500} --minigun
  [41] = {500} --spraycan
    [41] = {500} --spraycan
    [42] = {500} --fire extinguisher
    [43] = {36} --camera
}

--And the variable you would put to replace your current clip one would be:

local clip = weaponClip [ getPedWeapon (source)]

You would also have to specify the rest of the weapons but I've normally stated all the weapons that do have a clip, the others are like explosives and others so you'd have to add them to the table or also you could just use a if statement that would check if the weapon clip displayed is from a weapon from the table or if it's not (which means it would be melee or throwable) then just display 1 for the clip.

I can't seem to be able to edit my previous post for some reasons, but I just wanna say that I forgot some "," in the table which would get you an error, so dont forget to add them for the lines that do miss one except for the last one.

Link to comment

Try this:

function ammoRender ()
    local total = getPedTotalAmmo( localPlayer )
    local clip = getPedAmmoInClip( localPlayer )

    dxDrawText(clip..' | '..(total-clip), 1600/oX*x, 100/oY*y, _, _, _, 2/oX*x, "pricedown", "left", "top")
end
addEventHandler("onClientRender", root, ammoRender)

 

Edited by Mr.Loki
Link to comment

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...