CUSTOM ITEM MENU IN RM2K3

One way of implementing your custom made item menu in rm2k3

  • Kazesui
  • 12/28/2010 10:12 PM
  • 19193 views
I'd like to expand on narcodis's simple cms by adding how to implement your own item menu.
If you want to make your own custom menu, you should take a look at his tutorial and get familiar with it first.
you can find his tutorial here: http://rpgmaker.net/tutorials/395/

We'll be using pointers in this tutorial so I'll start by briefly explaining how they work:


The marked fields are used to indicate that you want point to a variable indirectly. For example if "ptrA" contains the value 6 here, then this operation would add 3 to the variable with 0006 as ID.
Likewise, if you'd use to lower marked field, you would first take the value of the variable there, let's say it's 2, then you would add the value of the variable with ID 0002.
If you still don't entirely understand the concept, I recommend you take a closer look at this tutorial on them: Tutorial on Pointers

Moving on.
This menu is based on being called upon from some instance, for example from the confirm section of a custom menu. Once called upon, this code should execute


We start by setting some initial parameters, which I'll explain one by one.
"Cursor" contains a value reflecting it's current position in the menu, with 0 being the first position.
"Cursor x " and "Cursor y" is the screen relative coordinates of the cursor, which we use in connection with "move picture" to display the cursor at the right position.
We also show the menuframe and cursor with show picture commands here, And perform 2 event calls Which will get right back to.

After the initial parameters has been set, we set a label, so that we can create a loop until we're done with the item menu. Right after the label, we'll want to add code which will happen for every action, like updating the position of the cursor. We then place a "key input" command, which wait's until a key has been hit, and then checks which key has been hit with branches.

Now, let's take a look at the event calls performed in the inital parameter section

This is the "MakeList" call. What it does, is to assign values corresponding to different items in a list of variables. This is done by checking if the hero party has the item in question in a certain order. Here it's done alphabetically, because this makes it easier to work with the pictures later on. The list of variables we'll use will span from variable 0041 to 0048.

We start by setting ptrA and itmListPtr to 41, which marks the ID of the first variable in our list.
We then check if the hero has any Antidotes. If yes, then we set the variable with ID equal to ptrA to 1, meaning that any '1' found in the list, will represent an antidote. After this value has been set, ptrA increments with 1 so that it points on the next item. It will continue like this until it has checked for all existing items. Once this is done, it will set any remaining elements in the list to 0. This is is basically just to clean up any old values still left in the list of variables.

You can have a number of events like this, if you'd like to have different sorting criterias, just by rearranging the conditional branches. I recommend that the values representing the items correspond to their alphabetical order though.

And now for the ShowList call

The concept here, is that we check the first item in the list we just created with as many branches as there are unique items. This has to be done for as many item slots you want your menu to be able to show.

Again we start with some initial parameters before we starting showing the pictures for the different items.
We set the coordinates for the first in picture in variables, and we get the value of the first item in the list
(ItmListTmp takes the value of the ID itmListPtr is pointing to).
We set the coordinates to the pictures in variables mainly for 2 reasons. First off, because if we have made a mistake in coordinates anywhere, we only have to adjust the variables, rather than a ton of pictures. If you have many items, and you simply forgot to fix the coordinates for one slot, it will be a true pain to fix it afterwards, so you should always use variables when showing a single pic from a given list of branches. The second reason, is because it makes it easier to copy paste. By using pointers to get the value of the current item in the list, and by using variables for coordinates, the only thing you need to change while going through the list for the different slots is the picture ID.

Here, we also store the amount we have of the certain item in a temporary variable ptrC. The call for "Item Count" takes this value and get the digits of it and show it as pictures next to the item. itmListPtr then increments with 1 so that itmListTmp can get the value of the next item in the list. We also increase the
pic y coordinate with 16 since that's the amount of distance we want for our pictures.

This process is repeated for every slot you want, and at the end you subtract the amount you've added to itmListPtr so that it returns to it's original value.


This event shows the call for "Item Count". It's given as a map event with several pages. The only difference between the pages here, are the ID's for the pictures. You could also store them in a long list and split them with branches instead, but I like eventpages instead. it's also more efficient to directly call an event page rather than going through a big list of branches.

