summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/script_commands.txt12
-rw-r--r--src/map/script.c12
2 files changed, 24 insertions, 0 deletions
diff --git a/doc/script_commands.txt b/doc/script_commands.txt
index ae9d05d46..bcd2297b9 100644
--- a/doc/script_commands.txt
+++ b/doc/script_commands.txt
@@ -8537,6 +8537,18 @@ Example:
---------------------------------------
+*cap_value(<number>, <min>, <max>)
+
+Returns the number but capped between <min> and <max>.
+
+Example:
+ // capped between 0 ~ 100
+ .@value = cap_value(10, 0, 100); // .@value will be equal to 10
+ .@value = cap_value(1000, 0, 100); // .@value will be equal to 100
+ .@value = cap_value(-10, 3, 100); // .@value will be equal to 3
+
+---------------------------------------
+
*md5("<string>")
Returns the md5 checksum of a number or string.
diff --git a/src/map/script.c b/src/map/script.c
index 478cc8e1d..1e0cd87ec 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -17784,6 +17784,17 @@ static BUILDIN(max)
return true;
}
+static BUILDIN(cap_value)
+{
+ int value = script_getnum(st, 2);
+ int min = script_getnum(st, 3);
+ int max = script_getnum(st, 4);
+
+ script_pushint(st, (int)cap_value(value, min, max));
+
+ return true;
+}
+
static BUILDIN(md5)
{
const char *tmpstr;
@@ -25801,6 +25812,7 @@ static void script_parse_builtin(void)
// <--- List of mathematics commands
BUILDIN_DEF(min, "i*"),
BUILDIN_DEF(max, "i*"),
+ BUILDIN_DEF(cap_value, "iii"),
BUILDIN_DEF(md5,"s"),
BUILDIN_DEF(swap,"rr"),
// [zBuffer] List of dynamic var commands --->