Explorar el Código

randomoptgroup script command (#6655)

* script command to get the random value of the random option ID, value and param of a random option group ID

Co-authored-by: Lemongrass3110 <lemongrass@kstp.at>

Thanks to @aleos89 !
Atemo hace 3 años
padre
commit
a6a3c165b2
Se han modificado 2 ficheros con 44 adiciones y 0 borrados
  1. 19 0
      doc/script_commands.txt
  2. 25 0
      src/map/script.cpp

+ 19 - 0
doc/script_commands.txt

@@ -10627,6 +10627,25 @@ Param - Parameter of random option
 
 ---------------------------------------
 
+*randomoptgroup <random option group ID>;
+
+This command fills the following arrays with the results of a random option group.
+The random option group IDs are specified in 'db/(pre-)re/item_randomopt_group.yml'.
+
+Arrays - from index 0 to MAX_ITEM_RDM_OPT-1 :
+.@opt_id[]                - array of random option ID.
+.@opt_value[]             - array of value.
+.@opt_param[]             - array of param.
+
+Example:
+	// Fill the arrays using the random option group ID 5 (group used for Crimson weapons).
+	randomoptgroup(5);
+
+	// Create a +9 Crimson Dagger [2] with the Group 5 applied
+	getitem3 28705,1,1,9,0,0,0,0,0,.@opt_id,.@opt_value,.@opt_param;
+
+---------------------------------------
+
 *clan_join(<clan id>{,<char id>});
 
 The attached player joins the clan with the <clan id>. On a successful join,

+ 25 - 0
src/map/script.cpp

@@ -25788,6 +25788,30 @@ BUILDIN_FUNC( laphine_upgrade ){
 	return SCRIPT_CMD_SUCCESS;
 }
 
+BUILDIN_FUNC(randomoptgroup)
+{
+	int id = script_getnum(st,2);
+
+	auto group = random_option_group.find(id);
+
+	if (group == nullptr) {
+		ShowError("buildin_randomoptgroup: Invalid random option group id (%d)!\n", id);
+		return SCRIPT_CMD_FAILURE;
+	}
+
+	struct item item_tmp = {};
+
+	group->apply( item_tmp );
+
+	for ( int i = 0; i < MAX_ITEM_RDM_OPT; ++i ) {
+		setd_sub_num(st, nullptr, ".@opt_id", i, item_tmp.option[i].id, nullptr);
+		setd_sub_num(st, nullptr, ".@opt_value", i, item_tmp.option[i].value, nullptr);
+		setd_sub_num(st, nullptr, ".@opt_param", i, item_tmp.option[i].param, nullptr);
+	}
+
+	return SCRIPT_CMD_SUCCESS;
+}
+
 #include "../custom/script.inc"
 
 // declarations that were supposed to be exported from npc_chat.cpp
@@ -26499,6 +26523,7 @@ struct script_function buildin_func[] = {
 	BUILDIN_DEF(getitempos,""),
 	BUILDIN_DEF(laphine_synthesis, ""),
 	BUILDIN_DEF(laphine_upgrade, ""),
+	BUILDIN_DEF(randomoptgroup,"i"),
 #include "../custom/script_def.inc"
 
 	{NULL,NULL,NULL},