View Single Post
  #6  
Old 10-18-2011, 12:01 AM
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
You don't even need to use client-side or a timeout to spawn trash at all.

DB

PHP Code:
function onCreated() {
  
// Configuration
  
this.max_trash = 20;
  
// Initialize Trash DB
  
destroyTrash();
  
spawnTrash();
}

function 
destroyTrash() {
  
// Loop through each piece of Trash
  
for (temp.trash: this.spawned_trash) {
    
// Destroy Trash NPC
    
temp.trash.destroy();
  }
  
// Initialize Spawned Trash Array
  
this.spawned_trash = {};
}

function 
spawnTrash() {
  
// Spawn Trash until Maximum Reached
  
while (this.spawned_trash.size() < this.max_trash) {
    
// Create Trash
    
temp.trash = createTrash();
    
// Add Trash to DB
    
this.spawned_trash.add(temp.trash);
  }
}

function 
createTrash() {
  
// Create Trash NPC
  
temp.trash = putnpc2();
  
temp.trash.join("trash");
  return 
temp.trash;
}

public function 
trashInDB(obj) {
  return (
obj in this.spawned_trash);
}

public function 
pickedUpTrash(obj) {
  
// Remove and Destroy Trash
  
this.spawned_trash.remove(obj);
  
obj.destroy();
  
// Spawn More Trash
  
spawnTrash();
} 
Class: trash

PHP Code:
function onPlayerEnters() {
  
// Check if Trash in DB
  
if (!TrashDB.trashInDB(this)) {
    
// Not found so destroy it
    
destroy();
  }
}

function 
onActionGrab() {
  
// Notify DB of Trash Picked Up
  
TrashDB.pickedUpTrash(this);
} 
__________________
Quote:

Last edited by fowlplay4; 10-18-2011 at 12:17 AM..
Reply With Quote