Easy Inventory Using An Array

1

Index

Fichiers attachés

Les fichiers suivants ont été attachés à ce tutoriel:

Contributeurs

Statistiques

4,201 visites, 5,837 vues

Outils

Partager

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 25 Mar, 2016. Last updated 25 Feb, 2019

Programmation de l'inventaire

Préparer les slots et le texte

La première chose que l'on va faire est de créer quelque chose pour metre à jour les objets invSlot et les objets slotAmt . C'est une simple boucle qui met invSlot à l'item Id de son slot respectif, et met le slotAmt au nombre d'item qu'il y a dans ce slot.

Prendre des items

Paramètre

Param0 L'id de l'objet à rajouter à l'inventaire.

Param1 (optional) combien d'exemplaire de cet item vont être rajouté.

Variables

foundSlot - Used to keep track of whether or not another slot containing the same item was found.

emptySlot - Stock le SlotID du premier slot vide qu'il a trouvé.

amountToAdd - Combien d'item vont être rajouté.

Fin Traduction Sirvoid

Events

Event 8 - Reset the variables.

Events 9-10 - Check if only 1 parameter was passed. If so, default amountToAdd to 1. Else, Set it to Param1.

Event 11 - Loop through each X element in the Inventory array. Don't bother proceeding if a slot was found already.

(Things to note: Inside of this loop, current slot will equal arr_inventory.CurX and current item ID will be arr_inventory.CurValue)

Event 12 - If the ID of item in the current slot is 0, this means it is empty. If an emptySlot has not been found yet (we want the first empty slot, not the last one) store the current slot in emptySlot.

Event 13 - If the ID of the item in the current slot matches the item ID we are adding (Param0) we set foundSlot to the current slot, add amountToAdd to the current amount of items in the slot, and finally call the UpdateInventory function.

Event 14 - First identify if the current slot is the last slot in the inventory array. If so, make sure a matching slot was not found and an empty slot does exist. Then the first empty slot (emptySlot) can be set to the ID of the item to add, and the amount in that slot can be set to amountToAdd. Then call the UpdateInventory function.

Dropping Items

Parameters

Param0 is the slotID we will be removing the item from.

Param1 is how many items should be removed.

Variables

itemsRemoved - How many items were removed from the slot (in case *Param1" was larger than how many items are actually in there)

Events

Event 18 - First set itemsRemoved to min(Current Slot Amount, Param1) This will get the lower of the two numbers to prevent removing more items than that slot actually has. Then remove that amount from the slot passed in Param0.

Event 19 - If that slot is now empty, set the slots ID to 0 to represent an empty slot. Setting the amount in that slot is not entirely necessary, I just have it there as a fail-safe.

Event 20 - Finally, call the UpdateInventory function and return itemsRemoved. Returning the variable is not necessary unless you need it somewhere else (eg. dropping those items on the ground)

Other Stuff

To add/remove items from the inventory we are simply calling these two functions when the groundItem or invSlot are clicked.

And that's all there is to it! I will be working on this tutorial in the future and adding/improving stuff.

.CAPX
  • 0 Comments

Want to leave a comment? Login or Register an account!