summaryrefslogtreecommitdiff
path: root/src/emap/script.c
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-08-21 18:01:32 +0300
committerAndrei Karas <akaras@inbox.ru>2015-08-21 20:11:59 +0300
commit36fb4cda271bda394b7e5e3b5911c6d9858aa8f8 (patch)
tree5f196194ab5e3810cfbc4d8346b275cbf1f41583 /src/emap/script.c
parent2a2edf5da86b7a5847f62242744376e7a9b304c7 (diff)
downloadevol-hercules-36fb4cda271bda394b7e5e3b5911c6d9858aa8f8.tar.gz
evol-hercules-36fb4cda271bda394b7e5e3b5911c6d9858aa8f8.tar.bz2
evol-hercules-36fb4cda271bda394b7e5e3b5911c6d9858aa8f8.tar.xz
evol-hercules-36fb4cda271bda394b7e5e3b5911c6d9858aa8f8.zip
Add script functions requestItemIndex and requestItemsIndex.
This functions request from player inventory indexes for items. Example: requestItemIndex @item; requestItemsIndex @item$, num;
Diffstat (limited to 'src/emap/script.c')
-rw-r--r--src/emap/script.c157
1 files changed, 136 insertions, 21 deletions
diff --git a/src/emap/script.c b/src/emap/script.c
index 656d415..56dcc29 100644
--- a/src/emap/script.c
+++ b/src/emap/script.c
@@ -88,7 +88,7 @@ BUILDIN(setCamNpc)
y = script_getnum(st, 4);
}
- send_npccommand2(script->rid2sd (st), st->oid, 2, nd->bl.id, x, y);
+ send_npccommand2(sd, st->oid, 2, nd->bl.id, x, y);
return true;
}
@@ -185,7 +185,7 @@ BUILDIN(npcTalk3)
BUILDIN(closeDialog)
{
getSD();
- send_npccommand(script->rid2sd (st), st->oid, 5);
+ send_npccommand(sd, st->oid, 5);
return true;
}
@@ -287,7 +287,7 @@ BUILDIN(requestLang)
st->state = RERUNLINE;
// send lang request
- send_npccommand(script->rid2sd(st), st->oid, 0);
+ send_npccommand(sd, st->oid, 0);
clif->scriptinputstr(sd, st->oid);
}
else
@@ -324,7 +324,7 @@ BUILDIN(requestItem)
if (is_string_variable(name))
{
- ShowError("script:requestlang: not a variable\n");
+ ShowError("script:requestitem: not a variable\n");
script->reportsrc(st);
return false;
}
@@ -336,7 +336,7 @@ BUILDIN(requestItem)
st->state = RERUNLINE;
// send item request
- send_npccommand(script->rid2sd(st), st->oid, 10);
+ send_npccommand(sd, st->oid, 10);
}
else
{
@@ -406,7 +406,135 @@ BUILDIN(requestItems)
st->state = RERUNLINE;
// send item request with limit count
- send_npccommand2(script->rid2sd (st), st->oid, 10, count, 0, 0);
+ send_npccommand2(sd, st->oid, 10, count, 0, 0);
+ }
+ else
+ {
+ // take received text/value and store it in the designated variable
+ sd->state.menu_or_input = 0;
+
+ if (!sd->npc_str)
+ {
+ 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));
+ st->state = RUN;
+ }
+ return true;
+}
+
+BUILDIN(requestItemIndex)
+{
+ 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))
+ {
+ ShowError("script:requestitemindex: not a variable\n");
+ script->reportsrc(st);
+ return false;
+ }
+
+ if (!sd->state.menu_or_input)
+ {
+ // first invocation, display npc input box
+ sd->state.menu_or_input = 1;
+ st->state = RERUNLINE;
+
+ // send item request
+ if (client || client->clientVersion >= 11)
+ send_npccommand(sd, st->oid, 11);
+ else
+ clif->scriptinputstr(sd, st->oid);
+ }
+ else
+ {
+ // take received text/value and store it in the designated variable
+ sd->state.menu_or_input = 0;
+
+ int item = 0;
+
+ if (!sd->npc_str)
+ {
+ ShowWarning("npc string not found\n");
+ script->reportsrc(st);
+ return false;
+ }
+
+ if (sscanf (sd->npc_str, "%5d", &item) < 1)
+ {
+ ShowWarning("input data is not item id\n");
+ script->reportsrc(st);
+ return false;
+ }
+
+ script->set_reg(st, sd, uid, name, (void*)h64BPTRSIZE(item), script_getref(st,2));
+ st->state = RUN;
+ }
+ return true;
+}
+
+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;
+ }
+
+ int count = 1;
+
+ if (script_hasdata(st, 3))
+ {
+ count = script_getnum(st, 3);
+ if (count < 0)
+ count = 1;
+ }
+
+ if (!sd->state.menu_or_input)
+ {
+ // first invocation, display npc input box
+ sd->state.menu_or_input = 1;
+ st->state = RERUNLINE;
+
+ // send item request with limit count
+ if (client || client->clientVersion >= 11)
+ send_npccommand2(sd, st->oid, 11, count, 0, 0);
+ else
+ clif->scriptinputstr(sd, st->oid);
}
else
{
@@ -546,14 +674,7 @@ BUILDIN(countItemColor)
int nameid, i;
int count = 0;
struct item_data* id = NULL;
-
- TBL_PC* sd = script->rid2sd(st);
- if (!sd)
- {
- ShowWarning("player not attached\n");
- script->reportsrc(st);
- return false;
- }
+ getSD();
if (script_isstringtype(st, 2))
{
@@ -1103,14 +1224,8 @@ BUILDIN(setMount)
BUILDIN(clientCommand)
{
- TBL_PC* sd = script->rid2sd(st);
+ getSD();
- if (sd == NULL)
- {
- ShowWarning("player not attached\n");
- script->reportsrc(st);
- return false;
- }
const char *const command = script_getstr(st, 2);
if (!command)
{