summaryrefslogtreecommitdiff
path: root/src/emap/pc.c
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-10-13 21:08:48 +0300
committerAndrei Karas <akaras@inbox.ru>2015-10-13 21:09:15 +0300
commitab731862f899dd87b84613ebf12a82cdc73e094f (patch)
treee0dff28ea24a942d0ad6d07783aadbccfc5022a7 /src/emap/pc.c
parentf7cce6ac2d1c010af4865212dc6ddc2a7aea66a4 (diff)
downloadevol-hercules-ab731862f899dd87b84613ebf12a82cdc73e094f.tar.gz
evol-hercules-ab731862f899dd87b84613ebf12a82cdc73e094f.tar.bz2
evol-hercules-ab731862f899dd87b84613ebf12a82cdc73e094f.tar.xz
evol-hercules-ab731862f899dd87b84613ebf12a82cdc73e094f.zip
Add support for take (pickup) script for items taked from ground by player.
Diffstat (limited to 'src/emap/pc.c')
-rw-r--r--src/emap/pc.c45
1 files changed, 37 insertions, 8 deletions
diff --git a/src/emap/pc.c b/src/emap/pc.c
index 1db0963..705c3dc 100644
--- a/src/emap/pc.c
+++ b/src/emap/pc.c
@@ -19,6 +19,7 @@
#include "emap/clif.h"
#include "emap/pc.h"
+#include "emap/script.h"
#include "emap/data/itemd.h"
#include "emap/data/mapd.h"
#include "emap/data/session.h"
@@ -461,12 +462,17 @@ bool epc_can_insert_card_into_post(bool retVal, struct map_session_data* sd,
// temporary inv index and item id
static int tempN = 0;
static int tempId = 0;
+static int tempAmount = 0;
int epc_dropitem_pre(struct map_session_data *sd, int *nPtr, int *amountPtr)
{
const int n = *nPtr;
if (n < 0 || n >= MAX_INVENTORY)
+ {
+ tempN = 0;
+ tempId = 0;
return 0;
+ }
tempN = n;
tempId = sd->status.inventory[n].nameid;
@@ -481,15 +487,38 @@ int epc_dropitem_post(int retVal, struct map_session_data *sd, int *nPtr, int *a
if (!item)
return retVal;
struct ItemdExt *data = itemd_get(item);
- if (!data || !data->dropScript)
+ if (!data)
+ return retVal;
+ script_run_item_amount_script(sd, data->dropScript, tempId, *amountPtr);
+ }
+ return retVal;
+}
+
+int epc_takeitem_pre(struct map_session_data *sd, struct flooritem_data *fitem)
+{
+ if (!fitem)
+ {
+ tempN = 0;
+ tempId = 0;
+ return 0;
+ }
+ tempN = -1;
+ tempId = fitem->item_data.nameid;
+ tempAmount = fitem->item_data.amount;
+ return 1;
+}
+
+int epc_takeitem_post(int retVal, struct map_session_data *sd, struct flooritem_data *fitem)
+{
+ if (retVal && tempN == -1 && tempId)
+ {
+ struct item_data *item = itemdb->search(tempId);
+ if (!item)
+ return retVal;
+ struct ItemdExt *data = itemd_get(item);
+ if (!data)
return retVal;
- script->current_item_id = tempId;
- pc->setreg(sd, script->add_str("@itemId"), tempId);
- pc->setreg(sd, script->add_str("@itemAmount"), *amountPtr);
- script->run(data->dropScript, 0, sd->bl.id, npc->fake_nd->bl.id);
- pc->setreg(sd, script->add_str("@itemId"), 0);
- pc->setreg(sd, script->add_str("@itemAmount"), 0);
- script->current_item_id = 0;
+ script_run_item_amount_script(sd, data->takeScript, tempId, tempAmount);
}
return retVal;
}