Skip to main content

WeaponSlot, WeaponMode and AmmoType

These tables describe a player's weapons: which inventory slot a weapon is in (WeaponSlot), which of its two firing modes you mean (WeaponMode), and which ammunition pool you mean (AmmoType). Use them to give, remove and inspect weapons and ammo.

Available on: Server, Client

Values​

WeaponSlot​

A player carries up to one weapon per slot.

Used by (see PlayerObjectHandle):

  • player:GetWeaponName(slot), player:GetWeaponAmmo(slot, mode) (server and client)
  • player:GiveWeapon(name, ammo, slot), player:RemoveWeapon(slot), player:SetWeaponAmmo(slot, mode, ammo) (server)

These functions accept the four slots below (the integers 0 to 3). Anything else raises the Lua error invalid weapon slot <n>.

NameValueMeaning
WeaponSlot.Primary0The primary weapon slot.
WeaponSlot.Secondary1The secondary weapon slot.
WeaponSlot.Heavy2The heavy weapon slot.
WeaponSlot.HandGrenade3The hand grenade slot, for thrown weapons such as w301_frag_grenade.

WeaponMode​

Every weapon has a primary and a secondary fire mode (in Just Cause 4 most weapons have an alternate fire), each with its own loaded ammo.

Used by (see PlayerObjectHandle):

  • player:GetWeaponAmmo(slot, mode) (server and client)
  • player:SetWeaponAmmo(slot, mode, ammo) (server)

Any value other than 0 or 1 raises the Lua error invalid weapon mode <n>.

NameValueMeaning
WeaponMode.Primary0The weapon's primary fire.
WeaponMode.Secondary1The weapon's secondary (alternate) fire.

AmmoType​

A player's spare ammunition is kept per ammo type, shared by every weapon that uses that type.

Used by (see PlayerObjectHandle):

  • player:GetInventoryAmmo(type) (server and client)
  • player:SetInventoryAmmo(type, ammo) (server)

Any value outside 0..44 raises the Lua error invalid ammo type <n>. Which weapon uses which type is decided by the game's weapon data; see the weapons list.

NameValueMeaning
AmmoType.Pistol0Pistol ammo.
AmmoType.Shotgun1Shotgun shells.
AmmoType.SMG2Submachine gun ammo.
AmmoType.AssaultRifle3Assault rifle ammo.
AmmoType.CombatRifle4Combat rifle ammo.
AmmoType.MachineGun5Machine gun ammo.
AmmoType.Sniper6Sniper rifle ammo.
AmmoType.Rockets7Rockets for rocket launchers.
AmmoType.Explosives8Explosives.
AmmoType.HandGrenade9Hand grenades.
AmmoType.GrenadeLauncher10Grenade launcher grenades.
AmmoType.SunGun11Sun gun ammo.
AmmoType.MissileStrike12Missile strikes.
AmmoType.Unlimited13Used by weapons with unlimited ammunition.
AmmoType.Beacon14Beacons.
AmmoType.NoAmmo15Used by weapons that use no ammunition.
AmmoType.Flare16Flares.
AmmoType.EMP17EMP ammo.
AmmoType.Mine18Mines.
AmmoType.Battery19Batteries.
AmmoType.TripwireMine20Tripwire mines.
AmmoType.Railgun21Railgun ammo.
AmmoType.Arrows22Arrows.
AmmoType.MiniRockets23Mini rockets.
AmmoType.ConcussionGrenade24Concussion grenades.
AmmoType.SmokeGrenade25Smoke grenades.
AmmoType.AttackDrone26Attack drones.
AmmoType.GuardDrone27Guard drones.
AmmoType.ExplosiveBullets28Explosive bullets.
AmmoType.StormGrenade29Storm grenades.
AmmoType.AirCartridge30Air cartridges.
AmmoType.BurstRifle31Burst rifle ammo.
AmmoType.RocketsAOC32Rockets, AOC weapon variant.
AmmoType.AssaultRifleAOC33Assault rifle ammo, AOC weapon variant.
AmmoType.ShotgunAOC34Shotgun shells, AOC weapon variant.
AmmoType.SniperAOC35Sniper rifle ammo, AOC weapon variant.
AmmoType.MachineGunAOC36Machine gun ammo, AOC weapon variant.
AmmoType.DlcSlot137Ammo slot reserved for DLC weapons (1).
AmmoType.DlcSlot238Ammo slot reserved for DLC weapons (2).
AmmoType.DlcSlot339Ammo slot reserved for DLC weapons (3).
AmmoType.DlcSlot440Ammo slot reserved for DLC weapons (4).
AmmoType.DlcSlot541Ammo slot reserved for DLC weapons (5).
AmmoType.DlcSlot642Ammo slot reserved for DLC weapons (6).
AmmoType.DlcSlot743Ammo slot reserved for DLC weapons (7).
AmmoType.DlcSlot844Ammo slot reserved for DLC weapons (8).

Example

-- server: give a joining player a loadout, then set their ammo
Event.Add("OnPlayerJoin", function(client)
local player = client:GetPlayer()
if not player then
return
end

player = player:AsPlayer()

player:GiveWeapon("wpn_000_assault_rifle", 240, WeaponSlot.Primary)
player:GiveWeapon("wpn_022_shotgun", 40, WeaponSlot.Secondary)
player:SetWeaponAmmo(WeaponSlot.Secondary, WeaponMode.Primary, 8)
player:SetInventoryAmmo(AmmoType.AssaultRifle, 500)

print(client:GetName() .. " has " .. player:GetInventoryAmmo(AmmoType.AssaultRifle) .. " spare rifle rounds")
end)