SCRMaps
/
Sign in

An inventory

Keeping the item catalogue separate from the inventory, and slicing one array across every player.

8 min read

An inventory is two pieces of data: the catalogue of every item in the game, and what each player is currently carrying. Mix them together and every change to an item means editing the inventory code as well.

Fill the catalogue once in onPluginStart. Keep it as an array of structs, addressed by number.

object Item_ {
    var index, type, name, weight;
    var text, buy, sell, lv;
};
const Item_List = EUDArray(20);

// type 1 = 장비 / equipment   2 = 소모품 / consumable
// type 3 = 재료 / material    4 = 퀘스트 / quest
type carries its weight because every rule below branches on it: equipment is one per slot, consumables and materials stack.

There is a low ceiling on how many fields an object can have. One mapper reports eight; the official compiler test asserts that alloc() on a class with eleven is an error. Rather than trust a number, build it before the design depends on it - and when you run out, splitting the struct in two is the usual answer.

The inventory itself only needs the item number and a count: the details come out of the catalogue by number. So one argument is enough for a function - you never pass type, name and price around.

Nor do you need an inventory per player. Slice one array by the number of slots.

const SLOTS = 5;
const Inven = EUDArray(SLOTS * 8);      // 8명분 / room for eight players

const base = getcurpl() * SLOTS;        // 1p -> 0, 2p -> 5, 3p -> 10 ...
Inven[base + 0];                        // 이 플레이어의 첫 칸 / this player's first slot
The player's current index times the slot count is where their slice starts. Inside a player loop that one line separates everybody.

The order you search in matters more than it looks. Look for an empty slot first and the same item ends up scattered across several of them.

  1. 1First look through every page for the item already being held. If it is there, add one to the count and stop.
  2. 2Only then look for an empty slot, and put it in the first one.
  3. 3If there is no empty slot the pickup fails. Tell the player: silently vanishing is the worst outcome.

Keep the page and slot number in variables while you search. Without them you run the same loop a second time to do the insert. Equipment skips step one because it never stacks; consumables and materials take a new slot only when a stack is full.

Draw the panel with a StringBuffer and take the keys through MSQC. Three variables are enough: on/off, the current page, and a cooldown. Without the cooldown one keypress toggles the inventory every cycle.

Detecting a button press with the build queueobject: making a struct
Sign in to track your progress