summaryrefslogtreecommitdiff
path: root/src/map/npc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/map/npc.c')
-rw-r--r--src/map/npc.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/src/map/npc.c b/src/map/npc.c
index 7a3fa9c3f..51482ccf4 100644
--- a/src/map/npc.c
+++ b/src/map/npc.c
@@ -1533,7 +1533,7 @@ static int npc_cashshop_buylist(struct map_session_data *sd, int points, struct
// Payment Process ----------------------------------------------------
if( nd->subtype == SCRIPT && nd->u.scr.shop->type == NST_CUSTOM ) {
- if( !npc->trader_pay(nd,sd,vt,points) )
+ if( !npc->trader_pay(nd,sd,vt,points,item_list) )
return ERROR_TYPE_MONEY;
} else {
if( sd->kafraPoints < points || sd->cashPoints < (vt - points) )
@@ -2066,7 +2066,7 @@ static void npc_trader_count_funds(struct npc_data *nd, struct map_session_data
*
* @return bool whether it was successful (if the script does not respond it will fail)
**/
-static bool npc_trader_pay(struct npc_data *nd, struct map_session_data *sd, int price, int points)
+static bool npc_trader_pay(struct npc_data *nd, struct map_session_data *sd, int price, int points, struct itemlist *item_list)
{
char evname[EVENT_NAME_LENGTH];
struct event_data *ev = NULL;
@@ -2079,6 +2079,22 @@ static bool npc_trader_pay(struct npc_data *nd, struct map_session_data *sd, int
if ( (ev = strdb_get(npc->ev_db, evname)) ) {
pc->setreg(sd,script->add_variable("@price"),price);
pc->setreg(sd,script->add_variable("@points"),points);
+ if (item_list != NULL) {
+ // discard old contents
+ script->cleararray_pc(sd, "@bought_nameid", (void*)0);
+ script->cleararray_pc(sd, "@bought_quantity", (void*)0);
+ int key_nameid = 0;
+ int key_amount = 0;
+
+ // save list of bought items
+ for (int i = 0; i < VECTOR_LENGTH(*item_list); i++) {
+ struct itemlist_entry *entry = &VECTOR_INDEX(*item_list, i);
+ intptr_t nameid = entry->id;
+ intptr_t amount = entry->amount;
+ script->setarray_pc(sd, "@bought_nameid", i, (void *)nameid, &key_nameid);
+ script->setarray_pc(sd, "@bought_quantity", i, (void *)amount, &key_amount);
+ }
+ }
script->run_npc(ev->nd->u.scr.script, ev->pos, sd->bl.id, ev->nd->bl.id);
} else
ShowError("npc_trader_pay: '%s' event '%s' not found, operation failed\n",nd->exname,evname);
@@ -2171,7 +2187,7 @@ static int npc_cashshop_buy(struct map_session_data *sd, int nameid, int amount,
points = price;
if( nd->subtype == SCRIPT && nd->u.scr.shop->type == NST_CUSTOM ) {
- if( !npc->trader_pay(nd,sd,price,points) )
+ if( !npc->trader_pay(nd,sd,price,points,NULL) )
return ERROR_TYPE_MONEY;
} else {
if( (sd->kafraPoints < points) || (sd->cashPoints < price - points) )