Modding:Random Functions: Difference between revisions

Jump to navigation Jump to search
→‎Randoms: Added GetSeededRandomGenerator. it rules
(→‎Randoms: Added GetSeededRandomGenerator. it rules)
Line 22: Line 22:
===LevelUpRandom()===
===LevelUpRandom()===
The Random used to determine randomized things at level up.
The Random used to determine randomized things at level up.
===GetSeededRandomGenerator(string Seed)===
If you don't want to use the game's seeds in fear of altering worldseed too much, there is a helper function that returns a new random that hashes a new random. This allows your mod to be affected by world seed but does not alter the base game's random number calls.
<syntaxhighlight lang="c#">
public static Random GetSeededRandomGenerator(string Seed)
        {
            if (XRLCore.Core.Game == null)
            {
                return new Random();
            }
            return new Random(Hash.String(XRLCore.Core.Game.GetWorldSeed(null) + Seed));
        }
</syntaxhighlight>
The Seed here should follow [[Modding: General Best Practices|best practice conventions]], so <code>YourName_YourMod</code> to avoid overlapping conflicts as much as possible.


==Returners==
==Returners==

Navigation menu