Esc to clear, Enter to open the best match, click an export to open it in its page
whip_gunny

Gunny API

Server and client exports of exports.whip_gunny, and its events; add dependency 'whip_gunny' to your fxmanifest. New to it? Read Weapon System first.

Giving weapons

GiveWeapon(source, weaponName, overrides?, reason?)SERVER#

Gives a player a weapon with a new serial, set up as you say. Rounds are held to what the gun or magazine holds.

ParamTypeDescription
sourcenumberThe player's server id
weaponNamestringThe weapon item ('gunny_pistol')
overridestable?serial; attachments ({ [slot] = attachment item }); a gun with magazines: magazine (one it takes) with ammo rounds in it; a gun without: ammo; either: loaded = true fills it (with its first magazine when none is named); the jerry can: fuel, 0-100; a throwable: amount
reasonstring?Why they got it, for the activity log ('shop purchase'), as AddItem takes
Returns: true, where, serial: where is 'inventory', or 'ground' at their feet when it didn't fit; serial finds it again (give and take back), nil for a throwable. Or false, reason: an unknown weapon or magazine, a magazine or attachment the gun doesn't take, or AddItem's own refusal (a player not loaded)
exports.whip_gunny:GiveWeapon(source, 'gunny_pistol', { loaded = true })
exports.whip_gunny:GiveWeapon(source, 'gunny_pistol', { serial = 'LSPD00000042', magazine = 'gunny_mag_pistol_extended', ammo = 10 })
GiveMagazine(source, magName, ammo?, reason?)SERVER#

Gives a player a magazine with rounds in it, held to what it holds.

ParamTypeDescription
sourcenumberThe player's server id
magNamestringThe magazine item ('gunny_mag_pistol')
ammonumber?Rounds in it: none is empty, and any number past its size fills it (its size can change on the Items page)
reasonstring?Why they got it, for the activity log
Returns: true, where, serial as GiveWeapon (the magazine's own serial), or false, reason: an unknown magazine, or AddItem's own refusal
exports.whip_gunny:GiveMagazine(source, 'gunny_mag_pistol', 999)   -- full, whatever its size

Weapon packs

RegisterWeapon(item, def) / RegisterMagazine(item, def)SERVERCLIENT#

A weapon pack's gun or magazine, on both sides, inside Gunny.register (@whip_gunny/lib/pack.lua). def is an entry shaped like gunny's items/weapons.lua or items/magazines.lua, checked as gunny's own are; a weapon may add attachments ({ [slot] = { [kind] = component } }). Register its magazines first; the same pack registering again replaces its own.

Returns: true, or false, reason: a missing field, an unknown caliber or magazine, a name of gunny's own or another pack's

Client#

There's no export to open a gun's magazine slot: it's a panel item, opened by the gun's whip_gunny:open_weapon action.

IsWeaponDrawn()CLIENT#

Whether one of gunny's weapons is in the player's hands. To follow it rather than ask, listen for whip_gunny:weapon:drawn / :holstered.

Returns: boolean
GetDrawnWeapon()CLIENT#

A copy of the weapon in the player's hands: { item, label, kind, slot, pocket, serial, ammo, capacity, magazine, attachments }, or nil. The count is live (a HUD).

FieldTypeDescription
kindstring'gun', 'melee', 'throwable' or 'fuelCan'
ammonumberA gun's rounds, a throwable's stack, the jerry can's petrol as GTA counts it (0 to 4500, not the item's 0-100%), 0 for melee
capacitynumber|nilThe most a gun holds: its magazine's size, or the rounds a gun with no magazine takes. nil with no magazine in, and for anything else
magazinestring|nilThe magazine's item name ('gunny_mag_pistol')
Returns: table|nil
local w = exports.whip_gunny:GetDrawnWeapon()
if w and w.kind == 'gun' and w.ammo == 0 then
    exports.whip_core:Notify(('Your %s is empty'):format(w.label), 'info')
end
DrawWeapon(slot, pocket?)CLIENT#

Draws the weapon in a pocket slot, with its animation, putting away another drawn one first. Waits: call it from a thread. To put a weapon away, call whip_core's FreeHands().

ParamTypeDescription
slotnumberThe slot
pocketstring?'player' (default) or 'accessory'
Returns: true (drawn, or already was), or false, reason: the hands blocked, a reload under way, the server refused
local ok, why = exports.whip_gunny:DrawWeapon(3)
Not during a reload. From the press until the reload ends (not only while the animation plays) it returns false and the gun stays out. A death, or BlockHands, still puts it away at once.
LoadBullets(slot, pocket?)CLIENT#

Fills the magazine in a pocket slot from the rounds carried, behind the server's bar (300 ms a round), and tells the player how it went. One magazine at a time; waits, so call it from a thread.

ParamTypeDescription
slotnumberThe magazine's slot
pocketstring?'player' (default) or 'accessory'
Returns: true, rounds loaded (a load stopped partway keeps what went in), or false, reason: 'Busy' (another bar is up), 'Magazine is full', no rounds carried, 'Loading cancelled'
UnloadBullets(slot, pocket?, count?)CLIENT#

Empties the magazine in a pocket slot into the pockets as rounds, or count of them, and tells the player. Waits: call it from a thread.

ParamTypeDescription
slotnumberThe magazine's slot
pocketstring?'player' (default) or 'accessory'
countnumber?How many (default: all)
Returns: true, rounds unloaded, or false, reason: it's empty, no room for the rounds
ApplyWeaponAttachments(ped, hash, item, attachments)CLIENT#

Fits a gun's attachments on any ped holding it (an NPC, a display), turning attachments as the gun's metadata has them ({ [slot] = attachment item }) into the GTA components that gun takes. The ped must hold the weapon first.

Returns: nothing
GiveWeaponToPed(npc, `WEAPON_PISTOL`, 12, false, true)
exports.whip_gunny:ApplyWeaponAttachments(npc, `WEAPON_PISTOL`, 'gunny_pistol', { muzzle = 'gunny_suppressor' })

Events#

For a police alert, evidence or a Director card, listen with AddEventHandler rather than watching the ped (naming rule).

EventSidePayload
whip_gunny:weapon:drawnServer{ source, item, kind, serial, slot, pocket }: kind is 'gun', 'melee', 'throwable' or 'fuelCan'
whip_gunny:weapon:holsteredServer{ source, item, serial, slot, pocket, reason }, once however it went: reason is 'holstered', 'moved' (it left its slot), 'replaced', 'logout' or 'dropped'
whip_gunny:weapon:firedServer{ source, item, serial, shots, ammo, coords }, each time the server takes rounds off a drawn gun (every shot fired). ammo is what's left; coords is nil once the shooter has gone
whip_gunny:weapon:drawnClientThe GetDrawnWeapon() table
whip_gunny:weapon:holsteredClient{ item, slot, pocket }

The client has no per-shot event: see the rounds on your HUD.