Weapon
Utility function for reading the player's current weapon state.
getCurrentWeaponInfo
Returns information about the weapon the ped currently has equipped.
local info = KOJA.Client.getCurrentWeaponInfo(ped)
| Parameter | Type | Description |
|---|---|---|
ped | number | Ped entity handle |
Returns table | nil
| Field | Type | Description |
|---|---|---|
weaponHash | number | Hash of the current weapon |
ammoInClip | number | Bullets remaining in the current magazine |
totalAmmo | number | Total ammo carried for this weapon |
Returns nil if the ped has no weapon equipped.
Example
local ped = PlayerPedId()
local info = KOJA.Client.getCurrentWeaponInfo(ped)
if info then
print('Weapon hash:', info.weaponHash)
print('Clip ammo:', info.ammoInClip)
print('Total ammo:', info.totalAmmo)
else
print('No weapon equipped')
end
With weapon name lookup:
local info = KOJA.Client.getCurrentWeaponInfo(PlayerPedId())
if info then
local name = GetDisplayNameFromVehicleModel(info.weaponHash) -- works for weapons too
print('Equipped:', name)
end
Related pages
- Getting Started — Configuration and Installation for Getting Started.
- API Reference — Client API and Server API for API Reference.
- Frameworks — Custom Framework and Overview for Frameworks.
- Inventory — Custom Inventory and Overview for Inventory.
- Text UI — A small on-screen prompt that shows an action key and a label.
- Vehicle — Utility functions for reading vehicle state on the client.