Jump to content
Khaikaa

Beating Intersect Engine Limitations: Counting empty inventory slots

Recommended Posts

Hi everybody,

 

Today I'm teaching you how to break another limitation of intersect engine: how to know the empty inventory slots of a player's inventory. Let's start with an example of usage:

 

Imagine that you created a very nice minigame that gives a nice reward to your players. But... what happens if a player starts the minigame with a full inventory by mistake? This player will lose this nice reward and there is nothing you can do to solve that... right?

 

WRONG!

 

You can check that player's inventory and send a warning message to him/her, so the player will notice he has not enough empty space on his/her inventory and go to the bank/shop to make more space. But how?

 

We will make this with an event that fills the player's inventory with a special item. For each item we add to his/her inventory we will add +1 to a player variable and repeat. After his/her inventory gets full, we will take all these special items so the player gets back his/her inventory empty spaces. That simple!

 

This is as so easy to do:

 

87aa33e9a7a3e85479a463bd90a4dfd2.png

 

Before getting started, make sure you have an available player variable and a useless item. If not, create them.

 

First of all, we set the player variable to 0 and add a label(I called this first label "contar"). After that, add a "change player items" command which will be adding the useless item. If it successfully adds the item, we add +1 to the player variable and go back to the "contar" label.

 

At some point there won't be any empty spaces in the player's inventory, so this loop will break. After that happens, add a new label(I called it "vaciar") and add another "change player items" command. This time, it will be taking the useless item. If we successfully take 1 of the useless items, we go back to the "vaciar" label. At some point we won't be able to take more useless items from that player's inventory and the loop will break. After that happens, add some show text command(i did this with a show chatbox text command) and tell the player that he has "(value of that player variable here)" empty spaces. You can optionally tell the player that he needs at least "x" empty spaces so he/she can earn these great rewards. or you can even forbid his/her entrance until he/she has enough empty space.

 

I hope this helps someone!

Share this post


Link to post
Share on other sites

This is a pretty clever way of checking inventory space. Can’t say I would’ve thought about doing this myself. 

 

One question though, shouldn’t there be an event that sets the temporary variable back to 0 after calculating how much inventory space is available?

Share this post


Link to post
Share on other sites

Yes, you can notice for its name that I use some multipurpose switches and variables (variableMultiproposito_1 would be multipurposeVariable_1 in english), so every time I need any of them I set them to 0/false as a good programming practice. I don't know which value may have that variable at the momment of running that event(which in this tutorial is triggered by commands just because it's comfortable to test with but I NEVER let the players manipulate these variables through commands for obvious reasons), so I reset them. Working this way saves a lot of switches/variables space and lets you have a clear workspace.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×