I'm busy with nodejs a bit for modding a game, but I'd like to know how to do something like this:
var zombieDirector =
{
zombieBison = 1
zombieChicken = 2
zombie = 3
skeleton = 3
}
and those names have another var like
var zombieBison = 'Entities/Zombies/zombieBison.cfg'
and now make the Bison spawned rare and skeleton and zombie more often.
you get this, where randomZombie equals to 'Entities/Zombies/aZombie.cfg'
ks.map.spawnEntity('zombie', randomZombie, 0, 0, 3);
I can't get any further than
var randomZombie = zombieDirector[Math.floor(Math.random() * zombieDirector.length)];
On another note: No JQuery please
Thanks in advance
In essence, you're talking about weighted random number generation. A little tricky, if you want to use math, but you can do it with an array, like this:
var choices = [];
for(prop in zombieDirector) {
for(var i = 0; i<zombieDirector[prop]; i++) {
choices.push(prop);
}
}
var choice = choices[Math.floor(Math.random() * choices.length + .5)];
The variable choice will now have a random monster name, weighted based on the number you provide in zombieDirector.