summaryrefslogtreecommitdiff
path: root/src/map/script.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/map/script.c')
-rw-r--r--src/map/script.c44
1 files changed, 23 insertions, 21 deletions
diff --git a/src/map/script.c b/src/map/script.c
index 03ff19973..7abbe83df 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -4371,8 +4371,8 @@ int buildin_close2(struct script_state *st)
*/
int buildin_menu(struct script_state *st)
{
- char *buf;
- int len,i, max = 1;
+ char *buf, *ptr;
+ int len,i;
struct map_session_data *sd = script_rid2sd(st);
nullpo_retr(0, sd);
@@ -4399,11 +4399,11 @@ int buildin_menu(struct script_state *st)
strcat(buf,":");
}
}
- for(i=0; (unsigned int)i < strlen(buf); i++){
- if(buf[i] == ':')
- max++;
- }
- sd->npc_menu = max; //Reuse to store max menu entries. Avoids the need of an extra variable.
+
+ ptr = buf;
+ sd->npc_menu = 0; //Reuse to store max menu entries. Avoids the need of an extra variable.
+ while (ptr && (ptr = strchr(ptr, ':')) != NULL)
+ { sd->npc_menu++; ptr++; }
clif_scriptmenu(sd,st->oid,buf);
aFree(buf);
} else if(sd->npc_menu==0xff){ // cancel
@@ -10614,8 +10614,8 @@ int buildin_jump_zero(struct script_state *st) {
int buildin_select(struct script_state *st)
{
- char *buf;
- int len,i,max = 1;
+ char *buf, *ptr;
+ int len,i;
struct map_session_data *sd;
sd=script_rid2sd(st);
@@ -10633,11 +10633,12 @@ int buildin_select(struct script_state *st)
strcat(buf,st->stack->stack_data[i].u.str);
strcat(buf,":");
}
- for(i=0; (unsigned int)i < strlen(buf); i++){
- if(buf[i] == ':')
- max++;
- }
- sd->npc_menu = max; //Reuse to store max menu entries. Avoids the need of an extra variable.
+
+ ptr = buf;
+ sd->npc_menu = 0; //Reuse to store max menu entries. Avoids the need of an extra variable.
+ while (ptr && (ptr = strchr(ptr, ':')) != NULL)
+ { sd->npc_menu++; ptr++; }
+
clif_scriptmenu(sd,st->oid,buf);
aFree(buf);
} else if(sd->npc_menu==0xff){
@@ -10659,8 +10660,8 @@ int buildin_select(struct script_state *st)
int buildin_prompt(struct script_state *st)
{
- char *buf;
- int len,i,max = 1;
+ char *buf, *ptr;
+ int len,i;
struct map_session_data *sd;
sd=script_rid2sd(st);
@@ -10679,11 +10680,12 @@ int buildin_prompt(struct script_state *st)
strcat(buf,st->stack->stack_data[i].u.str);
strcat(buf,":");
}
- for(i=0; (unsigned int)i < strlen(buf); i++){
- if(buf[i] == ':')
- max++;
- }
- sd->npc_menu = max; //Reuse to store max menu entries. Avoids the need of an extra variable.
+
+ ptr = buf;
+ sd->npc_menu = 0; //Reuse to store max menu entries. Avoids the need of an extra variable.
+ while (ptr && (ptr = strchr(ptr, ':')) != NULL)
+ { sd->npc_menu++; ptr++; }
+
clif_scriptmenu(sd,st->oid,buf);
aFree(buf);
} else {