Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
  • 0
Nevander

Random spawn script is not random

Question

So I'm trying to make some scripts where a monster will randomly be one of several possible spawn IDs. I set up an array that looks like

 

int monsters[8] = {T_ZOMBIE, T_SHOTGUY, T_IMP, T_HELLKNIGHT, T_BARON, T_MANCUBUS, T_CACODEMON, T_PAINELEMENTAL};

 

And then in the script I'm doing

 

Thing_SpawnFacing(tid, monsters[Random(0, 7)], 0, 0);

 

But for some reason it's not being truly random at run time. What I mean is, it seems to get randomized per map session and always in the same order which is really confusing me.

 

Three scripts do this, and as an example let's say the first script spawns Cacodemons, the second spawns Imps and the third spawns Zombiemen. That's fine, except if I load and try again I get the IDENTICAL order every single time without fail. I can even run script 2 first instead but I still get Cacodemons first.

 

What bullshittery is this?

Share this post


Link to post

6 answers to this question

Recommended Posts

  • 0

No idea how you managed it or how to fix it, but it sounds like you've got GZDoom to use a static seed, thus you'll get the exact same random results as long as nothing else interferes with the RNG that ACS uses.

 

That's assuming you are using GZDoom, anyway. If you're using a port that both supports ACS and uses the vanilla Doom RNG, then a static seed is expected and the only thing you can do is make sure the player sees some action before using random(), so stuff like pre-placed monsters and the player's weapons can forward the RNG.

Share this post


Link to post
  • 0

This is probably overcomplicated, but you could use a different variable per script to maintain some semblance of random spawns, but what @Arctangent says is solid. The RNG is calling for the random, then returning whatever number it receives every time, so your scripts are random, but only at first, and they go on like clockwork.

Share this post


Link to post
  • 0

If the issue is the vanilla PRNG, you might find that waking a monster (a lost soul safely contained outside the playable area is the best option) beforehand fixes the problem.

Share this post


Link to post
  • 0
On 5/8/2018 at 7:25 AM, Arctangent said:

No idea how you managed it or how to fix it, but it sounds like you've got GZDoom to use a static seed, thus you'll get the exact same random results as long as nothing else interferes with the RNG that ACS uses.

No idea how or why that would even be possible. I didn't do anything to the seed generation nor know of anything on the user end that could modify it.

Share this post


Link to post
  • 0
On 5/8/2018 at 11:57 AM, Grain of Salt said:

If the issue is the vanilla PRNG, you might find that waking a monster (a lost soul safely contained outside the playable area is the best option) beforehand fixes the problem.

Just tried it, still got the same identical result no matter which of the three scripts were ran first or when the enemy was awakened.

Share this post


Link to post
  • 0

Ok I figured out a fix that seems to work well. It instantly gave me better results.

 

I just threw three variables into a looping OPEN script that call Random separately every second. Then (at random) the player does the thing and it will use whatever the next number happens to be.

 

I still don't think it's actually truly random but at least it's not predetermined what will spawn every time.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×