Inventory and hotbar
The hotbar, the inventory window, death drops and lootable containers.
Players spawn with nothing: no weapons, no ammo. Any SWEP they pick up, spawn from the Q menu
or get through Player:Give goes into their inventory instead of their hands (with a "... added to
your inventory" notice). If the inventory is full, the weapon stays where it is.
A weapon whose addon has been removed from the server is deleted from inventories: when the player joins (with a notice, and a line in the server log), or when one handed over later is selected.
Hotbar #
Like Minecraft's: the first rpgx_hotbar_slots (9) inventory slots are the hotbar, shown at the
bottom of the screen. Whatever is in the selected slot (gold edge) is in your hands, and only
that; an empty slot means empty hands. Pick a slot with 1-9 / 0, the mouse wheel, or the
last-weapon key (back to the one before). GMod's own weapon selector is gone, and so is the pickup
list on the right (switching slots hands you the gun, so scrolling filled it). The item's name shows
above the hotbar for a moment after switching. The selected slot is saved.
Picked-up weapons fill the hotbar first, then the backpack; one that lands in the selected slot is in your hands right away.
The window #
Open it with I. Each player can change the key with rpgx_inventory_key in their console
(key names like i, tab, f1), or bind the rpgx_inventory command. Movement keys keep working
while it's open. It has three tabs: Inventory (what it opens on), Quests (the quest journal,
see Interactable NPCs) and Skills (the skill tree, see Levels and skills). On the Inventory tab the hotbar row is on top, the backpack (the other
slots) below.
| In the window | Does |
|---|---|
| Left click | Moves it to the other side (hotbar ↔ backpack), into the first free slot |
| Right click | Hold (selects its hotbar slot), Move to backpack / hotbar, Drop |
| Drag onto another slot | Move or swap |
- Everything keeps its slot, counts towards capacity and is saved.
- Two weapons of the same type can sit in the hotbar; switching between them swaps which one is out (GMod only allows one of a type in hand).
- Clip ammo is kept per weapon. Reserve ammo isn't: it's cleared on spawn and not saved yet.
- On death, the whole inventory drops in a container where you died: a cardboard box by
default (
rpgx_death_container_model). Anyone can press E on it and take items out one by one or all at once; it disappears when empty, or afterrpgx_death_container_lifetimeseconds if that is set (by default it stays). Clip ammo stays with each weapon. Withrpgx_death_drop 0you keep everything instead. What's in a container isn't saved: a map change or restart loses it. - A weapon in hand that disappears any other way (stripped by an admin tool, used up, dropped by another addon) is gone from the inventory as well.
- Server:
GAMEMODE:HotbarSelect( ply, slot ),GAMEMODE:InventoryHold( ply )(makes the hands match the selected slot),GAMEMODE:InventoryMove( ply, from, to )(to0 = the other side).
Consumables #
Grenades, SLAM, and later potions and the like get used up. They stack in one slot (the number in its corner), up to 5 grenades or 5 SLAMs a slot, and the stack counts down as you use them:
- Grenades and SLAM (HL2's
weapon_frag,weapon_slam): while one is in hand, your ammo for it is the stack. Throwing a grenade or placing a SLAM takes one off. The last one thrown is gone from the inventory and your hands. A SLAM whose charges are still out stays in hand at 0 as their detonator, until they've gone off. - They cost no stamina and have no spare ammo (see Guns): the stack is all there is.
- New ones (shops, rewards, pickups, containers) top up the stacks you have first, then start a new one. Dragging a stack onto another of the same kind moves over as many as fit. Dropping one drops the whole stack, and it's picked up as one. If only part of it fits, the rest stays on the ground.
- Stacks are saved with their amount, and drop with it on death.
Making one (addons): potions, food, bandages, anything used with a click, derive from
rpgx_consumable_base, e.g. lua/weapons/rpgx_potion_health.lua:
SWEP.Base = "rpgx_consumable_base"
SWEP.PrintName = "Health potion"
SWEP.Category = "RPG X"
SWEP.Spawnable = true
SWEP.RPGXMaxStack = 5 -- the most in one slot (10 if not set)
SWEP.UseSound = "items/smallmedkit1.wav"
SWEP.UseDelay = 1 -- seconds between two uses
function SWEP:CanUse( ply ) -- false (and why) = nothing happens, nothing is used up
if ( ply:Health() >= ply:GetMaxHealth() ) then return false, "You're already at full health." end
end
function SWEP:OnUse( ply )
ply:SetHealth( math.min( ply:Health() + 25, ply:GetMaxHealth() ) )
end
Every click that passes CanUse runs OnUse (server) and takes one off the stack. Using one isn't
an attack: it doesn't put you in combat. Any other SWEP can be a consumable too, with
SWEP.RPGXConsumable = true (and SWEP.RPGXMaxStack), using itself up through
GAMEMODE:InventoryConsume( ply, self.RPGXSlot, n ). Engine weapons that use ammo, like the grenade,
go in GAMEMODE.Consumables (class -> the most a slot). Server:
GAMEMODE:InventoryAdd( ply, class, nil, nil, amount ), GAMEMODE:ConsumableMax( class ) (both
sides, nil = not a consumable), and the hook RPGXConsumed( ply, class, used, left ).
Inventory size per player #
rpgx_inventory_slots is the default. To change one player's size:
rpgx_inventory_setslots <player name or SteamID> <slots|default>
Works from the server console, and for owners in their own console (the inventory_manage
permission). Online players can be named by
part of their name; offline players need a SteamID64 or STEAM_0:x:y. default goes back to
rpgx_inventory_slots. Making an inventory smaller never deletes anything: items above the new
size stay (shown red) and can be moved or dropped, but nothing new fits until there's room.
Containers (addons too) #
The death drop is a general lootable container, rpgx_container: any prop holding items that
players take with E. Loot chests and stashes can use the same thing (server):
local box = GAMEMODE:ContainerCreate( pos, angle, "models/props_junk/wood_crate001a.mdl", {
{ class = "weapon_pistol" }, -- clip1 / clip2 optional
{ class = "weapon_frag", amount = 3 }, -- consumables: how many (default 1)
{ class = "weapon_crowbar" },
}, { title = "Supply crate", removeWhenEmpty = true, lifetime = 0 } )
box:AddItem( "weapon_357" ) -- class, clip1, clip2, amount
RPGXContainerCanTake( ply, box, item ) returning false stops a player taking an item (locked
chests, owner-only drops).