Page 1 of 1

Decimals (percentage lower than 1%) and last weapon used function

Posted: Sat Sep 19, 2015 1:30 am
by Psycho
I don't know if this is an actual limitation that the doom engine has, or its just my big noobish when it comes to coding stuff, but here we go.

How can someone use decimals for monsters/weapons replacement chances (e.g. complex doom). I mean, when trying to code something really OP to spawn, I can't see to make a spawn chance lower than 1% possible. Tried using 0.01 and 0,01 and even 1/100, but none of them seen to work for me.

Is it even possible to use decimals for such a thing, and how could I make it work properly? If it's not possible, then what is problem with implementing such an apperrent trivial thing?

On a side note, I wonder why does zandronum doesn't have a last weapon used option for when configurating the controls, and if it's possible to code it (would be better to have it as a standart option in the menu).

RE: Decimals (percentage lower than 1%) and last weapon used function

Posted: Sat Sep 19, 2015 1:49 am
by Ænima
It depends how you're spawning the actors in question. If you're using the DropItem property of a RandomSpawner then just increase the "weight" of all the other actors listed in that spawner.


If it's decorate you can do something like this:

TNT1 AA 0 A_Jump(255, "NotPowerfulMonster")
TNT1 A 0 A_spawnitemex(powerful monster here)

That means that in order to make it to that SpawnItemEx call, you have a 1/65536 chance of making it past the A_jump calls because they are both 255/256 chances of jumping away from the super-OP-monster-spawning state and there's 2 of them in a row. Pretty simple.

Edit: math mistake

RE: Decimals (percentage lower than 1%) and last weapon used function

Posted: Sat Sep 19, 2015 11:24 am
by Dusk
That actually has 1/256 · 1/256 = 1 / 256² = 1/65536 ≈ 0.0015% to spawn. You can't just sum denominators together, go learn some math.

RE: Decimals (percentage lower than 1%) and last weapon used function

Posted: Sat Sep 19, 2015 1:49 pm
by Ivan
Psycho wrote: I don't know if this is an actual limitation that the doom engine has, or its just my big noobish when it comes to coding stuff, but here we go.

How can someone use decimals for monsters/weapons replacement chances (e.g. complex doom). I mean, when trying to code something really OP to spawn, I can't see to make a spawn chance lower than 1% possible. Tried using 0.01 and 0,01 and even 1/100, but none of them seen to work for me.

Is it even possible to use decimals for such a thing, and how could I make it work properly? If it's not possible, then what is problem with implementing such an apperrent trivial thing?

On a side note, I wonder why does zandronum doesn't have a last weapon used option for when configurating the controls, and if it's possible to code it (would be better to have it as a standart option in the menu).
Dusk wrote: That actually has 1/256 · 1/256 = 1 / 256² = 1/65536 ≈ 0.0015% to spawn. You can't just sum denominators together, go learn some math.
Ouch, denominator sum op.

Anyway, I'd rather use Randomspawners as Decorate jump statement blocks (notice, not just one jump involved if you have more than 2 monsters) can lead to some weird chances of spawning. With randomspawner, you have the option to give it a weight, which is effectively the chance to spawn in this case. See this:

Code: Select all

Actor MySpawner : Randomspawner {
    DropItem "HellKnight", 255, 16
    DropItem "BaronofHell", 255, 16
    DropItem "Cyberdemon", 255, 1
}
In here, the Cyberdemon effectively has a chance of 1/33 to spawn. Using this, you can achieve your percentages easily. You just have to figure out your weights. For instance, a 0.1% is effectively a 1 / 1000, so you can just have weights be 499, 500, 1 to achieve that. (There is an unequal chance of having Baron and Hellknight now, yes, but you know it's better than nothing) The rest have 499/1000 and 500/1000 (which is 50% effectively for both) chance to spawn.

Altenratively you can use ACS to handle all your spawning. That way you can have more power through some if statements to check if your random value is in the desired range.

RE: Decimals (percentage lower than 1%) and last weapon used function

Posted: Sat Sep 19, 2015 2:46 pm
by Ænima
Dusk wrote: That actually has 1/256 · 1/256 = 1 / 256² = 1/65536 ≈ 0.0015% to spawn. You can't just sum denominators together, go learn some math.
Easy bro, easy. I know, math was never my strong suit. I had a feeling it was actually squared and not just doubled because hitting 1/256 twice in a row should be like super rare but oh well. The method I was trying to tell him is still valid advice, though.

RE: Decimals (percentage lower than 1%) and last weapon used function

Posted: Sat Sep 19, 2015 5:54 pm
by Lollipop
Well, if you want a completely even distribution between barons and hellknights, then you can use the number 2 for the cyberdemon and fit the other numbers. 0.1% = 2/2000.
Cyberdemon: 2
Baron: 999
Hellknight: 999

That way they are easily distributed with the same chance to spawn the cyberdemon.
Not a big deal, but whatever.