Monster Spawning Madness

So I have this in the after entering room section:

if (RandomChance(12)) {
  SpawnSentret (this)
}
else if (RandomChance(12)) {
  SpawnHoothoot (this)
}

But it doesn't work the way I want it to. It's supposed to be an equal 12 and 12 spawn rate, but the Sentret spawns first since it's first. Also I can't just use "if" 'cause that leaves the chance of spawning both a Hoothoot and a Sentret, when I only want one.

Any thoughts?


I don't see what you are trying to do...
Is it a 1 in 12 chance that a Sentret spawns?
AND, a 1 in 12 chance that a Hoothoot spawns?
That is what it looks like to me.
Oh... 1 in 12 for a Sentret...
if no Sentret, then a 1 in 12 chance for a Hoothoot...
Maybe hit this from a different angle...
1 in 12 chance for a creature, then roll for what creature is seen...
IE:
chance=RandomChance(12)
if (chance=1){ // then there is a creature...
cr=RandomChance(2)
if (cr=1){
SpawnSentret(this)
}
else if (cr=2){
SpawnHoothoot(this)
}

or use a switch for a longer list of creatures.


POST REMOVED BECAUSE THE CODE WAS INCORRECT


Where did you guys get 1/12 from? KV, did you copy DarkLizerd? (Also, sorry for the 12\12. I changed it.)

I want a 12% chance for them both. That's 12/100 and 12/100.

I originally had it as:

if (RandomChance(12)) {
  SpawnSentret (this)
}
if (RandomChance(12)) {
  SpawnHoothoot (this)
}

(I actually had a lot more monsters, but I'm simplifying it here.) But sometimes it would spawn both at once.

(As I said, I have more monsters. A few pages had the chance of spawning 10 monsters, 5% chance each. I once spawned 3 monsters at once.)


misinformation removed


Apparently, DL and I separately assumed that same incorrect thing.


http://docs.textadventures.co.uk/quest/functions/corelibrary/randomchance.html

The effect is that if use RandomChance(10), there is a 10% chance of the function returning true, RandomChance(50) has a 50% chance of returning true, etc

Okay... You're right about the percentage, jmne. Sorry about that!


if (RandomChance(12)) {
  SpawnSentret (this)
}
if (RandomChance(12)) {
  SpawnHoothoot (this)
}

That looks right.

That should give you a 12% chance of getting a Sentret and a 12% chance of getting a Hoothoot, and one does not depend upon the other.

Change them from 12 to 100 to test it. Each one will definitely spawn that way, and it would prove that part of the script works.


doing this:

if (RandomChance (12)) {
  SpawnSentret (this)
} else if (RandomChance (12)) {
  SpawnHoothoot (this)
}

will roughly be:

12% chance of spawning a sentret
if no sentret spawned, then 12% chance of hoothoot spawning

in terms of the actual math of it, the hoothoot won't be '12%', as it's a 88% (100-12=88) and then a 12% chance, but I hate math, I think it was 'mrangel' or maybe 'Dark Lizard' doing whatever the calculation and actual percentage would be something else as its a bit more complicated due to the math of it... which I could not follow (HK hates math!)


doing this would be a little better, though it's still not exact as again the math makes it more complicated:

if (RandomChance (12)) { // this is for determining if a monster spawns
  if (RandomChance (50)) { // this (along with its matching 'else') is for determining which of the (two) monsters, spawn
    SpawnSentret (this)
  } else { // (the matching 'else')
    SpawnHoothoot (this)
  }
}

if you got more than 2 monsters to select between, then using 'GetRandomInt' for choosing which monster is selected, and then 'RandomChance' for whether it actually spawns or not, is really useful for this type of selection of spawns/drops, hehe:

monster_objectlist_variable = NewObjectList ()
list add (monster_objectlist_variable, orc)
list add (monster_objectlist_variable, ogre)
list add (monster_objectlist_variable, troll)
list add (monster_objectlist_variable, goblin)
list add (monster_objectlist_variable, gremlin)
list add (monster_objectlist_variable, cyclops)

selected_monster_object_variable = ObjectListItem (monster_objectlist_variable, GetRandomInt (0, ListCount (monster_objectlist_variable) - 1))

if (RandomChance (12)) {
  spawn_monster_function (selected_monster_object_variable)
}

result=DiceRoll("1d12") 
if (result = 1) {
SpawnSentret (this)
}
else if (result = 2) {
SpawnHoothoot (this)
}
else {
msg ("Luckily, nothing is spawning right now!")
}

If you want them to have the same probability, you need to adjust the later ones. So your first one is RandomChance(12), and the second is divided by the chance of the first one not happening, so RandomChance(12*100/88).

Or avoid the maths by using a single random number, as people suggested. I'd probably end up with something more like:

spawn = PickOneString(Split("Sentret;Hoothoot:nothing;nothing;nothing;nothing",";"))
if (not spawn = "nothing") {
  SpawnMonster(spawn, this)
}

ah, you just divide the number... if I can just remember that now... lol

wait... so you're actually just multiplying the percents:

(12/100) = 12.00% drop/spawn one
if drop/spawn one fails:
(88/100) * (12/100) = ~ 10.56% drop/spawn two

so, to make them both equal percents (@12%) ...

(88/100) * (13/100) = ~ 11.44%
(88/100) * (14/100) = ~ 12.32%

so...

RandomChance (12) for sentret = 12%
and
RandomChance (14) for hoothoot = ~ 12%

(12/100) / 88 = RandomChance (~13.64) = 12% for hoothoot


No, no no no no no no no no no no no no no no no no no no no no no no no no...
I might as well test out the roll thing...

roll = GetRandomInt(1,100)
if (roll > 0 and roll < 13) {
  SpawnSentret (this)
}
if (roll > 12 and roll < 25) {
  SpawnHoothoot (this)
}

I was wanting something simpler, with less typing, though.


Nobody?


I though you had this...
Sometimes, there is no getting around the typing, but there can be shortcuts...


this is the shortest way to do it:

(you can use your own names/labels, making them short, unlike mine)
(all you need is an ObjectList Attribute holding your monster objects that you want to be spawn'able)

randomly_selected_monster_spawn_object_variable = ObjectListItem (monster_spawn_objectlist_variable, GetRandomInt (0, ListCount (monster_spawn_objectlist_variable) - 1))

if (RandomChance (12)) {
  monster_spawn_function (randomly_selected_monster_spawn_object_variable)
}

I think this is what you want (similar to DarkLizerd's suggestion, above)...

// This simulates a percentile dice roll:
Spawn = GetRandomInt(1,100)
if (Spawn >=1 and Spawn <= 12) {
  msg (Spawn + " = Sentret spawned!")
}
else if (Spawn >= 13 and Spawn <= 24) {
  msg (Spawn + " = Hoothoot spawned!")
}
else {
  msg (Spawn + " = Nothing spawned.")
}

Alright, question.
What do I do with this? I get a syntax error from it.

roll = GetRandomInt(1,100)
firsttime {
  if (roll > 0 and < 86) {
    SpawnSentret (this)
  }
}
otherwise {
  if (roll > 0 and < 61) {
    SpawnSentret (this)
  }
}

What is the error that you get?


...otherwise { ... ???
Works for English, not so much for Quest...
I think you want an "else if" there...


@DL
It's a firsttime script. It needs otherwise.

@Dcoder
This.

Error running script: Error compiling expression 'roll > 0 and < 86': SyntaxError: Unexpected token "<"; expected one of "NOT", "-", <INTEGER>, <REAL>, <STRING_LITERAL>, "True", "False", <HEX_LITERAL>, <CHAR_LITERAL>, "null", <DATETIME>, <TIMESPAN>, "(", <IDENTIFIER>, "if", or "cast"Line: 1, Column: 14

Haven't come across that command before...


@DarkLizerd
Okay. C'est la vie.


firstime{
  //do something
}
otherwise{
  //do something else
}

is correct. (It was new to me when I saw XanMag do it not too long ago.)


I can't test it, but I think you need:

if (roll > 0){
  if(roll < 86){
    //Spawn something
  }
  else if (roll < 61 ){
    //Spawn something
  }
}

I just got it, so nevermind. I forgot the "roll"...

roll = GetRandomInt(1,100)
firsttime {
  if (roll > 0 and roll < 86) {
    SpawnSentret (this)
  }
}
otherwise {
  if (roll > 0 and roll < 61) {
    SpawnSentret (this)
  }
}

Log in to post a reply.

Support

Forums