summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgumi <git@gumi.ca>2018-10-10 16:23:19 -0400
committergumi <git@gumi.ca>2018-10-11 18:14:18 -0400
commite3df7d8ebda36542c477beba281dfc3f9c737af4 (patch)
treebc34170e800098ccee6246c0cd870644e239c160
parentbaeb7a1742b0fd7ac5d3a4cecd90f74d461895fe (diff)
downloadhercules-e3df7d8ebda36542c477beba281dfc3f9c737af4.tar.gz
hercules-e3df7d8ebda36542c477beba281dfc3f9c737af4.tar.bz2
hercules-e3df7d8ebda36542c477beba281dfc3f9c737af4.tar.xz
hercules-e3df7d8ebda36542c477beba281dfc3f9c737af4.zip
bake buildin_prompt into buildin_select and clarify the difference between the two
-rw-r--r--doc/script_commands.txt17
-rw-r--r--src/map/script.c98
-rw-r--r--src/map/script.h2
3 files changed, 23 insertions, 94 deletions
diff --git a/doc/script_commands.txt b/doc/script_commands.txt
index 64468ed49..aa7141951 100644
--- a/doc/script_commands.txt
+++ b/doc/script_commands.txt
@@ -1600,21 +1600,24 @@ perfectly equivalent.
---------------------------------------
*select("<option>"{, "<option>", ...})
-*prompt("<option>"{, "<option>", ...})
This function is a handy replacement for 'menu' that doesn't use a complex
-label structure. It will return the number of menu option picked,
-starting with 1. Like 'menu', it will also set the variable @menu to
-contain the option the user picked.
+label structure. It will return the number of the menu option picked,
+starting with 1. If the player presses cancel, the script is terminated.
- if (select("Yes:No") == 1)
+ if (select("Yes", "No") == 1)
mes("You said yes, I know.");
And like 'menu', the selected option is consistent with grouped options
and empty options.
-'prompt' works almost the same as select, except that when a character
-clicks the Cancel button, this function will return 255 instead.
+---------------------------------------
+
+*prompt("<option>"{, "<option>", ...})
+
+This function behaves exactly like select(), but when a player presses cancel
+it returns 255 and the script is not terminated. You almost always want to use
+select() rather than prompt().
---------------------------------------
diff --git a/src/map/script.c b/src/map/script.c
index 5eed58977..9682fea40 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -6216,103 +6216,27 @@ static BUILDIN(select)
ShowWarning("buildin_select: Too many options specified (current=%d, max=254).\n", sd->npc_menu);
script->reportsrc(st);
}
- } else if( sd->npc_menu == 0xff ) {// Cancel was pressed
+ } else if(sd->npc_menu == 0xff) { // Cancel was pressed
sd->state.menu_or_input = 0;
- st->state = END;
- } else {// return selected option
- int menu = 0;
-
- sd->state.menu_or_input = 0;
- for( i = 2; i <= script_lastdata(st); ++i ) {
- text = script_getstr(st, i);
- sd->npc_menu -= script->menu_countoptions(text, sd->npc_menu, &menu);
- if( sd->npc_menu <= 0 )
- break;// entry found
- }
- pc->setreg(sd, script->add_variable("@menu"), menu);
- script_pushint(st, menu);
- st->state = RUN;
- }
- return true;
-}
-/// Displays a menu with options and returns the selected option.
-/// Behaves like 'menu' without the target labels, except when cancel is
-/// pressed.
-/// When cancel is pressed, the script continues and 255 is returned.
-///
-/// prompt(<option_text>{,<option_text>,...}) -> <selected_option>
-///
-/// @see menu
-static BUILDIN(prompt)
-{
- int i;
- const char *text;
- struct map_session_data *sd = script->rid2sd(st);
- if (sd == NULL)
- return true;
-
-#ifdef SECURE_NPCTIMEOUT
- sd->npc_idle_type = NPCT_MENU;
-#endif
-
- if( sd->state.menu_or_input == 0 )
- {
- struct StringBuf buf;
-
- StrBuf->Init(&buf);
- sd->npc_menu = 0;
- for( i = 2; i <= script_lastdata(st); ++i )
- {
- text = script_getstr(st, i);
- if( sd->npc_menu > 0 )
- StrBuf->AppendStr(&buf, ":");
- StrBuf->AppendStr(&buf, text);
- sd->npc_menu += script->menu_countoptions(text, 0, NULL);
- }
-
- st->state = RERUNLINE;
- sd->state.menu_or_input = 1;
-
- /* menus beyond this length crash the client (see bugreport:6402) */
- if( StrBuf->Length(&buf) >= 2047 ) {
- struct npc_data * nd = map->id2nd(st->oid);
- char* menu;
- CREATE(menu, char, 2048);
- safestrncpy(menu, StrBuf->Value(&buf), 2047);
- ShowWarning("NPC Menu too long! (source:%s / length:%d)\n",nd?nd->name:"Unknown",StrBuf->Length(&buf));
- clif->scriptmenu(sd, st->oid, menu);
- aFree(menu);
- } else
- clif->scriptmenu(sd, st->oid, StrBuf->Value(&buf));
- StrBuf->Destroy(&buf);
-
- if( sd->npc_menu >= 0xff )
- {
- ShowWarning("buildin_prompt: Too many options specified (current=%d, max=254).\n", sd->npc_menu);
- script->reportsrc(st);
+ if (strncmp(get_buildin_name(st), "prompt", 6) == 0) {
+ pc->setreg(sd, script->add_variable("@menu"), 0xff);
+ script_pushint(st, 0xff);
+ st->state = RUN;
+ } else {
+ st->state = END;
}
- }
- else if( sd->npc_menu == 0xff )
- {// Cancel was pressed
- sd->state.menu_or_input = 0;
- pc->setreg(sd, script->add_variable("@menu"), 0xff);
- script_pushint(st, 0xff);
- st->state = RUN;
- }
- else
- {// return selected option
+ } else {// return selected option
int menu = 0;
sd->state.menu_or_input = 0;
- for( i = 2; i <= script_lastdata(st); ++i )
- {
+ for( i = 2; i <= script_lastdata(st); ++i ) {
text = script_getstr(st, i);
sd->npc_menu -= script->menu_countoptions(text, sd->npc_menu, &menu);
if( sd->npc_menu <= 0 )
break;// entry found
}
- pc->setreg(sd, script->add_variable("@menu"), menu);
+ pc->setreg(sd, script->add_variable("@menu"), menu); // TODO: throw a deprecation warning for scripts using @menu
script_pushint(st, menu);
st->state = RUN;
}
@@ -24978,7 +24902,7 @@ static void script_parse_builtin(void)
BUILDIN_DEF(close2,""),
BUILDIN_DEF(menu,"sl*"),
BUILDIN_DEF(select,"s*"), //for future jA script compatibility
- BUILDIN_DEF(prompt,"s*"),
+ BUILDIN_DEF2(select, "prompt", "s*"),
//
BUILDIN_DEF(goto,"l"),
BUILDIN_DEF(callsub,"l*"),
diff --git a/src/map/script.h b/src/map/script.h
index 9c72b793c..f05eb802c 100644
--- a/src/map/script.h
+++ b/src/map/script.h
@@ -177,6 +177,8 @@ struct item_data;
#define BUILDIN(x) bool buildin_ ## x (struct script_state* st)
+#define get_buildin_name(st) ( script->get_str((int)(script_getdata((st), 0)->u.num)) )
+
#define script_fetch(st, n, t) do { \
if( script_hasdata((st),(n)) ) \
(t)=script_getnum((st),(n)); \