From 6b20c5b6988c889df35b890d93c338f8b87fa430 Mon Sep 17 00:00:00 2001 From: Haru Date: Sun, 2 Nov 2014 01:30:33 +0100 Subject: Added min() and max() script commands - Special thanks to Streusel, Xgear Signed-off-by: Haru --- src/map/script.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src/map') diff --git a/src/map/script.c b/src/map/script.c index 1516a0234..006f275eb 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -14835,6 +14835,36 @@ BUILDIN(distance) // <--- [zBuffer] List of mathematics commands +BUILDIN(min) +{ + int i, min; + + min = script_getnum(st, 2); + for (i = 3; script_hasdata(st, i); i++) { + int next = script_getnum(st, i); + if (next < min) + min = next; + } + script_pushint(st, min); + + return true; +} + +BUILDIN(max) +{ + int i, max; + + max = script_getnum(st, 2); + for (i = 3; script_hasdata(st, i); i++) { + int next = script_getnum(st, i); + if (next > max) + max = next; + } + script_pushint(st, max); + + return true; +} + BUILDIN(md5) { const char *tmpstr; @@ -19283,6 +19313,8 @@ void script_parse_builtin(void) { BUILDIN_DEF(pow,"ii"), BUILDIN_DEF(distance,"iiii"), // <--- [zBuffer] List of mathematics commands + BUILDIN_DEF(min, "i*"), + BUILDIN_DEF(max, "i*"), BUILDIN_DEF(md5,"s"), // [zBuffer] List of dynamic var commands ---> BUILDIN_DEF(getd,"s"), -- cgit v1.2.3-60-g2f50