SRB2 Message Board  

Go Back   SRB2 Message Board > Archived > Outdated Releases (2.1.X) > Lua (2.1.X)

 
 
Thread Tools
Pseudorandom numbers library Details »»
Pseudorandom numbers library
Version: v1.0, by LJ Sonik LJ Sonik is offline
Developer Last Online: Jun 2020

Category: Version: SRB2 Rating: (1 votes - 2.80 average)
Released: 06-30-2014 Last Update: Never Favourites: 1
Scripts Re-Useable Content

WARNING, THIS SCRIPT DOES NOT WORK.



A little script that features functions returning pseudorandom numbers which are usable with netgames, including dedicated servers. I used the Xorshift algorithm, which is a simple, fast and reliable enough method for a game like srb2.
To assure synchronization on script loading, the numbers generated in the first map played will always follow the same suit. This won't happend once the map has been changed thought.

To use it in your mod, just insert it in a separate lump then you can use the following functions in the other scripts:
  • A_Random(): returns a random value from -2147483648 and 2147483647.
  • A_RandomKey(INT32 n): returns a random value from 0 to (n-1).
  • A_RandomRange(INT32 a, INT32 b): returns a random value from a to b, with a < b.
  • A_RandomDatas(): returns the mobj used to store the server-synchronized variables. Usually needed to check if the previous functions are already functional

Warning ! As the library uses a mobj to synchronize datas, you cannot use random numbers on the few first tics after map changing ! You have to check if the library is initialized with a test like "if not A_RandomDatas() return end". Tip: Don't use this check everytime you try getting a random number, make a global check if possible.

To dump the stupid bug with *.lua files, I add a screenshot of a mod using that library:

Click image for larger version

Name:	srb20019.png
Views:	417
Size:	120.0 KB
ID:	5239

Ho, and another one, because the site won't let me post this thread else:

Click image for larger version

Name:	srb20073.png
Views:	395
Size:	90.1 KB
ID:	5241

Download Now

File Type: lua random.lua (926 Bytes, 244 views)

Show Your Support

  • The author of this addon has given explicit permission for its content to be re-used and/or reproduced.

Comments
Old 07-01-2014   #2
MellowJacket
The unreliable judge
Judge
 
MellowJacket's Avatar
Default

This works and I'm happy to pass it. It's a pretty simple script and it's also competing with the Linedef type 451 (Random Range) but I imagine someone will find a use for this somewhere.

Also it's worth noting that you can find an example of this script in action here.
__________________
Meanwhile in Aerial Garden Zone
MellowJacket is offline  
Old 07-01-2014   #3
LJ Sonik
Developer
Default

Ho I already used it many times. It is very useful every time you create a script that is meant to work with netgames and that would use P_Random(), P_RandomKey(), RandomRange(), or similar functions from the default Lua library.
LJ Sonik is offline  
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 10:16 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2020, vBulletin Solutions, Inc.