From 3d76d08ce39ea9f4d4d4e0f015eec74ec6653cd3 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 29 Jan 2016 00:20:54 +0300 Subject: Change script function requestitemsindex to return value. --- src/emap/init.c | 2 +- src/emap/script.c | 31 +++++-------------------------- src/emap/scriptdefines.h | 18 ++++++++++++++++++ 3 files changed, 24 insertions(+), 27 deletions(-) (limited to 'src/emap') diff --git a/src/emap/init.c b/src/emap/init.c index 33405b0..47c823d 100644 --- a/src/emap/init.c +++ b/src/emap/init.c @@ -100,7 +100,7 @@ HPExport void plugin_init (void) addScriptCommand("requestitem", "", requestItem); addScriptCommand("requestitems", "*", requestItems); addScriptCommand("requestitemindex", "", requestItemIndex); - addScriptCommand("requestitemsindex", "v*", requestItemsIndex); + addScriptCommand("requestitemsindex", "*", requestItemsIndex); addScriptCommand("requestcraft", "*", requestCraft); addScriptCommand("initcraft", "s", initCraft); addScriptCommand("dumpcraft", "i", dumpCraft); diff --git a/src/emap/script.c b/src/emap/script.c index 8d5cb44..d2281d6 100644 --- a/src/emap/script.c +++ b/src/emap/script.c @@ -768,34 +768,12 @@ BUILDIN(requestItemIndex) BUILDIN(requestItemsIndex) { - getSessionData(client); - struct script_data* data; - int64 uid; - const char* name; - - data = script_getdata(st, 2); - if (!data_isreference(data)) - { - ShowError("script:requestitem: not a variable\n"); - script->reportsrc(st); - st->state = END; - return false; - } - uid = reference_getuid(data); - name = reference_getname(data); - - if (!is_string_variable(name)) - { - ShowWarning("parameter is not variable\n"); - script->reportsrc(st); - return false; - } - + getSessionDataReturnS(client, "-1"); int count = 1; - if (script_hasdata(st, 3)) + if (script_hasdata(st, 2)) { - count = script_getnum(st, 3); + count = script_getnum(st, 2); if (count < 0) count = 1; } @@ -819,12 +797,13 @@ BUILDIN(requestItemsIndex) if (!sd->npc_str) { + script_pushstr(st, aStrdup("-1")); ShowWarning("npc string not found\n"); script->reportsrc(st); return false; } - script->set_reg(st, sd, uid, name, (void*)sd->npc_str, script_getref(st, 2)); + script_pushstr(st, aStrdup(sd->npc_str)); st->state = RUN; } return true; diff --git a/src/emap/scriptdefines.h b/src/emap/scriptdefines.h index 5d462f4..274f8f4 100644 --- a/src/emap/scriptdefines.h +++ b/src/emap/scriptdefines.h @@ -22,6 +22,24 @@ } \ struct SessionExt *data = session_get(sd->fd) +#define getSessionDataReturnS(data, def) \ + if (!st->rid) \ + { \ + ShowWarning("!st->rid\n"); \ + script->reportsrc(st); \ + script_pushstr(st, aStrdup(def)); \ + return false; \ + } \ + TBL_PC *sd = script->rid2sd(st); \ + if (!sd) \ + { \ + ShowWarning("player not attached\n"); \ + script->reportsrc(st); \ + script_pushstr(st, aStrdup(def)); \ + return false; \ + } \ + struct SessionExt *data = session_get(sd->fd) + #define getSessionData(data) \ if (!st->rid) \ { \ -- cgit v1.2.3-70-g09d2