We are trying to transfer NPC Trader of Hercules to rAthena but we received an error if we will use the item name.
This is the code that cause the error. It means it doesn't allow Item name in sellitem scriptcommand.
prontera,73,134,5 trader Milk Merchant#prt1 4_F_01,{
OnInit:
sellitem Milk;
end;
}
But if we use this format there is no problem at all.
prontera,73,134,5 trader Milk Merchant#prt1 4_F_01,{
OnInit:
sellitem 519;
end;
}
So this is the current sellitem script command code.
/**
* @call sellitem <Item_ID>,{,price{,qty}};
*
* adds <Item_ID> (or modifies if present) to shop
* if price not provided (or -1) uses the item's value_sell
**/
BUILDIN_FUNC(sellitem) {
struct npc_data *nd;
struct item_data *it;
int i = 0, id = script_getnum(st,2);
int value = 0;
int qty = 0;
int rental = 0; // Judas Bound/Rental
int bound = 0; // Judas Bound/Rental
if( !(nd = map_id2nd(st->oid)) ) {
ShowWarning("buildin_sellitem: trying to run without a proper NPC!\n");
return false;
} else if ( !(it = itemdb_exists(id)) ) {
ShowWarning("buildin_sellitem: unknown item id '%d'!\n",id);
return false;
}
value = script_hasdata(st,3) ? script_getnum(st, 3) : it->value_buy;
if( value == -1 )
value = it->value_buy;
if( !nd->u.scr.shop )
npc_trader_update(nd->src_id?nd->src_id:nd->bl.id);
else {/* no need to run this if its empty */
for( i = 0; i < nd->u.scr.shop->items; i++ ) {
if( nd->u.scr.shop->item[i].nameid == id )
break;
}
}
if( i != nd->u.scr.shop->items ) {
nd->u.scr.shop->item[i].value = value;
nd->u.scr.shop->item[i].qty = qty;
} else {
for( i = 0; i < nd->u.scr.shop->items; i++ ) {
if( nd->u.scr.shop->item[i].nameid == 0 )
break;
}
// Judas Bound/Rental
rental = script_getnum(st, 4);
bound = script_getnum(st, 5);
if (rental > 0) {
bound = 0;
}
else {
if (bound > 4) {
ShowWarning("buildin_sellitem: Can't add %s (%s/%s), bound is out of range!\n", it->name, nd->exname, nd->path);
return false;
}
}
if( i == nd->u.scr.shop->items ) {
if( nd->u.scr.shop->items == USHRT_MAX ) {
ShowWarning("buildin_sellitem: Can't add %s (%s/%s), shop list is full!\n", it->name, nd->exname, nd->path);
return false;
}
i = nd->u.scr.shop->items;
RECREATE(nd->u.scr.shop->item, struct npc_item_list, ++nd->u.scr.shop->items);
}
nd->u.scr.shop->item[i].nameid = it->nameid;
nd->u.scr.shop->item[i].value = value;
nd->u.scr.shop->item[i].qty = qty;
}
return SCRIPT_CMD_SUCCESS;
}
But judas made an adjustments using this new code and you need to add " " on the item name.
BUILDIN_FUNC(sellitem) {
struct npc_data *nd;
struct item_data *it;
- int i = 0, id = script_getnum(st,2);
+ int i = 0, id;
int value = 0;
int qty = 0;
int rental = 0; // Judas Bound/Rental
int bound = 0; // Judas Bound/Rental
+ // Resolve Item
+ struct script_data *someItem = script_getdata(st, 2);
+ get_val(st, someItem);
+ if (data_isint(someItem)) {
+ id = script_getnum(st, 2);
+ }
+ else if (data_isstring(someItem)) {
+ const char* str = script_getstr(st, 2);
+ struct item_data *testData = itemdb_searchname(str);
+ id = testData->nameid;
+ }
if( !(nd = map_id2nd(st->oid)) ) {
ShowWarning("buildin_sellitem: trying to run without a proper NPC!\n");
@ -24308,7 +24321,7 @@ struct script_function buildin_func[] = {
//
/* New Shop Support */
BUILDIN_DEF(openshop,"?"),
- BUILDIN_DEF(sellitem,"i?????"), // Judas Bound/Rental
+ BUILDIN_DEF(sellitem,"??????"), // Judas Bound/Rental
Anyone know how can we use the item name instead of using the new code.