Skip to content

Commit 259a790

Browse files
Merge pull request #2472 from Emistry/scriptcommand_cap_value
Add *cap_value script command
2 parents 9154e3c + 1f9c83e commit 259a790

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

doc/script_commands.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8537,6 +8537,18 @@ Example:
85378537

85388538
---------------------------------------
85398539

8540+
*cap_value(<number>, <min>, <max>)
8541+
8542+
Returns the number but capped between <min> and <max>.
8543+
8544+
Example:
8545+
// capped between 0 ~ 100
8546+
.@value = cap_value(10, 0, 100); // .@value will be equal to 10
8547+
.@value = cap_value(1000, 0, 100); // .@value will be equal to 100
8548+
.@value = cap_value(-10, 3, 100); // .@value will be equal to 3
8549+
8550+
---------------------------------------
8551+
85408552
*md5("<string>")
85418553

85428554
Returns the md5 checksum of a number or string.

src/map/script.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17784,6 +17784,17 @@ static BUILDIN(max)
1778417784
return true;
1778517785
}
1778617786

17787+
static BUILDIN(cap_value)
17788+
{
17789+
int value = script_getnum(st, 2);
17790+
int min = script_getnum(st, 3);
17791+
int max = script_getnum(st, 4);
17792+
17793+
script_pushint(st, (int)cap_value(value, min, max));
17794+
17795+
return true;
17796+
}
17797+
1778717798
static BUILDIN(md5)
1778817799
{
1778917800
const char *tmpstr;
@@ -25801,6 +25812,7 @@ static void script_parse_builtin(void)
2580125812
// <--- List of mathematics commands
2580225813
BUILDIN_DEF(min, "i*"),
2580325814
BUILDIN_DEF(max, "i*"),
25815+
BUILDIN_DEF(cap_value, "iii"),
2580425816
BUILDIN_DEF(md5,"s"),
2580525817
BUILDIN_DEF(swap,"rr"),
2580625818
// [zBuffer] List of dynamic var commands --->

0 commit comments

Comments
 (0)