diff --git a/doc/script_commands.txt b/doc/script_commands.txt index 74b1c411d9..6e9e101c1a 100644 --- a/doc/script_commands.txt +++ b/doc/script_commands.txt @@ -10627,6 +10627,25 @@ Param - Parameter of random option --------------------------------------- +*randomoptgroup ; + +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({,}); The attached player joins the clan with the . On a successful join, diff --git a/src/map/script.cpp b/src/map/script.cpp index 3ac1fd278e..abe413560d 100644 --- a/src/map/script.cpp +++ b/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},