Jump to content
Deadeye_Rob

Check, add, remove objects from player inventory.

Recommended Posts

Hi guys!

I've been racking my brains to figure this out but with no success.

 

How do I create a script that will check a player's inventory for a predetermined quantity of objects say; 10 Iron Ore.

 

If they possess the required item/quantity it will remove/despawn it from their inventory and in exchange will spawn another object.

 

See where I'm going? ?

Many help would be fantastic. Thanks guys!

Rob

Share this post


Link to post
Share on other sites

Ping me on discord, i got some great scripts just like that. Not sure how they work, we have them in the P1 library. 

  • Thanks 1

Share this post


Link to post
Share on other sites

If you want to try work it out by yourself here is the basic idea, you need to do a for each loop with the array of items in the player's inventory, inside the for each loop you need to use an if statement to see if the item is equal to the type you are looking for, then you can check if there is enough of that item and from there you spawn the new item in the players inventory. does this make any sense whats so ever?

Share this post


Link to post
Share on other sites

You all should be ashamed of yourselves for being so lazy as not to provide a half decent answer with a real explanation. @RedEagle_P1. @Oliver Hope@Deadeye_Rob

Click on the image to make it bigger to see it!

image.thumb.png.f14b19d3af2c342a82634291b4a2714b.png

Here, we made an instruction using a global storage. (Global Storage is useful because it can be used anywhere, anytime)

The instruction "Player Has Item?" has 3 variables, the player, the item type, and the quantity.

First it checks for each slot in the players inventory.

It then checks if we have the correct item type  AND If the amount is correct.

If TRUE  ->  pay the amount we need to get the thing.

 

Ex: Player Buys Spear

If  (Player)  has 3 Old Coins  

If its true, the player will then pay 3 Old Coins and after a Spear will spawn in the players inventory.

Edited by Igor Q.
  • Thanks 2

Share this post


Link to post
Share on other sites

You sir, are an absolute genius!

Thanks very much Igor! I had to make a minor adjustment for it to work properly however. On the "Player Has Item?" chain; the 'Set Stack Count Entity' should just have the 'Item' box within its parameters. Not the 'Get Stack Count Entity -Item'. Otherwise this will generate an error.

I'm going to toy around with this script to include templated items to see what I can create. You've repeaked my interest on this matter again! My Vault project will have to wait! :P

 

20191014222942_1.thumb.jpg.449450978b3176a5aa504a2d6a41af0d.jpg

*Here is a quick visual breakdown of what I corrected to adapt the script for my purposes so far!

 

Thanks again Igor!

  • Like 1

Share this post


Link to post
Share on other sites

Hey no worries at all! I've never attempted to use Arrays, instructions or variables!

But you've definitely got my old cogs turning! ?

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×