The first thing we do here, is to check if there's no item at the slot. if so, then we are to erase any numbers which should not be there and end the event straight away. If not, we can take the value and get its digits.
both variable 28 and 29 takes the value of ptrC here. It's generally good if you can line up a lot of variables who'll get the same value, since this can be done in one operation.
since rm2k3 only takes integer values (natural numbers), dividing by 10, will eliminate any number in the one position, and modulo 10 will eliminate any number in the digits before the one position. Using this we obtain the digit for one and ten. And we check them towards the numbers available, normally from 0 to 9, with some special checks to avoid leading zeros (As the code shows, I've been a little lazy here).

the pic x and pic y are the same variables as those use for setting the item pictures. Since the numbers will always be on the same place relative to the item picture, some simple adding and subtracting can be done to get the coordinates of the number. You shouldn't forget to return them to their original values (i.e. the one before the event call), at the end though, since they might still be needed in the event which called this event.

At this point, we can have an Item Menu looking like this:

We here have an item menu with 4 slots. If the hero has more than 4 items, the player can press right to go to another page of items as long as there are more pages with items available. Mind you that in this tutorial, we've only been using space from 41 to 48, meaning 2 full pages.

For how we'll interact with the menu, we take another look at the ItemMenu event, spesifically, the branches which deal with the arrow keys


1 and 4, i.e. down and up are fairly simple. The branch for the down key checks if the cursor is above the bottom slot and moves the cursor down by 16 pixels if it isn't, but returns it to the top by subtracting 3x16 pixels if it is. the branch for the up key is the same, just vice versa.

2, the left key that is checks if the itmListPtr is on 41, which marks the beginning of the list. If it is, then it won't do anything. But if itmListPtr is higher, it means it's on a "higher" page, meaning there has to be a lower as well, and it'll subtract 4 from itmListPtr to point to the 4 first items in the list. That is, it only points to the first item, but the "ShowItem" event, shows up to 4 items, so you can say that it's pointing to the 4 first items.

3, the right key shall open a new page to the right, if there are items on that page. Here we make use of the calculation from the "MakeList" call revolving around the variable "pages". It based itself on how many items you have, and decreases this with a certain constant, and then divides by the amount of items you can have on a page. The constant is there so that you'll get 2 after dividing by 4 if you have between 5 and 8 items. Hitting the right key, will check if the "current page" variable is lower than the "pages" variable, meaning there's another page to access. It further increases the current page by 1.

Both left and right key call "ShowList" again, because we now need to show new items, depending on what page we're on.

Now, we're almost done. We only have to add functionality to the items, and we need to be able to remove them when we have none left.

Item Effects


When the confirm key is pressed, ptrA first take the value of itmListPtr and then adds the value of the cursor, thus we have the position of the current item in our list of variables. ptrB takes the value in the variable ptrA is pointing to, so that we know what item we're using. Now we call the event "Item Effects".

It starts by setting a switch "zero item" to off. This switch is used to determine if the item count has dropped to 0 after this usage. Next we check if there was an item at the position where we hit confirm. If not, we end the event right there.
Then we check for as many items as there are, and execute the effect once found. we also subtract the item in question by one and then check if the hero party still has that item, and if not, the zero item switch is turned on.

Once the event is done, it will return to the item menu event, where it will now check if the item count dropped to 0 for the current item. If yes, then the variable which ptrA is pointing to will be set to 0, meaning there's no item there anymore.
We then call "showList" again, to display the changes, and the loop continues.

Further on, choosing the cancel key, will erase all picture and then return to whatever called the event.

Something you may have noticed is my message "Error: bottom reached" at the bottom of the event process in the item menu event. This is because at the end of each branch, there's a jump to label 1 statement (or end event in case of cancel), which means you should never be able to reach the bottom of the event. If this happens, something unexpected has happened, and I like to notified about it.


And that's about it. With this you should have created a simple item menu of your own. A little bit confusing?
Well yeah, when it comes to custom stuff like this, there are a lot of ends to tie together, so there's a lot to wrap your mind around.
If you want to take a closer look at the code, you can download it here: sample project

it's the project directory, with the code and some pictures to make the menu. not that it should be a problem, but it requires rm2k3 rtp.

good luck with designing your item menus

Posts

Pages: 1
Hmm! I think I'll try out both menus. God knows I'm no good with code. Thanks a lot >>b
This is a really nice tutorial, and it's easy. I think I'll try it out myself as well.
I haven't been able to get the page-changing command to work.

Basically, everything works, but switching pages. Mainly, I can't figure it out because I can't make out what exactly certain variables mean, which are involved into page changes.

Here is the beginning and end of my MakeList:




Don't bother with the numbers inside the branches. The -31 and such where merely assumption based, but didn't work (as somany other combinations). The difference between my menu and the menu in the tutorial:

I have 38 spots for items and display 10 items per page.
I didn't understand why ptrA and itemlistPtr were set to 41, and why at the end you set ptrA 50 Less/Equal. Is this in any relation to the amount of items shown per page / amount of items existing?

Also here is the code In my key input for the page changing:


Again don't wonder about the -3. First I assumed I should take -10/+10 (considering the -4/+4 in the tutorial are based on the amount of items per page)

So, while switching left works once, further left clicks will result in total chaos (empty pages, pages showing the same item twice, random items somewhere in the list etc.)

While pressing right will usually show an empty page or doesn't allow switching.
If this is too much I'm asking for, I might be able to find the problems by myself if someone explains the mentioned variables to me.

Thanks!
author=White_Rabbit
I have 38 spots for items and display 10 items per page.
I didn't understand why ptrA and itemlistPtr were set to 41, and why at the end you set ptrA 50 Less/Equal. Is this in any relation to the amount of items shown per page / amount of items existing?

The reason ptrA and itemListPtr is set to 41 because "make_list" is initating a menu, so both needs to be "reset"... kind of.
they are set to 41, because that's where I decided to keep the values of my items. If you want to store your items from variables 101 to 200 (would mean that you have 100 unique items), you would set them 101 instead. In this sense, its kind of arbitrary what values you choose, as long as you dont use the variables in the range for something else.

ptrA is doing all the work in "make_list". It starts to fill your entire list with the ID of the items in your inventory. If you have an antidote, the first slot in your menu will contain antidote, if you dont have any miracle water, but you have mana potion(s), then slot 2 will hold mana potion. (which is decided by the number which is given by the number 3 here)

in this tutorial, the variables 41 to 50 holds the self given ids of the items as they will be presented in the list. since this menu only holds 4 items at a time, first page will give 41 to 44, next page will give 45 to 48 and so on. This is done by having itemListPtr point at the first item of a page, and then showing as many items as can be shown on a page.

So this mean that, yes, your initial assumption was correct, you were supposed to add and decrease itemListPtr by 10, since you have 10 items per page.

However, you seem to have kept the 41 to 50 range, which can only store 10 items at most, in other word not sufficient for your 38 items. The range has to go until 78 at least to contain all possible items. This also means that you must not be using variable 41 to 78 for anything else. You should probably free until variable 80 though, since last page would go from 71 to 80, and making sure that 79 and 80 are zero, you dont need to put in extra branches as to not include those.

This means you'll have to change the branch which checks if ptrA is less than 50 to 78.
The reason for that branch to begin with is that once you do a new "make_list" there might be still items which you used up last time you opened the menu, but which wasn't cleared out for whatever reason, so you just set every variable beyond the last item to 0, meaning there is no item there.

hope this was of some help
Thanks for helping me.
I can imagine how your hand wanders in direction of your forehead when reading this:
Changing the range from 50 to 80 only changed that my cursor wanders into the upper left corner of the screen. Switching to 80 greater would bring him back (as well as 50 less equal, out of curiousness, the breakpoint where this happens is 78, at 77 it gets pushed only into the left corner of the screen, 76 it's normal. This is way beyond my abilities. I mean, I tested it in your demo project, and that doesn't happen there. I also understand everything you said there. And it doesn't even make any sense, the cursor is in no relation to ptr. I've even deactivated the key-branches, as it might have been coming from there, but it still changed position. Switching pages still results in weird stuff, switching to left pushes the items 1 row down every time, creating empty spots. Switching right shows blank pages. I've been carefully reading all the codes for everything like 5 times to find the mistake, even showlist. But I guess it can't be helped.

Btw are the variables for pages correct like this?
from 50 to 80 or from 51 to 80? (I'm going to assume the latter).
If you're using this range, rather than from 41 as in the tutorial, you will of course have to change the - 31 to -41 instead, such that it will know the correct amount of pages to show.

Also, if you're using the range from 51 to 80, then you should have the branch check for "Branch if ptrA is 80 less/equal"
This branch should always have the value of the last variable you'll be using to store the items for the menu.

Changing the range from 51 to 80 would bring one other problem as well if you have 38 items. 51 to 80 = only 30 variables. If you make a test with more than 30 items, it will start overwriting variables you have after variable 80. If the variables dealing with the position of the cursor would happen to be right after variable 80, this could be a reason for your troubles. Also, if you had 80 greater as branch, and you were testing with 30 differnt items or more, it would come at the effect that would set all variables beyond the last item to 0.

if this happened, it should have been very noticable due to lag though, as you'd have an infinite loop running wild.
Nonono, I set it from 41-80 instead of 41-50. that's what I ment. Also I didn't say I put greater than, but that Greater than leaves my cursor where it is, while less than (the proper option) pushes him into the upper left corner of the screen. Again, 78-80 less than = cursor gets pushed into the upper left corner. At 77 it gets pushed only to the left corner, at 76 (and less) it stays normal. In all cases, changing pages still doesn't work. The problem lies way deeper. I've even gone that far that I've cloned the whole menu from your tutorial, only keeping my own makelist and showlist (and self explaining, returning the variable/switch links) , but it didn't work, so the problem could come from either of these (makelist/showlist). One of these also includes these variables -

I don't know if changing these could fix anything, as -31 and /10 where assumption-based as well.
I'm not 100% sure but I think I found the miraculous variable.
At the end of the tutorial's showlist, you've put an Var Oper ItemListPtr - 3. I didn't have this in mine (I repeated the ItemlistPtr+1 / itemlisttmp set car V itemlistptr, which came after every spot). I've changed it into -3 now aswell but it didn't work. However, testing it in your tutorial, after changing 3 to whatever else, it started changing pages in a similair way to mine (showing random items and numbers). If that is the case, I might have to use a different variable, but I haven't figured out yet why you've actually set it to -3, or in what relation this stands to.
Edit: nvm it was 9. I finally got it to work now!!
Sorry for the troubles.
I know this topic's pretty old, but I'm hoping someone can help here. I'm trying to keep the played from moving the cursor to empty spots in the menu. So far I'm successful, but I'd like to make it so if you are changing pages it will automatically go to the closest filled item slot.
I'm using 6 item slots per page and the pages move down and up versus left and right, so if the cursor is currently in position 6, but there is no item in position 3 it will check position 2 and then position 1. Right now it only checks position 3 and I can't seem to figure out how to get it to check the other positions without lots of unnecessary code.

The way it works right now, the game first does all the work to move the cursor without moving the cursor image and then performs all the functions it would to normally select that item. If the variables return there is no item present then it returns all the variables to the last cursor position.

<>Variable Oper: [3034:itemListPtr] +, 6
<>Variable Oper: [3026:Current Page]+, 1
<>Variable Oper: [3030:Cursor]-, 3
<>Variable Oper: [3030:Cursor (y)]-, 46
<>Variable Oper: [3038:Ptr A] Set, Var [3034]'s Value
<>Variable Oper: [3038:Ptr A] +, Var [3030]'s Value
<>Variable Oper: [3039:Ptr B] Set, Var [V3038]] Value
<>Branch if Var [3039:Ptr B] is 0
<>Variable Oper: [3032:Cursor(y)]+, 46
<>Variable Oper: [3030:Cursor]+, 3
<>Variable Oper: [3034:itemListPtr]-, 6
<>Variable Oper: [3026:Current Page]-, 1
<>Jump to Label: 1
:End

And that works, but I can't think of a good way to check the slots next to it. I may end up just having it default to the first slot no matter what to make things simple.
Hello! Thank you so much for this. I was wondering if anybody knew any way to add item sprites next to an item's name in the inventory/battle screens in RPG Maker 2003, and how to a picture appear when an item is used in battle?

I've been searching and turning Google upside down but haven't found anything along these lines ;_; Thank you!
Ahhh so sorry for the misplaced question!! I was trying to figure out how to land on the main forum page but the website's a bit confusing to navigate (I could find articles and tutorials and stuff but couldn't figure out forums). Thank you so much for the quick reply though! I'll give the glyphs a shot - and I'll try asking on the main forums too, once I figure out how to get there. *_*
D'oh, there it is! Thanks again so much for being so accommodating of this very much newbie newb ; u ; / I'll try to be more careful next time where I post, too!!
Pages: 1