Jump to content

Question

Posted

Hi.

Guys, how can i make an npc count mutiple items before "goto" next part?

For example:

check if player has 10 jellopy and 10 feather, then "goto" GvI

GvI:

delitem 909,10;

delitem 949,10;

close;

3 answers to this question

Recommended Posts

  • 1
Posted
6 minutes ago, HeyC said:

Hi.

Guys, how can i make an npc count mutiple items before "goto" next part?

For example:

check if player has 10 jellopy and 10 feather, then "goto" GvI

GvI:

delitem 909,10;

delitem 949,10;

close;

You'll use an AND statement designated by &&, you need it double like this, in your IF statement.

if(countitem(1111) >= 10 && countitem(1111) >= 10 )

 

  • 1
Posted

Or, if you have a list os many items, you can store their IDs in an array:

setarray .@items[0], 1234, 1235, 1236, 1237, 1238, 1239, 1240, 1241, 1242, 1243, 1244, 1245;

Then, if you want to make sure that the player has at least X of each item, you iterate over the array:

set .@requiredAmount, X;
set .@hasAllItems, 1;
for (.@i = 0; .@i < getarraysize(.@items); .@i++) {
	if (countitem(.@item[.@i]) < .@requiredAmount) {
      set .@hasAllItems, 0;
      break;
    }
}
if (.@hasAllItems) {
  // Player has at least X items of every ID
} else {
  // Player does not have X items of every ID
}

Or, if you'd like to specify different quantities for each item, you can also do:

setarray .@items[0], 1234, 1235, 1236, 1237, 1238, 1239, 1240, 1241, 1242, 1243, 1244, 1245;
setarray .@requiredAmount[0], 10, 10, 5, 5, 10, 10, 5, 6, 7, 10, 50, 100;

set .@hasAllItems, 1;
for (.@i = 0; .@i < getarraysize(.@items); .@i++) {
	if (countitem(.@item[.@i]) < .@requiredAmount[.@i]) {
      set .@hasAllItems, 0;
      break;
    }
}
if (.@hasAllItems) {
  // Player has the required amount of items of every ID
} else {
  // Player does not have the required amount of items of every ID
}

You can also unite the two arrays together:

setarray .@item_and_amount[0], 1234, 10, 1235, 10, 1236, 5, 1237, 5, 1238, 10, 1239, 10, 1240, 5, 1241, 6, 1242, 7, 1243, 10, 1244, 50, 1245, 100;
/* The above array holds pairs of values, where the first value is the item ID and the second value is the required amount */

set .@hasAllItems, 1;
for (.@i = 0; .@i < getarraysize(.@item_and_amount) - 1; .@i = .@i + 2) {
	if (countitem(.@item_and_amount[.@i]) < .@item_and_amount[.@i+1]) {
      set .@hasAllItems, 0;
      break;
    }
}
if (.@hasAllItems) {
  // Player has the required amount of items of every ID
} else {
  // Player does not have the required amount of items of every ID
}

 

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.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...