From 5d7c8d9857f096abfc4f205c8771b0b4c91fab2c Mon Sep 17 00:00:00 2001 From: Ibrahim Zidan Date: Tue, 7 May 2019 06:37:11 +0200 Subject: Implement new script fields for items triggered on rentral status changes - OnRentalStartScript triggered when a rental item is added to inventory - OnRentalEndScript triggered when a rental period end/expire of the item Related #140 Signed-off-by: Ibrahim Zidan --- src/map/pc.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'src/map/pc.c') diff --git a/src/map/pc.c b/src/map/pc.c index 8ac820d79..b82eb5dae 100644 --- a/src/map/pc.c +++ b/src/map/pc.c @@ -4789,13 +4789,15 @@ static int pc_additem(struct map_session_data *sd, const struct item *item_data, pc->equipitem(sd, i, data->equip); /* rental item check */ - if( item_data->expire_time ) { - if( time(NULL) > item_data->expire_time ) { - pc->rental_expire(sd,i); + if (item_data->expire_time > 0) { + if (time(NULL) > item_data->expire_time) { + pc->rental_expire(sd, i); } else { - int seconds = (int)( item_data->expire_time - time(NULL) ); + int seconds = (int)(item_data->expire_time - time(NULL)); clif->rental_time(sd->fd, sd->status.inventory[i].nameid, seconds); pc->inventory_rental_add(sd, seconds); + if (data->rental_start_script != NULL) + script->run_item_rental_start_script(sd, data, 0); } } quest->questinfo_refresh(sd); @@ -4826,12 +4828,21 @@ static int pc_delitem(struct map_session_data *sd, int n, int amount, int type, sd->status.inventory[n].amount -= amount; sd->weight -= sd->inventory_data[n]->weight*amount ; + + // It's here because the data would most likely get zeroed in following if [Hemagx] + struct item_data *itd = sd->inventory_data[n]; + bool is_rental = (sd->status.inventory[n].expire_time > 0) ? true : false; + if( sd->status.inventory[n].amount <= 0 ){ if(sd->status.inventory[n].equip) pc->unequipitem(sd, n, PCUNEQUIPITEM_RECALC|PCUNEQUIPITEM_FORCE); memset(&sd->status.inventory[n],0,sizeof(sd->status.inventory[0])); sd->inventory_data[n] = NULL; } + + if (is_rental && itd->rental_end_script != NULL) + script->run_item_rental_end_script(sd, itd, 0); + if(!(type&1)) clif->delitem(sd,n,amount,reason); if(!(type&2)) -- cgit v1.2.3-60-g2f50