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
Gives a player a weapon with a new serial, set up as you say. Rounds are held to what the gun or magazine holds.
| Param | Type | Description |
|---|---|---|
| source | number | The player's server id |
| weaponName | string | The weapon item ('gunny_pistol') |
| overrides | table? | 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 |
| reason | string? | Why they got it, for the activity log ('shop purchase'), as AddItem takes |
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 })
Gives a player a magazine with rounds in it, held to what it holds.
| Param | Type | Description |
|---|---|---|
| source | number | The player's server id |
| magName | string | The magazine item ('gunny_mag_pistol') |
| ammo | number? | Rounds in it: none is empty, and any number past its size fills it (its size can change on the Items page) |
| reason | string? | Why they got it, for the activity log |
true, where, serial as GiveWeapon (the magazine's own serial), or false, reason: an unknown magazine, or AddItem's own refusalexports.whip_gunny:GiveMagazine(source, 'gunny_mag_pistol', 999) -- full, whatever its size
Weapon packs
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.
true, or false, reason: a missing field, an unknown caliber or magazine, a name of gunny's own or another pack'sClient#
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.
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.
booleanA 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).
| Field | Type | Description |
|---|---|---|
| kind | string | 'gun', 'melee', 'throwable' or 'fuelCan' |
| ammo | number | A 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 |
| capacity | number|nil | The 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 |
| magazine | string|nil | The magazine's item name ('gunny_mag_pistol') |
table|nillocal 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
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().
| Param | Type | Description |
|---|---|---|
| slot | number | The slot |
| string? | 'player' (default) or 'accessory' |
true (drawn, or already was), or false, reason: the hands blocked, a reload under way, the server refusedlocal ok, why = exports.whip_gunny:DrawWeapon(3)
false and the gun stays out. A death, or BlockHands, still puts it away at once.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.
| Param | Type | Description |
|---|---|---|
| slot | number | The magazine's slot |
| string? | 'player' (default) or 'accessory' |
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'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.
| Param | Type | Description |
|---|---|---|
| slot | number | The magazine's slot |
| string? | 'player' (default) or 'accessory' | |
| count | number? | How many (default: all) |
true, rounds unloaded, or false, reason: it's empty, no room for the roundsFits 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.
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).
| Event | Side | Payload |
|---|---|---|
whip_gunny:weapon:drawn | Server | { source, item, kind, serial, slot, pocket }: kind is 'gun', 'melee', 'throwable' or 'fuelCan' |
whip_gunny:weapon:holstered | Server | { 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:fired | Server | { 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:drawn | Client | The GetDrawnWeapon() table |
whip_gunny:weapon:holstered | Client | { item, slot, pocket } |
The client has no per-shot event: see the rounds on your HUD.