From e7f4ce26bbce3712591673788448c063dea1054b Mon Sep 17 00:00:00 2001 From: Jesusaves Date: Wed, 19 Jun 2019 10:39:55 -0300 Subject: Improve shovel_scatter() accuracy. It's now 3x more reliable. --- npc/items/shovel.txt | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) (limited to 'npc/items') 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; } -- cgit v1.2.3-60-g2f50