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 !
This commit is contained in:
Atemo 2022-03-11 19:04:59 +01:00 committed by GitHub
parent 2012857815
commit a6a3c165b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 0 deletions

View File

@ -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>}); *clan_join(<clan id>{,<char id>});
The attached player joins the clan with the <clan id>. On a successful join, The attached player joins the clan with the <clan id>. On a successful join,

View File

@ -25788,6 +25788,30 @@ BUILDIN_FUNC( laphine_upgrade ){
return SCRIPT_CMD_SUCCESS; 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" #include "../custom/script.inc"
// declarations that were supposed to be exported from npc_chat.cpp // 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(getitempos,""),
BUILDIN_DEF(laphine_synthesis, ""), BUILDIN_DEF(laphine_synthesis, ""),
BUILDIN_DEF(laphine_upgrade, ""), BUILDIN_DEF(laphine_upgrade, ""),
BUILDIN_DEF(randomoptgroup,"i"),
#include "../custom/script_def.inc" #include "../custom/script_def.inc"
{NULL,NULL,NULL}, {NULL,NULL,NULL},