diff --git a/src/map/script.cpp b/src/map/script.cpp index 59e266aeb8..b4dceefc35 100644 --- a/src/map/script.cpp +++ b/src/map/script.cpp @@ -13959,23 +13959,48 @@ BUILDIN_FUNC(getitemslots) *------------------------------------------*/ BUILDIN_FUNC(getiteminfo) { - unsigned short n; - struct item_data *i_data; - t_itemid item_id = script_getnum(st,2); - n = script_getnum(st,3); - i_data = itemdb_exists(item_id); + item_data *i_data = itemdb_exists(item_id); - if (i_data && n <= 16) { - int *item_arr = (int*)&i_data->value_buy; -#ifndef RENEWAL - if (n == 16) - script_pushint(st,0); - else + if (i_data == nullptr) { + script_pushint(st, -1); + return SCRIPT_CMD_SUCCESS; + } + switch( script_getnum(st, 3) ) { + case 0: script_pushint(st, i_data->value_buy); break; + case 1: script_pushint(st, i_data->value_sell); break; + case 2: script_pushint(st, i_data->type); break; + case 3: script_pushint(st, i_data->maxchance); break; + case 4: script_pushint(st, i_data->sex); break; + case 5: script_pushint(st, i_data->equip); break; + case 6: script_pushint(st, i_data->weight); break; + case 7: script_pushint(st, i_data->atk); break; + case 8: script_pushint(st, i_data->def); break; + case 9: script_pushint(st, i_data->range); break; + case 10: script_pushint(st, i_data->slots); break; + case 11: + if (i_data->type == IT_WEAPON || i_data->type == IT_AMMO) { // keep old compatibility + script_pushint(st, i_data->subtype); + } else { + script_pushint(st, i_data->look); + } + break; + case 12: script_pushint(st, i_data->elv); break; + case 13: script_pushint(st, i_data->wlv); break; + case 14: script_pushint(st, i_data->view_id); break; + case 15: script_pushint(st, i_data->elvmax); break; + case 16: { +#ifdef RENEWAL + script_pushint(st, i_data->matk); +#else + script_pushint(st, 0); #endif - script_pushint(st,item_arr[n]); - } else - script_pushint(st,-1); + break; + } + default: + script_pushint(st, -1); + break; + } return SCRIPT_CMD_SUCCESS; } @@ -14006,27 +14031,51 @@ BUILDIN_FUNC(getiteminfo) *------------------------------------------*/ BUILDIN_FUNC(setiteminfo) { - int n,value; - struct item_data *i_data; - t_itemid item_id = script_getnum(st,2); - n = script_getnum(st,3); - value = script_getnum(st,4); - i_data = itemdb_exists(item_id); + item_data *i_data = itemdb_exists(item_id); -#ifndef RENEWAL - if( n == 16 ){ - script_pushint( st, -1 ); + if (i_data == nullptr) { + script_pushint(st, -1); return SCRIPT_CMD_SUCCESS; } -#endif + int value = script_getnum(st,4); - if (i_data && n>=0 && n<=16) { - int *item_arr = (int*)&i_data->value_buy; - item_arr[n] = value; - script_pushint(st,value); - } else - script_pushint(st,-1); + switch( script_getnum(st, 3) ) { + case 0: i_data->value_buy = static_cast(value); break; + case 1: i_data->value_sell = static_cast(value); break; + case 2: i_data->type = static_cast(value); break; + case 3: i_data->maxchance = static_cast(value); break; + case 4: i_data->sex = static_cast(value); break; + case 5: i_data->equip = static_cast(value); break; + case 6: i_data->weight = static_cast(value); break; + case 7: i_data->atk = static_cast(value); break; + case 8: i_data->def = static_cast(value); break; + case 9: i_data->range = static_cast(value); break; + case 10: i_data->slots = static_cast(value); break; + case 11: + if (i_data->type == IT_WEAPON || i_data->type == IT_AMMO) { // keep old compatibility + i_data->subtype = static_cast(value); + } else { + i_data->look = static_cast(value); + } + break; + case 12: i_data->elv = static_cast(value); break; + case 13: i_data->wlv = static_cast(value); break; + case 14: i_data->view_id = static_cast(value); break; + case 15: i_data->elvmax = static_cast(value); break; + case 16: { +#ifdef RENEWAL + i_data->matk = static_cast(value); +#else + value = 0; +#endif + break; + } + default: + script_pushint(st, -1); + break; + } + script_pushint(st, value); return SCRIPT_CMD_SUCCESS; }