Thread: Chest class
View Single Post
  #5  
Old 10-09-2011, 07:09 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
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.
__________________
Quote:
Reply With Quote