diff options
author | Andrei Karas <akaras@inbox.ru> | 2015-08-21 23:22:55 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2015-08-21 23:22:55 +0300 |
commit | 4333293820d5c7de27e9e760dfeaadbc1686f2c3 (patch) | |
tree | 8b85e0447407cfe6cb58a935c3c27d3dc6c9ed09 | |
parent | 36fb4cda271bda394b7e5e3b5911c6d9858aa8f8 (diff) | |
download | plugin-4333293820d5c7de27e9e760dfeaadbc1686f2c3.tar.gz plugin-4333293820d5c7de27e9e760dfeaadbc1686f2c3.tar.bz2 plugin-4333293820d5c7de27e9e760dfeaadbc1686f2c3.tar.xz plugin-4333293820d5c7de27e9e760dfeaadbc1686f2c3.zip |
Add script function failedrefindex and some macro.
New function: failedrefindex index
index - inventory item index
Example:
failedrefindex .@itemid;
-rw-r--r-- | src/emap/init.c | 1 | ||||
-rw-r--r-- | src/emap/script.c | 17 | ||||
-rw-r--r-- | src/emap/script.h | 1 | ||||
-rw-r--r-- | src/emap/scriptdefines.h | 49 |
4 files changed, 60 insertions, 8 deletions
diff --git a/src/emap/init.c b/src/emap/init.c index fcd8208..550ebf7 100644 --- a/src/emap/init.c +++ b/src/emap/init.c @@ -116,6 +116,7 @@ HPExport void plugin_init (void) addScriptCommand("setmount", "?", setMount); addScriptCommand("clientcommand", "s", clientCommand); addScriptCommand("isunitwalking", "?", isUnitWalking); + addScriptCommand("failedrefindex", "i", failedRefIndex); do_init_langs(); diff --git a/src/emap/script.c b/src/emap/script.c index 56dcc29..88b9f34 100644 --- a/src/emap/script.c +++ b/src/emap/script.c @@ -1263,3 +1263,20 @@ BUILDIN(isUnitWalking) script_pushint(st, ud->walktimer != INVALID_TIMER); return true; } + +BUILDIN(failedRefIndex) +{ + getSD() + getInventoryIndex(2) + + if (sd->status.inventory[n].nameid <= 0 || sd->status.inventory[n].amount <= 0) + return false; + + sd->status.inventory[n].refine = 0; + if (sd->status.inventory[n].equip) + pc->unequipitem(sd, n, PCUNEQUIPITEM_RECALC|PCUNEQUIPITEM_FORCE); + clif->refine(sd->fd, 1, n, sd->status.inventory[n].refine); + pc->delitem(sd, n, 1, 0, DELITEM_FAILREFINE, LOG_TYPE_SCRIPT); + clif->misceffect(&sd->bl, 2); + return true; +} diff --git a/src/emap/script.h b/src/emap/script.h index e999f4a..abf6b55 100644 --- a/src/emap/script.h +++ b/src/emap/script.h @@ -44,5 +44,6 @@ BUILDIN(getAreaDropItem); BUILDIN(setMount); BUILDIN(clientCommand); BUILDIN(isUnitWalking); +BUILDIN(failedRefIndex); #endif // EVOL_MAP_SCRIPT diff --git a/src/emap/scriptdefines.h b/src/emap/scriptdefines.h index 2121763..d35f71c 100644 --- a/src/emap/scriptdefines.h +++ b/src/emap/scriptdefines.h @@ -7,49 +7,82 @@ #define getSessionDataReturn(def) \ if (!st->rid) \ { \ + ShowWarning("!st->rid\n"); \ + script->reportsrc(st); \ script_pushint(st, def); \ - return true; \ + return false; \ } \ TBL_PC *sd = script->rid2sd(st); \ if (!sd) \ { \ + ShowWarning("player not attached\n"); \ + script->reportsrc(st); \ script_pushint(st, def); \ - return true; \ + return false; \ } \ struct SessionExt *data = session_get(sd->fd) #define getSessionData(data) \ if (!st->rid) \ - return true; \ + { \ + ShowWarning("!st->rid\n"); \ + script->reportsrc(st); \ + return false; \ + } \ TBL_PC *sd = script->rid2sd(st); \ if (!sd) \ - return true; \ + { \ + ShowWarning("player not attached\n"); \ + script->reportsrc(st); \ + return false; \ + } \ struct SessionExt *data = session_get(sd->fd) #define getMapData(m) \ struct MapdExt *mapData = mapd_get(m); \ if (!mapData) \ - return true; + { \ + ShowWarning("cant get map data\n"); \ + script->reportsrc(st); \ + return false; \ + } #define getMapDataReturn(m, def) \ struct MapdExt *mapData = mapd_get(m); \ if (!mapData) \ { \ + ShowWarning("cant get map data\n"); \ + script->reportsrc(st); \ script_pushint(st, def); \ - return true; \ + return false; \ } #define getSD() \ TBL_PC *sd = script->rid2sd(st); \ if (!sd) \ - return true + { \ + ShowWarning("player not attached\n"); \ + script->reportsrc(st); \ + return false; \ + } #define getSDReturn(def) \ TBL_PC *sd = script->rid2sd(st); \ if (!sd) \ { \ + ShowWarning("player not attached\n"); \ + script->reportsrc(st); \ script_pushint(st, def); \ - return true; \ + return false; \ + } + +#define getInventoryIndex(idx) \ + const int n = script_getnum(st, idx); \ + if (n < 0 || n >= MAX_INVENTORY) \ + { \ + ShowWarning("Wrong inventory index\n"); \ + script->reportsrc(st); \ + return false; \ } #endif // EVOL_MAP_SCRIPTDEFINES |