Browse Source

Add cap_value script command (#7307)

* Supports int64.
Co-authored-by: Lemongrass3110 <lemongrass@kstp.at>
HAO YAN 2 years ago
parent
commit
7d19b4bbdd
2 changed files with 19 additions and 0 deletions
  1. 12 0
      doc/script_commands.txt
  2. 7 0
      src/map/script.cpp

+ 12 - 0
doc/script_commands.txt

@@ -8967,6 +8967,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
+
+---------------------------------------
+
 *round(<number>,<precision>);
 *ceil(<number>,<precision>);
 *floor(<number>,<precision>);

+ 7 - 0
src/map/script.cpp

@@ -24129,6 +24129,12 @@ BUILDIN_FUNC(minmax){
 	return SCRIPT_CMD_SUCCESS;
 }
 
+BUILDIN_FUNC(cap_value)
+{
+	script_pushint64(st, cap_value(script_getnum64(st, 2), script_getnum64(st, 3), script_getnum64(st, 4)));
+	return SCRIPT_CMD_SUCCESS;
+}
+
 /**
  * Safety Base/Job EXP addition than using `set BaseExp,n;` or `set JobExp,n;`
  * Unlike `getexp` that affected by some adjustments.
@@ -27047,6 +27053,7 @@ struct script_function buildin_func[] = {
 	BUILDIN_DEF2(minmax,"minimum", "*"),
 	BUILDIN_DEF2(minmax,"max", "*"),
 	BUILDIN_DEF2(minmax,"maximum", "*"),
+	BUILDIN_DEF(cap_value, "iii"),
 	// <--- [zBuffer] List of mathematics commands
 	BUILDIN_DEF(md5,"s"),
 	// [zBuffer] List of dynamic var commands --->