Jump to content
  • 0
almarket23

getinventorylist help

Question

Hi everyone. Does anyone know how to do this? Basically what I need is a script that can check the item equipment of a player which is not equip and remove it all from the players inventory.

 

example:

A player has a 3 Silk Robe (ID:2321) and 5 Shoes (ID:2403) in his inventory. When the player clicks this NPC, all of his 3 Silk Robe and 5 Shoes in his inventory will be removed and he will get an item in exchange like Red Potion.

 

I am tying to use this one but I cant seem to make it work. It can only remove an item one at a time which is not what I want.

 

if( countitem(2321) == 1 ){
getinventorylist;
for (set .@i, 0; .@i < @inventorylist_count; set .@i, .@i + 1 )
if ( @inventorylist_id[.@i] == 2321 )
set .count01, @inventorylist_amount[.@i];
delitem 2321, .count01;
getitem 501,.count01;
}
if( countitem(2403) == 1 ){
getinventorylist;
for (set .@i, 0; .@i < @inventorylist_count; set .@i, .@i + 1 )
if ( @inventorylist_id[.@i] == 2403 )
set .count01, @inventorylist_amount[.@i];
delitem 2403, .count01;
getitem 501,.count01;
}

I hope someone can help me with this one...

Share this post


Link to post
Share on other sites

7 answers to this question

Recommended Posts

  • 0

You can make everything inside 1 for loop, going through the entire inventory and checking the item type example:

(I didn't test this code)

 

getinventorylist;
for (.@i = 0; .@i < @inventorylist_count; .@i++ ) { // Loop through the entire inventory
	if ( @inventorylist_equip[.@i] == 0 ) { // Item should not be equipped
		if ( getiteminfo(@inventorylist_id[.@i], 2) == 5 ) { 
			// Item is an armor type
			.@count01 += @inventorylist_amount[.@i]; // add to .@count01
			delitem @inventorylist_id[.@i], @inventorylist_amount[.@i]; // delete item
		}
	}
}
// Now we went through all items, get .@count01 red potions
getitem 501, .@count01;

Share this post


Link to post
Share on other sites
  • 0

thanks KirieZ. Its working that way I like it however this script is getting all the equipment in players inventory. How can I make this script get a certain type of equipement in players inventory?

 

Like when a player has a 3 Silk Robe (ID:2321) and 5 Shoes (ID:2403) in his inventory. When the player clicks this NPC, all of his 3 Silk Robe and 5 Shoes in his inventory will be removed and he will get an item in exchange.

 

Silk Robe (ID:2321) = 1 Red Potion

Shoes (ID:2403) = White Potion

 

Only Silk Robe (ID:2321) and Shoes (ID:2403) is the one that will be removed. not included the other equipments in players inventory.

Edited by almarket23

Share this post


Link to post
Share on other sites
  • 0

Ah, right, I thought you wanted to exchange everything.

You can make 2 arrays, one with Item Ids (e.g.: setarray .itemIds[0], 2321, 2403;) and one with "rewards" (e.g.: setarray .rewards[0], Red_Potion, White_Potion;) then instead of checking the type ( getiteminfo(<ID>, 2) ) you check if this item is in .ItemIds, if it's, get its index, then you can exchange it for the reward.

 

something like:

for (.@j = 0; .@j < getarraysize(.ItemIds); .@j++) {
   if (@inventorylist_id[.@i] ==  .ItemIds[.@j]) break;
}

if (.@j < getarraysize(.ItemIds)) {
  // This item reward is .rewards[.@j]
  // delitem/getitem
} else {
  // This item is not rewardable
}

Share this post


Link to post
Share on other sites
  • 0


setarray .ItemIds[0], 2321, 2403;

setarray .rewards[0], Red_Potion, White_Potion;

 

getinventorylist;

for (.@i = 0; .@i < @inventorylist_count; .@i++ ) { // Loop through the entire inventory

 

if ( @inventorylist_equip[.@i] == 0 ) { // Item should not be equipped

for (.@j = 0; .@j < getarraysize(.ItemIds); .@j++) { // Check if it's a rewardable item

if (@inventorylist_id[.@i] == .ItemIds[.@j]) break;

}

 

if (.@j < getarraysize(.ItemIds)) { // If it's

delitem @inventorylist_id[.@i], @inventorylist_amount[.@i]; // delete item

getitem .rewards[.@j], @inventorylist_amount[.@i];

}

}

}

Share this post


Link to post
Share on other sites
  • 0

Sir KirieZ thank you so much. This is what I am looking for. One more thing sir I just forgot, is it possible for the player to get random item exchange?

 

Example 

if the player has ID:2321 he will get Red Potion random of 1 or 2 Red potion

if the player has ID:2403 he will get White Potion random of 5 or 7 White potion

Share this post


Link to post
Share on other sites
  • 0

yeah, it's, I can't code it at moment, but you can do it by making two extra arrays, one with the minimun and another with the maximum reward, then just use rand(min[.@j], max[.@j]).

 

example:

setarray .min[0],  1, 5;
setarray .max[0], 2, 7;

Share this post


Link to post
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.   Restore formatting

  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.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.