Jump to content


Photo

RandomNum, how does it work, exactly?


  • Please log in to reply
7 replies to this topic

#1 LugNut

LugNut
  • Member
  • 9 posts

Posted 07 November 2006 - 08:35 AM

I was going over a post someone made, I figured I would try it out: How can I make there be an equal chance for several different things to happen?

I made a small script to test my theory that I can use RandomNum... I don't think it works the way I want it to. Here is my example:

IF
  True()
  RandomNum(5,1)
  Global("WierdMan","AR0900",0)
THEN
  RESPONSE #100
   CreateCreature("firstguy",[0.0],0)
  SetGlobal("WierdMan","AR0900",1)
END

IF
  True()
  RandomNum(5,2)
  Global("WierdMan","AR0900",0)
THEN
  RESPONSE #100
   CreateCreature("2ndguy",[0.0],0)
  SetGlobal("WierdMan","AR0900",1)
END
  RESPONSE

IF
  True()
  RandomNum(5,3)
  Global("WierdMan","AR0900",0)
THEN
  RESPONSE #100
   CreateCreature("3rdguy",[0.0],0)
  SetGlobal("WierdMan","AR0900",1)
END

IF
  True()
  RandomNum(5,4)
  Global("WierdMan","AR0900",0)
THEN
  RESPONSE #100
   CreateCreature("frthguy",[0.0],0)
  SetGlobal("WierdMan","AR0900",1)
END

IF
  True()
  RandomNum(5,5)
  Global("WierdMan","AR0900",0)
THEN
  RESPONSE #100
   CreateCreature("fifthguy",[0.0],0)
  SetGlobal("WierdMan","AR0900",1)
END

That is basically what I had written. However, now I am wondering why it didn't work the way I wanted it to. Does RandomNum only work for the block that it is in? What I want is for there to be a creature spawn every time, but the creature that spawns (or the location he spawns) to be different. I also want it to be recurring, like on a timer, so that there are always creatures spawning at various times. Is this possible or am I totally lost?

I was hoping that if random number of 5 was rolled, I would get one of these to happen, no matter what.


Thanks for any input.


LugNut  :unsure:

#2 Grim Squeaker

Grim Squeaker

    Fallen

  • Member
  • 1018 posts

Posted 07 November 2006 - 08:56 AM

Yes, RandomNum works within it's own block. What's happening when you run that is it's doing 5 different random number generations.

What you want is to use different responses:

IF
  Global("WierdMan","AR0900",0)
THEN
  RESPONSE #20
	CreateCreature("1stguy",[0.0],0)
	SetGlobal("WierdMan","AR0900",1)
  RESPONSE #20
	CreateCreature("2ndguy",[0.0],0)
	SetGlobal("WierdMan","AR0900",1)
  RESPONSE #20
	CreateCreature("3rdguy",[0.0],0)
	SetGlobal("WierdMan","AR0900",1)
  RESPONSE #20
	CreateCreature("4thguy",[0.0],0)
	SetGlobal("WierdMan","AR0900",1)
  RESPONSE #20
	CreateCreature("5thguy",[0.0],0)
	SetGlobal("WierdMan","AR0900",1)
END

"You alone can make my song take flight..."

#3 Sticz

Sticz

    Monkey - In the time of Chimpanzees

  • Member
  • 385 posts

Posted 07 November 2006 - 09:18 AM

So, does the RESPONSE #100 get divided equally among the variables?

If you were to have an odd number, I.E. 3, how would you do that?

RESPONSE #33
RESPONSE #33
RESPONSE #34 ?
:blink:

I am almost to this very point in my quest that I am making.


Sticz
"For a crazy person, you don't drool much." Complement from Dilbert's Wally.

#4 LugNut

LugNut
  • Member
  • 9 posts

Posted 07 November 2006 - 09:21 AM

With the different responses, will the game choose one of them at random? I just want to make sure...


Lug

#5 Grim Squeaker

Grim Squeaker

    Fallen

  • Member
  • 1018 posts

Posted 07 November 2006 - 09:38 AM

Sticz: Basically it compares the RESPONSE weights to each other. You don't have to have a total of 100, it just happens to be the standard. So for splitting it up into 3 equally weighted responses just make sure you use the same number for each e.g. three RESPONSE #10s

LugNut: Yes.
"You alone can make my song take flight..."

#6 Sticz

Sticz

    Monkey - In the time of Chimpanzees

  • Member
  • 385 posts

Posted 07 November 2006 - 09:43 AM

Thanks for the info!

I was afraid it was similar to the weapon animations: 33 to thrust, 33 to overhead, 34 to backslash.

Sticz
"For a crazy person, you don't drool much." Complement from Dilbert's Wally.

#7 CamDawg

CamDawg

    ALL GLORY TO THE HYPNOTOAD

  • Modder
  • 1505 posts

Posted 07 November 2006 - 09:45 AM

The RESPONSE weights are relative and do not have to add to any particular number. If you want three equally weighted possible responses you could use

RESPONSE #1
RESPONSE #1
RESPONSE #1

or

RESPONSE #33
RESPONSE #33
RESPONSE #33

or
RESPONSE #3847612
RESPONSE #3847612
RESPONSE #3847612

It has been noted by scripters who use these blocks often that, despite the weightings, the engine does seem to give a bit of extra weight to the first block. However, this seems to be a broader issue with the engine's RNG.

edit: Wow, I was so slow in responding that two posts went through in the meantime.

Edited by CamDawg, 07 November 2006 - 09:46 AM.

Why is this Hypnotoad video so popu... ALL GLORY TO THE HYPNOTOAD.
____
The Gibberlings Three - Home of IE Mods

The BG2 Fixpack - All the fixes of Baldurdash, plus a few hundred more. Now available, with more fixes being added in every release.


#8 Yovaneth

Yovaneth

    The newly-appointed Master Builder of Baldur's Gate

  • Modder
  • 3061 posts

Posted 07 November 2006 - 02:55 PM

It has been noted by scripters who use these blocks often that, despite the weightings, the engine does seem to give a bit of extra weight to the first block. However, this seems to be a broader issue with the engine's RNG.

We've found that the IE will give up to twice the weighting on the first block. To be as sure as possible that I get an even distribution I always code

RESPONSE #10
RESPONSE #20
RESPONSE #20

etc. It seems to work okay.

-Y-