What I am trying to accomplish is a script that spawns trash across the gmap and then the trash is pickupable but my script(s) seem to have an issue.
They seem to be spawning WAY more than its supposed to.
Anyway here are the scripts.
The npc trashspawner
PHP Code:
function onCreated() {
this.spawntime = 0.05;
onTimeout();
}
function onTimeout() {
if (server.trashspawned > 10) {
server.trashspawned = 10;
}
if (server.trashspawned < 10) {
onSpawning();
}
settimer(this.spawntime);
}
function onSpawning() {
this.spawn = int(random(1, 6));
if (this.spawn == "1") {
this.item = "Tire";
this.itemimage = "bc_trash-tire.png";
}
if (this.spawn == "2") {
this.item = "Bottle";
this.itemimage = "bc_trash-bottle.png";
}
if (this.spawn == "3") {
this.item = "Paper";
this.itemimage = "bc_trash-paper.png";
}
if (this.spawn == "4") {
this.item = "Motherboard";
this.itemimage = "bc_trash-motherboard.png";
}
if (this.spawn == "5") {
this.item = "Soda";
this.itemimage = "bc_trash-sodacan.png";
}
if (this.spawn == "6") {
this.item = "Wires";
this.itemimage = "bc_trash-wires.png";
}
if (server.trashspawned < 10) {
temp.spawnx = random(0, 448);
temp.spawny = random(0, 448);
temp.t = putnpc2(temp.spawnx, temp.spawny, null);
temp.t.itemimage = this.itemimage;
temp.t.itemname = this.item;
temp.t.join("gunderak_trashdrop");
}
}
The class gunderak_trashdrop
PHP Code:
function onCreated() {
if (server.trashspawned > 10) {
destroy();
}
setshape(1, 32, 32);
setimg(this.itemimage);
}
function onActionGrab() {
client.trash += 1;
server.trashspawned -= 1;
triggerclient("gui", "-System/Message", "msg", "Server", "You gained [" @ this.itemname @ "]! You now have: " @ client.trash @ " Trash!", "orange");
destroy();
}
//#CLIENTSIDE
function onCreated() {
if (server.trashspawned > 10) {
destroy();
}
triggerserver("weapon", "-System/Trash", "spawn");
dontblock();
drawunderplayer();
setshape(1, 32, 32);
if (onwall(this.x, this.y)) {
destroy();
triggerserver("weapon", "-System/Trash", "unspawn");
}
}
The weapon -System/Trash
PHP Code:
function onActionServerSide() {
if (params[0] == "unspawn") {
if (server.trashspawned > 0) {
server.trashspawned--;
}
}
if (params[0] == "spawn") {
if (server.trashspawned < 10) {
server.trashspawned++;
}
}
}
Any help is appriciated

PS: yes I know im probably doing this completely wrong, I cannot think of any other way to accomplish my goal.
If you would like put in an easier way your more than welcome.