Announcement: Be excellent to each other.


Caravel Forum : DROD RPG Boards : RPG Architecture : pRNG (pseudo Random Number Generator)
New Topic New Poll Post Reply
Poster Message
Casebier
Level: Master Delver
Avatar
Rank Points: 270
Registered: 08-03-2005
IP: Logged
icon pRNG (0)  
Okay, so I coded a psuedo-Random Number Generator into DROD RPG... now what should I do with it? :-)

____________________________
Casebier
--------------------------------
Revisiting old Project: ZelDROD 1 / ZelDROD RPG (If I can ever find the custom graphic files that I made for it.)

[Last edited by Casebier at 11-06-2009 10:56 PM]
11-05-2009 at 10:11 PM
View Profile Send Private Message to User Show all user's posts Quote Reply
RoboBob3000
Level: Smitemaster
Avatar
Rank Points: 1914
Registered: 10-23-2003
IP: Logged
icon Re: pRNG (0)  
Share the code?

____________________________
http://beepsandbloops.wordpress.com/
11-05-2009 at 10:38 PM
View Profile Send Private Message to User Show all user's posts This architect's holds Quote Reply
Casebier
Level: Master Delver
Avatar
Rank Points: 270
Registered: 08-03-2005
IP: Logged
icon Re: pRNG (+1)  
Fairly simple code that I attached to a NPC. The first three lines are just there to prepare the NPC for the RNG. The code could be simplified one line by using 'Seed' instead of 'RNG2', but I did it this way to make it easier to understand. The final modulus returns a number between 0 and ( operand - 1 ).
Yes, the initial number could go negative, if you don't set the seed early enough in the game. Either that, or check to make sure RNG1 is positive when it gets set.

I couldn't remember where I saw the maximum number allowed in DRPG, so I used 8191 and 131071 instead of 131071 and 524287.

Ctrl+B-able code follows:
Click here to view the secret text


____________________________
Casebier
--------------------------------
Revisiting old Project: ZelDROD 1 / ZelDROD RPG (If I can ever find the custom graphic files that I made for it.)
11-06-2009 at 12:35 AM
View Profile Send Private Message to User Show all user's posts Quote Reply
Casebier
Level: Master Delver
Avatar
Rank Points: 270
Registered: 08-03-2005
IP: Logged
icon Re: pRNG (0)  
Just realized how to protect against overflow on the initial RNG1...

Seed = _TotalTime % 131071

Only way it will overflow now is if the player waits a LONG time before reaching turn #10. :D

____________________________
Casebier
--------------------------------
Revisiting old Project: ZelDROD 1 / ZelDROD RPG (If I can ever find the custom graphic files that I made for it.)
11-06-2009 at 11:04 PM
View Profile Send Private Message to User Show all user's posts Quote Reply
Mechadragon
Level: Delver
Avatar
Rank Points: 61
Registered: 10-30-2004
IP: Logged
icon Re: pRNG (0)  
What pRNG implementation is it based on, or did you play with numbers until you made it work?
11-09-2009 at 06:18 AM
View Profile Send Private Message to User Send Email to User Show all user's posts Quote Reply
Casebier
Level: Master Delver
Avatar
Rank Points: 270
Registered: 08-03-2005
IP: Logged
icon Re: pRNG (+1)  
Drats, I can't find the page anymore that showed me how to code a pRNG. It's the method that uses Mersenne Primes (a number that is 2^N - 1 and prime).

It had code in both Assembly and C (or was it Java?), and I was able to figure out how it was going about the process from that other code. Of course, they never made it as easy as I did in my code.

____________________________
Casebier
--------------------------------
Revisiting old Project: ZelDROD 1 / ZelDROD RPG (If I can ever find the custom graphic files that I made for it.)

[Last edited by Casebier at 11-10-2009 03:46 AM]
11-10-2009 at 03:28 AM
View Profile Send Private Message to User Show all user's posts Quote Reply
Niborius2
Level: Roachling
Rank Points: 12
Registered: 01-07-2015
IP: Logged
icon Re: pRNG (+2)  
Sorry for reviving a very old topic, but I figured it would be cool if I could make a kind of gamble machine, that would always cost like 50 greckles and it will randomly raise the player's ATK and DEF from 1 to 10. So you may be unlucky and only raise 1 point for each, or if you're lucky you got the whole 10 points for both.

How would I make something like that?

I hope this post gets seen and that there are still people playing this game ^^

