|
@@ -17209,8 +17209,17 @@ BUILDIN_FUNC(npcshopitem)
|
|
|
|
|
|
// generate new shop item list
|
|
// generate new shop item list
|
|
RECREATE(nd->u.shop.shop_item, struct npc_item_list, amount);
|
|
RECREATE(nd->u.shop.shop_item, struct npc_item_list, amount);
|
|
|
|
+ nd->u.shop.count = 0;
|
|
for (n = 0, i = 3; n < amount; n++, i+=offs) {
|
|
for (n = 0, i = 3; n < amount; n++, i+=offs) {
|
|
- nd->u.shop.shop_item[n].nameid = script_getnum(st,i);
|
|
|
|
|
|
+ t_itemid nameid = script_getnum( st, i );
|
|
|
|
+
|
|
|
|
+ if( itemdb_exists( nameid ) == nullptr ){
|
|
|
|
+ ShowError( "builtin_npcshopitem: Item ID %u does not exist.\n", nameid );
|
|
|
|
+ script_pushint( st, 0 );
|
|
|
|
+ return SCRIPT_CMD_FAILURE;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ nd->u.shop.shop_item[n].nameid = nameid;
|
|
nd->u.shop.shop_item[n].value = script_getnum(st,i+1);
|
|
nd->u.shop.shop_item[n].value = script_getnum(st,i+1);
|
|
#if PACKETVER >= 20131223
|
|
#if PACKETVER >= 20131223
|
|
if (nd->subtype == NPCTYPE_MARKETSHOP) {
|
|
if (nd->subtype == NPCTYPE_MARKETSHOP) {
|
|
@@ -17219,8 +17228,8 @@ BUILDIN_FUNC(npcshopitem)
|
|
npc_market_tosql(nd->exname, &nd->u.shop.shop_item[n]);
|
|
npc_market_tosql(nd->exname, &nd->u.shop.shop_item[n]);
|
|
}
|
|
}
|
|
#endif
|
|
#endif
|
|
|
|
+ nd->u.shop.count++;
|
|
}
|
|
}
|
|
- nd->u.shop.count = n;
|
|
|
|
|
|
|
|
script_pushint(st,1);
|
|
script_pushint(st,1);
|
|
return SCRIPT_CMD_SUCCESS;
|
|
return SCRIPT_CMD_SUCCESS;
|
|
@@ -17230,7 +17239,6 @@ BUILDIN_FUNC(npcshopadditem)
|
|
{
|
|
{
|
|
const char* npcname = script_getstr(st,2);
|
|
const char* npcname = script_getstr(st,2);
|
|
struct npc_data* nd = npc_name2id(npcname);
|
|
struct npc_data* nd = npc_name2id(npcname);
|
|
- int n, i;
|
|
|
|
uint16 offs = 2, amount;
|
|
uint16 offs = 2, amount;
|
|
|
|
|
|
if (!nd || ( nd->subtype != NPCTYPE_SHOP && nd->subtype != NPCTYPE_CASHSHOP && nd->subtype != NPCTYPE_ITEMSHOP && nd->subtype != NPCTYPE_POINTSHOP && nd->subtype != NPCTYPE_MARKETSHOP)) { // Not found.
|
|
if (!nd || ( nd->subtype != NPCTYPE_SHOP && nd->subtype != NPCTYPE_CASHSHOP && nd->subtype != NPCTYPE_ITEMSHOP && nd->subtype != NPCTYPE_POINTSHOP && nd->subtype != NPCTYPE_MARKETSHOP)) { // Not found.
|
|
@@ -17246,10 +17254,16 @@ BUILDIN_FUNC(npcshopadditem)
|
|
|
|
|
|
#if PACKETVER >= 20131223
|
|
#if PACKETVER >= 20131223
|
|
if (nd->subtype == NPCTYPE_MARKETSHOP) {
|
|
if (nd->subtype == NPCTYPE_MARKETSHOP) {
|
|
- for (n = 0, i = 3; n < amount; n++, i += offs) {
|
|
|
|
|
|
+ for (int n = 0, i = 3; n < amount; n++, i += offs) {
|
|
t_itemid nameid = script_getnum(st,i);
|
|
t_itemid nameid = script_getnum(st,i);
|
|
uint16 j;
|
|
uint16 j;
|
|
|
|
|
|
|
|
+ if( itemdb_exists( nameid ) == nullptr ){
|
|
|
|
+ ShowError( "builtin_npcshopadditem: Item ID %u does not exist.\n", nameid );
|
|
|
|
+ script_pushint( st, 0 );
|
|
|
|
+ return SCRIPT_CMD_FAILURE;
|
|
|
|
+ }
|
|
|
|
+
|
|
// Check existing entries
|
|
// Check existing entries
|
|
ARR_FIND(0, nd->u.shop.count, j, nd->u.shop.shop_item[j].nameid == nameid);
|
|
ARR_FIND(0, nd->u.shop.count, j, nd->u.shop.shop_item[j].nameid == nameid);
|
|
if (j == nd->u.shop.count) {
|
|
if (j == nd->u.shop.count) {
|
|
@@ -17272,12 +17286,20 @@ BUILDIN_FUNC(npcshopadditem)
|
|
|
|
|
|
// append new items to existing shop item list
|
|
// append new items to existing shop item list
|
|
RECREATE(nd->u.shop.shop_item, struct npc_item_list, nd->u.shop.count+amount);
|
|
RECREATE(nd->u.shop.shop_item, struct npc_item_list, nd->u.shop.count+amount);
|
|
- for (n = nd->u.shop.count, i = 3; n < nd->u.shop.count+amount; n++, i+=offs)
|
|
|
|
|
|
+ for (int n = nd->u.shop.count, i = 3, j = 0; j < amount; n++, i+=offs, j++)
|
|
{
|
|
{
|
|
- nd->u.shop.shop_item[n].nameid = script_getnum(st,i);
|
|
|
|
|
|
+ t_itemid nameid = script_getnum( st, i );
|
|
|
|
+
|
|
|
|
+ if( itemdb_exists( nameid ) == nullptr ){
|
|
|
|
+ ShowError( "builtin_npcshopadditem: Item ID %u does not exist.\n", nameid );
|
|
|
|
+ script_pushint( st, 0 );
|
|
|
|
+ return SCRIPT_CMD_FAILURE;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ nd->u.shop.shop_item[n].nameid = nameid;
|
|
nd->u.shop.shop_item[n].value = script_getnum(st,i+1);
|
|
nd->u.shop.shop_item[n].value = script_getnum(st,i+1);
|
|
|
|
+ nd->u.shop.count++;
|
|
}
|
|
}
|
|
- nd->u.shop.count = n;
|
|
|
|
|
|
|
|
script_pushint(st,1);
|
|
script_pushint(st,1);
|
|
return SCRIPT_CMD_SUCCESS;
|
|
return SCRIPT_CMD_SUCCESS;
|