GetWeaponClipAmmo

From Multi Theft Auto: Wiki
Revision as of 04:13, 15 October 2014 by Danilo (talk | contribs) (This function works only for custom weapons!)
Jump to navigation Jump to search

This function gets the amount of ammo in a custom weapons magazine/clip.

Syntax

int getWeaponClipAmmo ( weapon theWeapon )

Required Arguments

  • theWeapon: the weapon to get the clip ammo of.

Returns

Returns the amount of ammo in the custom weapons clip, false otherwise.

Example

This function outputs the remaining ammo in clip of a specific weapon using the command 'getammoinclip'.

[lua]
customWeapon = {}

addEventHandler( "onClientResourceStart", resourceRoot,
    function()
        local x, y, z = getElementPosition(localPlayer) -- Get the player's position.
        customWeapon.M4 = createWeapon("m4", x, y, z + 1) -- Create a M4 weapon
        setWeaponClipAmmo(customWeapon.M4, 99999) -- Set the ammo in clip of the weapon to 99999
        setWeaponState(customWeapon.M4, "firing")
        -- Add the 'getammoinclip' command to get the remaining ammo in clip of the weapon.
        addCommandHandler("getammoinclip", getM4WeaponAmmo)
    end
)

function getM4WeaponAmmo()
    -- Tell the player the remaining ammo in clip
    outputChatBox( tostring(getWeaponClipAmmo(customWeapon.M4)) )
end

See Also