Use a DB-NPC to store chest contents instead of serverr flags.
You can do that like this:
PHP Code:
function onCreated() {
this.db = YourDatabaseNPCsName;
if (!this.chest_id) {
echo("Chest created in " @ this.level.name @ " without chest id!");
destroy();
}
}
function onActionAddItem(item) {
// Make sure item is in chest
if (item in getItems()) {
// Remove weapon from chest
takeItem(item);
// Add weapon to player
player.addweapon(item);
}
}
function onActionTakeItem(item) {
// Make sure the item isn't already in chest
if (!(item in getItems())) {
// Remove weapon from Player
player.removeweapon(item);
// Add item to chest
addItem(item);
}
}
/* Chest functions to interact with database */
function getItems() {
return this.db.("chest_" @ this.chestid);
}
function addItem(item) {
this.db.("chest_" @ this.chestid).add(item);
}
function takeItem(item) {
this.db.("chest_" @ this.chestid).remove(item);
}
then when you add chests to levels:
PHP Code:
function onCreated() {
this.chest_id = "someuniqueid";
join("your_chest_class");
}
You'll have to update how you send the chest data to the client though.