From 92c1c98824efb789709d70ee8d6d5ed6e49b47a3 Mon Sep 17 00:00:00 2001 From: Fate Date: Wed, 13 May 2009 22:10:41 +0000 Subject: menu command: skip all options after (and including) the first option with a blank line --- src/map/script.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'src/map/script.c') diff --git a/src/map/script.c b/src/map/script.c index d731b3f..9378e33 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -1625,21 +1625,34 @@ int buildin_close2(struct script_state *st) int buildin_menu(struct script_state *st) { char *buf; - int len,i; + int i, len = 0; // [fate] len is the total # of bytes we need to transmit the string choices + int menu_choices = 0; + int finished_menu_items = 0; // [fate] set to 1 after we hit the first empty string + struct map_session_data *sd; sd=script_rid2sd(st); + // We don't need to do this iteration if the player cancels, strictly speaking. + for (i = st->start+2; i < st->end; i += 2) { + int choice_len; + conv_str(st,& (st->stack->stack_data[i])); + choice_len = strlen(st->stack->stack_data[i].u.str); + len += choice_len + 1; // count # of bytes we'll need for packet. Only used if menu_or_input = 0. + + if (choice_len && !finished_menu_items) + ++menu_choices; + else + finished_menu_items = 1; + } + if(sd->state.menu_or_input==0){ st->state=RERUNLINE; sd->state.menu_or_input=1; - for(i=st->start+2,len=16;iend;i+=2){ - conv_str(st,& (st->stack->stack_data[i])); - len+=strlen(st->stack->stack_data[i].u.str)+1; - } + buf=(char *)aCalloc(len,sizeof(char)); buf[0]=0; - for(i=st->start+2,len=0;iend;i+=2){ + for(i=st->start+2; menu_choices > 0; i+=2, --menu_choices){ strcat(buf,st->stack->stack_data[i].u.str); strcat(buf,":"); } @@ -1653,10 +1666,9 @@ int buildin_menu(struct script_state *st) pc_setreg(sd,add_str("l15"),sd->npc_menu); pc_setreg(sd,add_str("@menu"),sd->npc_menu); sd->state.menu_or_input=0; - if(sd->npc_menu>0 && sd->npc_menu<(st->end-st->start)/2){ + if(sd->npc_menu > 0 && sd->npc_menu <= menu_choices){ int pos; if( st->stack->stack_data[st->start+sd->npc_menu*2+1].type!=C_POS ){ - printf("script: menu: not label !\n"); st->state=END; return 0; } -- cgit v1.2.3-60-g2f50