Notes on the Inventory System


The items.dat is a list of the bins that will be in a player's inventory. These bins hold a flex (real) value. Only players have an inventory - actors do not. The verbs in this section set or retrieve the properties of bins.

A typical bin in the items.dat looks like this:

#name    ID     min  max  flags bin's cog
fists    1      0    1    0x024 cog=weap_fists.cog
Bin properties:

Name
Bin ID
Min
Max
Flags
Cog
Available
Activated


The Name of a Bin

The name of a bin in the items.dat is only used if the bin has an icon. All bins flagged as an item or force power must have an icon, or JK will crash. The Hotkey Tutorial explains how to give a bin an icon.

The ID of a Bin

All bins have an ID number that is used to refer to the bin. If the bin's number is 60, then GetInv(player, 60) is used to find the amount held by that bin. In JK, the last bin used by LEC was 115. So if you create a new bin, you should start where they left off and create bin 116, then 117, and so on.

Bins don't have to be in order of number, and you can skip numbers. I.e., you could create bin 120 in the middle of the items.dat and it would work correctly (though your hotkeys may be messed up).

The Minimum Value

The minimum value of a bin is the amount that you will always have in it. So if you set the minimum of bin 60 to 100, then you would always have 100 shields. SetInv() and ChangeInv() cannot set the value of a bin below the minimum of a bin.

Say a bin has a minimum of 10 and a current value of 20. When SetInv() sets the value of that bin to 0, the value of the bin will be reduced to 10 because the bin value cannot be set below the minimum. Use GetInvMin() to return the minimum bin value.

The Maximum Value

The maximum value is the most you can have in a bin. If SetInv() or ChangeInv() tries to set the value of the bin over its max limit, then the bin will be given the maximum value. Use GetInvMax() to return the maximum bin value.

The Flags of a Bin

A bin's flags tell the engine whether the bin is a hotkey, force power, weapon, or item and decide what messages the bin should receive. These flags are optional. A bin with only placeholder flags (0x000) will simply hold a value. Use SetInvFlags() to set a bin's flags through Cog. Read the Inventory Flags document in the Flags section for a description of each flag.

A Bin's Cog

A bin's cog performs a different function depending on the flags of the bin. If the bin is flagged as a weapon, then the cog will act as a weapon cog and process messages like selected, deselected, and fire for the weapon. Cogs listed in the items.dat also receive messages from the local player. When you need to send a message to a cog via SendMessage(), you will need a reference to it. Assigning a cog to a bin and using GetInvCog() is the easiest way to get a reference to the cog. Assigning a cog to a bin is optional.

Available

When a bin is available, the item of that bin is usable. You can have an amount greater than zero in the bin, and yet it won't be available. Availability makes forces and items show up in their selection boxes. Use IsInvAvailable() to check if the bin is available or not. A bin must be available for its hotkey to work. If a force or item is available, but you don't have anything in the bin, the selection boxes will flicker when they view the force or item; however, the cog will still work.

Activated

When a bin is "activated," its icon (if it has one) will be displayed in the top-right corner of the screen. Use SetInvActivated() to activate or deactivate the bin. Use IsInvActivated() to check if the bin is activated or not. The verb, SetBinWait(), is used to pause the activation of a bin until a delay has ended.