summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/map/npc.c22
-rw-r--r--src/map/npc.h2
-rw-r--r--src/plugins/HPMHooking/HPMHooking_map.Hooks.inc4
3 files changed, 22 insertions, 6 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) )
diff --git a/src/map/npc.h b/src/map/npc.h
index 16d7a984b..f9ef82c68 100644
--- a/src/map/npc.h
+++ b/src/map/npc.h
@@ -326,7 +326,7 @@ struct npc_interface {
void (*debug_warps) (void);
/* */
void (*trader_count_funds) (struct npc_data *nd, struct map_session_data *sd);
- bool (*trader_pay) (struct npc_data *nd, struct map_session_data *sd, int price, int points);
+ bool (*trader_pay) (struct npc_data *nd, struct map_session_data *sd, int price, int points, struct itemlist *item_list);
void (*trader_update) (int master);
enum market_buy_result (*market_buylist) (struct map_session_data *sd, struct itemlist *item_list);
int (*barter_buylist) (struct map_session_data *sd, struct barteritemlist *item_list);
diff --git a/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc b/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc
index 8cb425011..01be7c215 100644
--- a/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc
+++ b/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc
@@ -58534,7 +58534,7 @@ void HP_npc_trader_count_funds(struct npc_data *nd, struct map_session_data *sd)
}
return;
}
-bool HP_npc_trader_pay(struct npc_data *nd, struct map_session_data *sd, int price, int points) {
+bool HP_npc_trader_pay(struct npc_data *nd, struct map_session_data *sd, int price, int points, struct itemlist *item_list) {
int hIndex = 0;
bool retVal___ = false;
if (HPMHooks.count.HP_npc_trader_pay_pre > 0) {
@@ -58550,7 +58550,7 @@ bool HP_npc_trader_pay(struct npc_data *nd, struct map_session_data *sd, int pri
}
}
{
- retVal___ = HPMHooks.source.npc.trader_pay(nd, sd, price, points);
+ retVal___ = HPMHooks.source.npc.trader_pay(nd, sd, price, points, item_list);
}
if (HPMHooks.count.HP_npc_trader_pay_post > 0) {
bool (*postHookFunc) (bool retVal___, struct npc_data *nd, struct map_session_data *sd, int price, int points);