From 36040a2d577264bf8460ae1851ffdac622969381 Mon Sep 17 00:00:00 2001 From: Jesusaves Date: Sun, 10 Feb 2019 02:04:18 -0200 Subject: [skip ci] I need more verbosity and control --- npc/005-1-1/main.txt | 2 +- npc/functions/array.txt | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) (limited to 'npc') diff --git a/npc/005-1-1/main.txt b/npc/005-1-1/main.txt index 66a5a43cf..e80aaa7b1 100644 --- a/npc/005-1-1/main.txt +++ b/npc/005-1-1/main.txt @@ -136,7 +136,7 @@ OnInteract: // Destroy the crop if needed .@cropId$=getcropid(.@x, .@y); - if (array_find(@DESTROYED, .@cropId$) == -1) { + if (array_find2(@DESTROYED, .@cropId$) == -1) { debugmes("[LOGIC] -------------------------- crop found"); array_push(@DESTROYED, .@cropId$); debugmes("[LOGIC] -------------------------- crop destroyed"); diff --git a/npc/functions/array.txt b/npc/functions/array.txt index 1a106175e..4da22b6fe 100644 --- a/npc/functions/array.txt +++ b/npc/functions/array.txt @@ -71,6 +71,24 @@ function script array_find { freeloop(false); return -1; } +// array_find2(, ) +// Simplified version +// if not found it returns -1 + +function script array_find2 { + .@size = getarraysize(getarg(0)); + freeloop(true); + + for (.@i = getarrayindex(getarg(0)); .@i < .@size; ++.@i) { + if (getelementofarray(getarg(0), .@i) == getarg(1)) { + freeloop(false); + return true; + } + } + + freeloop(false); + return -1; +} -- cgit v1.2.3-60-g2f50