From d3c277d189ff513258f290c84680d275c4d05e0c Mon Sep 17 00:00:00 2001 From: Jesusaves Date: Sat, 1 Jun 2019 21:00:28 -0300 Subject: Improve randomizer functions with rand2() - a fix proposed by 4144. --- npc/functions/main.txt | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'npc/functions/main.txt') diff --git a/npc/functions/main.txt b/npc/functions/main.txt index 075142e12..2aa670ca4 100644 --- a/npc/functions/main.txt +++ b/npc/functions/main.txt @@ -241,16 +241,29 @@ function script npctalkonce { // Randomizer functions ///////////////////////////////////////////// +// pseudo-fix randomness +// rand2( min, max ) +function script rand2 { + if (getargcount() == 2) { + .@min=getarg(0)*10; + .@max=getarg(1)*10+9; + } else { + .@min=0; + .@max=getarg(0)*10+9; + } + return rand(.@min, .@max)/10; +} + // returns one argument randomly // any( {, ...} ) function script any { - return getarg(rand(getargcount())); + return getarg(rand2(getargcount())); } // returns any member of the array // any_of( ) function script any_of { - return getelementofarray(getarg(0), getarrayindex(getarg(0)) + rand(getarraysize(getarg(0)) - getarrayindex(getarg(0)))); + return getelementofarray(getarg(0), getarrayindex(getarg(0)) + rand2(getarraysize(getarg(0)) - getarrayindex(getarg(0)))); } // TMW2 Custom Functions -- cgit v1.2.3-70-g09d2