L2BoxInstance
What is it ?
Boxes are NPC that represent a kind of store with six drawers where you can put items.
It is used like a shared warehouse, but the content is dependant on the box instance,
just like a physical box.
The NPC for example a treasure box is put somewhere on the map and one or more
characters get access to it. When the box is selected an html menu will present the
drawers and the items stored there. Access rights are given by admins and all
characters who have access can store and withdraw items.
That way it can be used as another kind of clan box as well as a storage for a
character who collects a lot. Without access privileges you cannot take a look into drawers.
Just like a physical box you cannot access it from different places but have to go to it,
open it, put something in it or take something out.
The access rights act like a key and everybody with a key can do the same with the box.
A box can store an infinite number of items.
How is it implemented ?
Any NPC is identified by an ID, instances of this NPC have a spawn id and
while the server is up there is an object id. As every player can have a treasure box
(i.e. instances of the same NPC) the spawn id is taken to identify a box not the NPC id.
The object id would also be unique but changes after the server is restarted.
Each NPC is represented by a row in the npc table and belongs to a type like
L2Merchant, L2Trainer, etc. For boxes a new type L2Box was introduced.
This type makes the server spawn instances as an L2BoxInstance with the associated logic.
On a click (function onAction()) it shows an html page with the commands to
store and withdraw items. The html interface was chosen to circumvent the limit a trade
or warehouse list has. The traditional lists cannot have more than a certain number of
different items due to the size limit of the packages used by the server and the client.
There is no possibility to split the content of a warehouse into multiple pages,
it will always show you the complete content. With html pages we are free and can have
a multiple page design and thus reach the goal of unlimited space.
The content is stored in a database table boxes and the names of the characters who
have access are stored together with the spawn id in the table boxaccess.
Admins can control the box instance by creating (spawning) it and add users to the
boxaccess using the admin command box_access.
Source code: source:trunk/L2_Gameserver/java/net/sf/l2j/gameserver/model/L2BoxInstance.java
How to …
spawn a box?
To spawn a box pick an NPC and change its type to L2Box in the npc database table.
There are treasure chests, a strong wooden chest and a supply box that suit
for a box representation. 1042 is one of the IDs that can be used.
The changed npc table has to be read by the server so you may have to restart it after that change.
In the game place your admin character wher the box should reside, target yourself and spawn the NPC using the admin menu or with a command like: spawn 1042
get the first page displayed?
The first click will issue a chat command like with any other NPC. To display the box menu put an html page in your data folder under html/default/<npc-id>.htm. You can use this page or create a new one to your liking.
change access?
Target the box and type: box_access This command without parameters shows a list of characters that can use this box. Append character names seperated by a blank to the command to grant access or prefix the character names with "no" to remove the access right. Example: box_access Adam Eve no Kain will grant access to Adam and Eve and remove it for Kain.
identify the items in the box?
The items are listed with their names taken out of the database i.e. server-side. This may be different to what the client shows e.g. in the inventory. If there is an item name that gives no hint what it is you may want to change the name in the database.
