Jump to content

Bug with getWeaponAmmo ?


nic062

Recommended Posts

Hello Everybody,

I think there is a problem with the function getWeaponAmmo when it's used with a custom weapon created with createWeapon. It seems that the function always return 0.

Here is an example :

  
local theWeapon 
  
  
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), function() 
    theWeapon = createWeapon("m4", 1, 1, 3) 
    setWeaponOwner(theWeapon, localPlayer) 
    setWeaponClipAmmo(theWeapon, 10) 
    setWeaponAmmo(theWeapon, 90) 
end) 
  
  
function handleCustomWeapon() 
    if getKeyState("mouse1") then 
        setWeaponState(theWeapon, "firing") 
    else 
        setWeaponState(theWeapon, "ready") 
    end 
    dxDrawText("getWeaponClipAmmo = "..getWeaponClipAmmo(theWeapon).."\ngetWeaponAmmo = "..getWeaponAmmo(theWeapon), 100, 200) 
    setControlState("fire", false) 
end 
addEventHandler("onClientPreRender", getRootElement(), handleCustomWeapon) 
  

Can you confirm me or explain why my script doesn't work.

Cordialy.

ps : I use

Link to comment
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), function() 
    theWeapon = createWeapon("m4", 1, 1, 3) 
    setWeaponOwner(theWeapon, localPlayer) 
    setWeaponClipAmmo(theWeapon, 10) 
    setWeaponAmmo(theWeapon, 90) 
end) 
  
  
function handleCustomWeapon() 
    if getKeyState("mouse1") then 
        setWeaponState(theWeapon, "firing") 
    else 
        setWeaponState(theWeapon, "ready") 
    end 
    dxDrawText("getWeaponClipAmmo = "..getWeaponClipAmmo(theWeapon).." \n getWeaponAmmo = "..getWeaponAmmo(theWeapon), 100, 200) 
    setControlState("fire", false) 
end 
addEventHandler("onClientPreRender", getRootElement(), handleCustomWeapon) 

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