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);
}