Thanks in advance!
01-07-2015 at 04:09 PM
View Profile Send Private Message to User Show all user's posts Quote Reply
Nuntar
Level: Smitemaster
Avatar
Rank Points: 3236
Registered: 02-20-2007
IP: Logged
icon Re: pRNG (0)  
The above script generates a random number between 1 and 100 in the variable RNG3. If you want to raise the player's ATK and DEF by a random amount from 1 to 10, you could add these lines:

Set var ATKGain = RNG3 / 10
Set var DEFGain = RNG3 % 10
Set var _ATK + ATKGain
Set var _DEF + DEFGain

However, players will always be able to save and try again until they get the best outcome, so use this with care :P

____________________________
50th Skywatcher
01-07-2015 at 07:47 PM
View Profile Send Private Message to User Show all user's posts High Scores This architect's holds Quote Reply
Niborius2
Level: Roachling
Rank Points: 12
Registered: 01-07-2015
IP: Logged
icon Re: pRNG (0)  
Thanks for your quick reply! I thought I was the only one still playing this game :)

And I won't have to worry about players mis-using the save function because I'll only have direct friends play my hold and I'll watch them as they play.
01-07-2015 at 09:31 PM
View Profile Send Private Message to User Show all user's posts Quote Reply
Niborius2
Level: Roachling
Rank Points: 12
Registered: 01-07-2015
IP: Logged
icon Re: pRNG (0)  
I'm trying to get this to work with an altar, but it seems to break my whole Altar. The script runs as far as asking the question to the player, and then nothing happens and the altar no longer works. Any ideas? Here is the whole script:

Label Altar
  Wait for entity Player 7,7,7,7
  Answer option "Some ATK (5 ATK - 200 greckles)",ATK
  Answer option "Some DEF (6 DEF - 160 greckles)",DEF
  Answer option "Play Casino Game",Casino
  Question Would you like to buy something?
Label ATK
  If ... 
        Wait until var "_GR" < 200
     Speech "Not enough money!",Normal,Self,0,.
     Go to end
  If End 
  Set var "_GR" - 200
  Set var "_ATK" + 5
  Speech "Attack upgraded!",Normal,Self,0,.
  Go to end
Label DEF
  If ... 
        Wait until var "_GR" < 160
     Speech "Not enough money!",Normal,Self,0,.
     Go to end
  If End 
  Set var "_GR" - 160
  Set var "_DEF" + 6
  Speech "Defense upgraded!",Normal,Self,0,.
  Go to end
Label Casino
  Set var "Seed" = _TotalTime
  Set var "RNG1" = Seed * 8191
  Set var "RNG2" = RNG1 % 131071
  Set var "RNG3" = RNG2 % 100
  Set var "Seed" = RNG2
  Wait 0
  Set var "ATKGain" = RNG3 / 10
  Set var "DEFGain" = RNG3 % 10
  Set var "_ATK" = + ATKGain
  Set var "_DEF" + DEFGain
  Go to end
Label end
  Wait while entity is Player 7,7,7,7
  Go to Altar


01-08-2015 at 11:12 AM
View Profile Send Private Message to User Show all user's posts Quote Reply
Nuntar
Level: Smitemaster
Avatar
Rank Points: 3236
Registered: 02-20-2007
IP: Logged
icon Re: pRNG (0)  
Firstly, take out "Wait 0". The purpose of "Wait 0" is to avoid a script trying to run a loop twice in the same turn, which will make it stop running altogether. Your "Wait while entity is Player at (7,7)" / "Wait for entity Player at (7,7)" serves the same purpose, making "Wait 0" redundant.

Secondly, Set var "_ATK" = + ATKGain should be Set var "_ATK" + ATKGain, i.e. when you double-click on the command, "Add" should be selected on the sub-menu, and the far right text box should contain "ATKGain".

Don't forget to add a cost for playing the casino game, otherwise the player can gain infinite stats!

One final thing. Currently, the ATK and DEF gains range from 0 to 9, not 1 to 10. If you want 1 to 10, simply change Set var "_ATK" + ATKGain to Set var "_ATK" + ATKGain + 1 and similarly with DEF.

____________________________
50th Skywatcher
01-08-2015 at 02:07 PM
View Profile Send Private Message to User Show all user's posts High Scores This architect's holds Quote Reply
New Topic New Poll Post Reply
Caravel Forum : DROD RPG Boards : RPG Architecture : pRNG (pseudo Random Number Generator)
Surf To:


Forum Rules:
Can I post a new topic? No
Can I reply? No
Can I read? Yes
HTML Enabled? No
UBBC Enabled? Yes
Words Filter Enable? No

Contact Us | CaravelGames.com

Powered by: tForum tForumHacks Edition b0.98.8
Originally created by Toan Huynh (Copyright © 2000)
Enhanced by the tForumHacks team and the Caravel team.