summaryrefslogtreecommitdiff
path: root/npc/other
diff options
context:
space:
mode:
authorAnnieRuru <jeankof@ymail.com>2015-11-17 06:29:18 +0800
committerHaru <haru@dotalux.com>2015-12-13 03:08:37 +0100
commitbb214d4651c9c9aa9599f50cb5de52059176a87f (patch)
tree06d7c288feee0fd792be008461de3123b8460a35 /npc/other
parent5c4fd6af2ac8eb5a3e0696d86cf21d86d1c61a38 (diff)
downloadhercules-bb214d4651c9c9aa9599f50cb5de52059176a87f.tar.gz
hercules-bb214d4651c9c9aa9599f50cb5de52059176a87f.tar.bz2
hercules-bb214d4651c9c9aa9599f50cb5de52059176a87f.tar.xz
hercules-bb214d4651c9c9aa9599f50cb5de52059176a87f.zip
Add 'F_ShuffleNumbers' as Global Function
Diffstat (limited to 'npc/other')
-rw-r--r--npc/other/Global_Functions.txt30
1 files changed, 30 insertions, 0 deletions
diff --git a/npc/other/Global_Functions.txt b/npc/other/Global_Functions.txt
index dc675f8d0..6febe2dff 100644
--- a/npc/other/Global_Functions.txt
+++ b/npc/other/Global_Functions.txt
@@ -40,6 +40,7 @@
//= 2.17 Renamed 'F_RandMes' to 'F_Rand'. [Euphy]
//= 2.18 Removed useless 'getJobName' function. [Euphy]
//= 2.19 Improved 'F_InsertComma' function. [Emistry]
+//= 2.20 Add 'F_ShuffleNumbers' function. [AnnieRuru]
//============================================================
//////////////////////////////////////////////////////////////////////////////////
@@ -361,3 +362,32 @@ function script Time2Str {
return .@Time$;
}
+
+//////////////////////////////////////////////////////////////////////////////////
+// *** Function "F_ShuffleNumbers":
+// Generate a set of numbers in random order that the numbers are not repeated
+// --- callfunc "F_ShuffleNumbers",<start num>,<last num>,<output array>{,<count>};
+// Examples:
+// callfunc("F_ShuffleNumbers", 0, 5, .@output) // possible output 4,1,3,2,0,5
+// callfunc("F_ShuffleNumbers", -5, 1, .@output) // possible output -3,-5,-4,-2,-1,1,0
+// callfunc("F_ShuffleNumbers", 0, 100, .@output, 5) // possible output 9,55,27,84,33
+// Reminder: Use *freeloop command when appropriate !
+//////////////////////////////////////////////////////////////////////////////////
+function script F_ShuffleNumbers {
+ deletearray getarg(2);
+ .@static = getarg(0);
+ .@range = getarg(1) +1 - .@static;
+ .@count = getarg(3, .@range);
+ if (.@range <= 0 || .@count <= 0)
+ return 0;
+ if (.@count > .@range)
+ .@count = .@range;
+ for (.@i = 0; .@i < .@range; ++.@i)
+ .@temparray[.@i] = .@i;
+ for (.@i = 0; .@i < .@count; ++.@i) {
+ .@rand = rand(.@range);
+ set getelementofarray( getarg(2), .@i ), .@temparray[.@rand] + .@static;
+ .@temparray[.@rand] = .@temparray[--.@range];
+ }
+ return .@count;
+}