Jump to content
  • 0

How to separate arrays in a menu?


Selerie

Question


  • Group:  Members
  • Topic Count:  9
  • Topics Per Day:  0.01
  • Content Count:  13
  • Reputation:   0
  • Joined:  12/27/21
  • Last Seen:  

	mes "Monster ID: "+getmonsterinfo(.@mob_id,MOB_NAME)+"'";
	if (getmobdrops(.@mob_id)) {	// 'getmobdrops' returns 1 on success
		// immediately copy global temporary variables into scope variables,
		// since we don't know when 'getmobdrops' will get called again for
		// another mob, overwriting your global temporary variables
		.@count = $@MobDrop_count;
		copyarray .@item[0],$@MobDrop_item[0],.@count;
		copyarray .@rate[0],$@MobDrop_rate[0],.@count;

		mes getmonsterinfo(.@mob_id,MOB_NAME) + " - " + .@count + " drops found:";
		for( .@i = 0; .@i < .@count; .@i++ ) {
			.@menu$ = .@menu$ + .@item[.@i] + " (" + getitemname(.@item[.@i]) + ") " + .@rate[.@i]/100 + ((.@rate[.@i]%100 < 10) ? ".0":".") + .@rate[.@i]%100 + "%";
		}
		.@menu$ = .@menu$ + ":";
	} else {
		mes "Unknown monster ID.";
	}
	.@part = .@count[select(.@menu$)];

Can someone help me separate the menu instead of 1 line?

screenrathenaPRE000.jpg

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

  • Group:  Members
  • Topic Count:  16
  • Topics Per Day:  0.00
  • Content Count:  662
  • Reputation:   671
  • Joined:  11/12/12
  • Last Seen:  

The separator used for menus is the colon, ":". So just change "%" to "%:".

Though, this line:

.@part = .@count[select(.@menu$)];

doesn't make a whole lot of sense. Keep in mind that select returns the first value as 1 instead of 0, so you have to remove 1. What you probably wanted to write was the following.

.@selected = select(.@menu$) - 1;
.@itemid = .@item[.@selected];

Also, not... an issue, but you'd probably want to change your variable names a bit by adding an 's' to your arrays otherwise it becomes very messy (and addding [0] is redundant).

copyarray .@items, $@MobDrop_item, .@count;

Also, might as well use sprintf for your drop rates, it makes your life easier. So something like this:

	mes "Monster ID: "+getmonsterinfo(.@mob_id,MOB_NAME)+"'";
	
	if (getmobdrops(.@mob_id)) {	// 'getmobdrops' returns 1 on success
		// immediately copy global temporary variables into scope variables,
		// since we don't know when 'getmobdrops' will get called again for
		// another mob, overwriting your global temporary variables
		.@count = $@MobDrop_count;
		copyarray .@items, $@MobDrop_item, .@count;
		copyarray .@rates, $@MobDrop_rate, .@count;

		mes getmonsterinfo(.@mob_id,MOB_NAME) + " - " + .@count + " drops found:";
		
		for (.@i = 0; .@i < .@count; .@i++) {
			.@menu$ = .@menu$ + sprintf("%d (%s) %d.%02d%%", .@items[.@i], getitemname(.@items[.@i]), .@rates[.@i] / 100, .@rates[.@i] % 100) + ":";
		}
		
		.@menu$ = .@menu$ + ":";
	}
	else {
		mes "Unknown monster ID.";
	}
	
	.@selected = select(.@menu$) - 1;
	.@item = .@items[.@selected];
	.@rate = .@rates[.@selected];

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...