Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions doc/script_commands.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8536,6 +8536,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.
Expand Down
12 changes: 12 additions & 0 deletions src/map/script.c
Original file line number Diff line number Diff line change
Expand Up @@ -17778,6 +17778,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;
Expand Down Expand Up @@ -25797,6 +25808,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 --->
Expand Down