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:
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:
Ho, and another one, because the site won't let me post this thread else:
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:
Ho, and another one, because the site won't let me post this thread else:
Attachments
Last edited: