Jump to content
  • 0

Removing array in choices if condition is not met


Xellyehria

Question


  • Group:  Members
  • Topic Count:  7
  • Topics Per Day:  0.00
  • Content Count:  22
  • Reputation:   1
  • Joined:  10/19/16
  • Last Seen:  

 

I wanted to create an array menu where the choices in that array will only show if the player have the item in his inventory.

To make it simple I wanted to make a script where player can store a list of cards from the list I made in an array. However since there's a lot of card in the list I would like to reduce the choices in the menu by only showing the cards that they have in the inventory. If they don't have the cards in the inventory I don't want it to show in the menu.

I am a complete newbie in this so your help will be greatly appreciated.

This is currently the one I am using but it show every card.

query_sql( "SELECT `card_id`, `card_name`, `card_type` FROM `card_list` WHERE `card_race` = 'monster' ORDER BY `card_name` ASC limit 500 ",.@iid,.@in$,.@tp$);
    .@size = getarraysize( .@iid );
    for( .@i = 0; .@i < .@size; .@i++ )
        set .@menu$,.@menu$ + .@in$[.@i] +" - " + .@tp$[.@i] + ":";
    .@i = select( .@menu$ ) - 1;
    set .itemid,.@iid[.@i];

At one point I managed through trial and error to make it only show the card name in the list if they have one in the inventory but when I check the ID of their choice it's different on the menu they clicked.

ex. They clicked Poring Card but the item id is Pupa Card...

I would really appreciate any help because I don't understand what I am doing and I am completely newbie in this. Thank you in advanace.

 

 

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0

  • Group:  Forum Moderator
  • Topic Count:  93
  • Topics Per Day:  0.02
  • Content Count:  10015
  • Reputation:   2348
  • Joined:  10/28/11
  • Last Seen:  

query_sql( "SELECT `card_id`, `card_name`, `card_type` FROM `card_list` WHERE `card_race` = 'monster' ORDER BY `card_name` ASC limit 500 ",.@iid,.@in$,.@tp$);
.@size = getarraysize( .@iid );
for( .@i = 0; .@i < .@size; .@i++ ) {
	if (countitem(.@iid[.@i]) >= 1)
		set .@menu$, .@menu$ + .@in$[.@i] +" - " + .@tp$[.@i];
	set .@menu$, .@menu$ + ":";
}
.@i = select( .@menu$ ) - 1;

or

getinventorylist;
for (.@i = 0; .@i < @inventorylist_count; .@i++) {
	if (getiteminfo(@inventorylist_id[.@i],2) == IT_CARD)
		.@menu$ = .@menu$ + getitemname(@inventorylist_id[.@i]);
	.@menu$ = .@menu$ + ":";
}
.@i = select( .@menu$ ) - 1;

 

  • Upvote 1
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  26
  • Topics Per Day:  0.01
  • Content Count:  350
  • Reputation:   43
  • Joined:  09/07/12
  • Last Seen:  

you can use "@inventorylist" (iirc) to get the inventory or the player,

then check for the cards item in the list then display the item name using "getitemname".

 

i suggest reading the docs that will save you a lot of time.

 

also be   aware that arrays index start from '0' not '1'

  • Upvote 1
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  7
  • Topics Per Day:  0.00
  • Content Count:  22
  • Reputation:   1
  • Joined:  10/19/16
  • Last Seen:  

14 minutes ago, Emistry said:

query_sql( "SELECT `card_id`, `card_name`, `card_type` FROM `card_list` WHERE `card_race` = 'monster' ORDER BY `card_name` ASC limit 500 ",.@iid,.@in$,.@tp$);
.@size = getarraysize( .@iid );
for( .@i = 0; .@i < .@size; .@i++ ) {
	if (countitem(.@iid[.@i]) >= 1)
		set .@menu$, .@menu$ + .@in$[.@i] +" - " + .@tp$[.@i];
	set .@menu$, .@menu$ + ":";
}
.@i = select( .@menu$ ) - 1;

 

 

I think the first one is similar on what I've come up with the trial and error. Unfortunately while it doesn't show the missing cards in the inventory it causes error on the selection. Example if the array contains poring card and pupa card and it is on ascending order by name. If I don't have poring card it won't show in the menu, only the pupa card will... however after I select pupa card it display the ID of poring card instead. I think although it doesn't show in the choices the menu keep it's ID instead. Is there another way to fix this so I could use it in the other script?

the inventory one is very useful for me though. Thank you very very much!

Link to comment
Share on other sites

  • 0

  • Group:  Forum Moderator
  • Topic Count:  93
  • Topics Per Day:  0.02
  • Content Count:  10015
  • Reputation:   2348
  • Joined:  10/28/11
  • Last Seen:  

hmm?

1 hour ago, Xellyehria said:

Unfortunately while it doesn't show the missing cards in the inventory it causes error on the selection. Example if the array contains poring card and pupa card and it is on ascending order by name.

the script shouldn't be showing any card that doesn't exist in your char inventory.

1 hour ago, Xellyehria said:

however after I select pupa card it display the ID of poring card instead.

check your database entry instead?

1 hour ago, Xellyehria said:

the menu keep it's ID instead.

 set .itemid,.@iid[.@i];

change the .itemid variable ......

  • Upvote 1
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  7
  • Topics Per Day:  0.00
  • Content Count:  22
  • Reputation:   1
  • Joined:  10/19/16
  • Last Seen:  

 Thank you very much it's working well now.

 

 

test.png.5768e2405c910c0947788bee8dbe3af2.png

Edited by Xellyehria
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...