summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--npc/functions/RNGesus.txt10
1 files changed, 7 insertions, 3 deletions
diff --git a/npc/functions/RNGesus.txt b/npc/functions/RNGesus.txt
index 7d2ff7c7..6883f8f1 100644
--- a/npc/functions/RNGesus.txt
+++ b/npc/functions/RNGesus.txt
@@ -44,9 +44,9 @@ function script relative_array_random {
for (.@i = .@initial_index + 1; .@i < .@size; .@i += 2) {
if (.@is_str) {
- .@total_prob += atoi(getelementofarray(getarg(0), .@i));
+ .@total_prob += max(1, atoi(getelementofarray(getarg(0), .@i)));
} else {
- .@total_prob += getelementofarray(getarg(0), .@i);
+ .@total_prob += max(1, getelementofarray(getarg(0), .@i));
}
}
@@ -54,7 +54,7 @@ function script relative_array_random {
set(getelementofarray(getarg(0), 0), .@total_prob);
}
- .@target_sum = rand(.@total_prob);
+ .@target_sum = rand(0, .@total_prob);
for (.@i = .@initial_index; .@sum < .@target_sum; .@i += 2) {
if (.@is_str) {
@@ -62,6 +62,10 @@ function script relative_array_random {
} else {
.@sum += getelementofarray(getarg(0), .@i + 1);
}
+
+ if (.@sum >= .@target_sum) {
+ break;
+ }
}
freeloop(false);