summaryrefslogtreecommitdiff
path: root/npc/items
diff options
context:
space:
mode:
authorJesusaves <cpntb1@ymail.com>2019-06-19 10:39:55 -0300
committerJesusaves <cpntb1@ymail.com>2019-06-19 10:39:55 -0300
commite7f4ce26bbce3712591673788448c063dea1054b (patch)
tree45d96546e664ed23e4ee8a80f2b229be0eb756ab /npc/items
parent9b6ed08a927644777b50bb4e6496b811566a48cb (diff)
downloadserverdata-e7f4ce26bbce3712591673788448c063dea1054b.tar.gz
serverdata-e7f4ce26bbce3712591673788448c063dea1054b.tar.bz2
serverdata-e7f4ce26bbce3712591673788448c063dea1054b.tar.xz
serverdata-e7f4ce26bbce3712591673788448c063dea1054b.zip
Improve shovel_scatter() accuracy. It's now 3x more reliable.
Diffstat (limited to 'npc/items')
-rw-r--r--npc/items/shovel.txt29
1 files changed, 21 insertions, 8 deletions
diff --git a/npc/items/shovel.txt b/npc/items/shovel.txt
index c116c83f8..3c6e23b88 100644
--- a/npc/items/shovel.txt
+++ b/npc/items/shovel.txt
@@ -40,14 +40,27 @@ function script shovel_scatter {
.@x2=getarg(3);
.@y2=getarg(4);
.@amount=getarg(5,1);
-
- freeloop(true); // DANGEROUS
- for (.@i = 0; .@i < .@amount; .@i++)
- shovel_scriptItem(.@map$, rand(.@x1,.@x2), rand(.@y1,.@y2), getarg(rand(getargcount()-6)+6));
- freeloop(false);
-
- .@wtc = getarraysize($@WBT_Random_id);
- debugmes "Scattered "+.@amount+" items on "+.@map$+". Currently scattered: "+.@wtc;
+ .@dbgamm=.@amount; // debug message
+
+ .@wta = getarraysize($@WBT_Random_id); // wta - original
+ .@wtb = .@wta+.@amount; // wtb - future
+ .@tries=3;
+ do {
+ freeloop(true); // DANGEROUS
+ for (.@i = 0; .@i < .@amount; .@i++)
+ shovel_scriptItem(.@map$, rand(.@x1,.@x2), rand(.@y1,.@y2), getarg(rand(getargcount()-6)+6));
+ freeloop(false);
+
+ .@wtc = getarraysize($@WBT_Random_id); // wtc - current
+ .@amount=.@wtb-.@wtc;
+
+ //debugmes "WTA %d WTB %d. WTC %d, tries %d, amount %d and dbg %d", .@wta, .@wtb, .@wtc, .@tries, .@amount, .@dbgamm;
+ if (.@wtc >= .@wtb)
+ .@tries=0;
+ else
+ .@tries-=1;
+ } while (.@tries > 0);
+ debugmes "Scattered "+.@dbgamm+" items on "+.@map$+". Currently scattered: "+.@wtc;
return;
}