How do I make the Equip/Unequip system in my game?

0 favourites
From the Asset Store
Create complex dialogues with ease with this tool/template!
  • hello, first of all english isn't my first language so i'm sorry if i write anything wrong, so...

    i'm creating a rpg game, i've created an array for storing the player itens (the game has an inventory of course) but i'm having a lot of difficulties manipulating the array, here's what i want to do:

    • if the player clicks the chest slot, and the chest slot already has a chestplate equipped, then the code would look for the first empty array space to store the chestplate in (so that would be an Unequip system) but i can't figure out how to do that, the way i tried to do actually replaces all the empty inventory slots to the chestplate instead of only the first one available, would love some help since i really don't know what to do.
  • Do your items have unique IDs?

  • Do your items have unique IDs?

    no, i just created an array to create some "Slots", "Slot" is a sprite that i've created so he has all the animations (for example if the value is 1 then the slot animation will be a potion, etc)

  • so your item Id for potion is 1... continue...

  • I want suggest you to use an invisible tilemap and check if the object is at a specific tile position, if so, improve the player with its stats.

    To know the tileposition, you can check the positiontotileX and Y of the tilemap

  • so your item Id for potion is 1... continue...

    I want suggest you to use an invisible tilemap and check if the object is at a specific tile position, if so, improve the player with its stats.

    To know the tileposition, you can check the positiontotileX and Y of the tilemap

    The only problem i'm having is to store an item only in the first empty slot instead of all the empty inventory slots, what i wanted to do is if the player clicks on an equipped item the code would remove this piece from the equipment slots and store it in only the FIRST empty slot available of the inventory, the way that i tried to do is checking the array XY but it doesn't change the value (to store the item) of only the first empty slot but ALL the slots, i don't know how to fix it i'm using the array in a wrong way.

  • try using "once while true" conditional.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • try using "once while true" conditional.

    i tried that and it didn't work too, i guess that "runs once" means that he will fill the entire array only 1 time, oh god...

  • Well, take a printscreen of you events and place here, I can't figure out what you're doing wrong.

  • Well, take a printscreen of you events and place here, I can't figure out what you're doing wrong.

    I think i've managed to explain everything right, follow the order of the screenshots:

    1) prnt.sc/dg3dmn

    2) prnt.sc/dg3e32

    3) prnt.sc/dg3e97

    4) prnt.sc/dg3ef3

  • Can't you just use the "Push" function in the Array object? That pushes a value to the 0 index of the array.

    Also, what is "Array" is that you item list, or is that your inventory?

  • Can't you just use the "Push" function in the Array object? That pushes a value to the 0 index of the array.

    Also, what is "Array" is that you item list, or is that your inventory?

    i don't know how to use the Push, how would it work?

    and the "Array" is the array of the player inventory, it's an 5x5 array so it creates 25 item slots for the player to store his itens

  • You have one Array (I'll call this ItemsArr) that contains all of your items and one Array (I'll call this Array InventoryArr for this post) for your inventory.

    When you want to add a new item to your inventory you push the item Id from the ItemsArr to the IventoryArr, like:

    IventoryArr: Push to front: ItemsArr.IndexOf("potion")[/code:293mmz1k]
    
    Then you loop through your InventoryArr again to display the new object in the inventory.
    
    So for example, let's say your ItemsArr looks like:
    
    ["potion","sword","armor","cape"]
    Idx: 0________1_______2_______3
    
    and your inventory array has a sword and armor and looks like this: 
    
    [1,2]
    
    When you use [code:293mmz1k]IventoryArr: Push to front: ItemsArr.IndexOf("potion")[/code:293mmz1k]
    
    Then your InventoryArr would look like:
    
    [0,1,2]
    
    If you then use [code:293mmz1k]IventoryArr: Push to front: ItemsArr.IndexOf("cape")[/code:293mmz1k]
    
    Your InventoryArr would look like:
    
    [3,0,1,2]
    
    Then to display items, you loop through your InventoryArr and pull items from your ItemsArr using the item IDs stored in your inventory array.
    
    The 5x5 is only a display change, not a fundamental data structure property.  So you would address the 5x5 property in your display loop using a row variable and incrementing it every 5.
    
    Like this: [url=https://drive.google.com/open?id=0B-xiqKTWbBrfZktIajB6ZmtoaVk]https://drive.google.com/open?id=0B-xiq ... jB6ZmtoaVk[/url]
  • You have one Array (I'll call this ItemsArr) that contains all of your items and one Array (I'll call this Array InventoryArr for this post) for your inventory.

    When you want to add a new item to your inventory you push the item Id from the ItemsArr to the IventoryArr, like:

    IventoryArr: Push to front: ItemsArr.IndexOf("potion")[/code:4b9qp1hs]
    
    Then you loop through your InventoryArr again to display the new object in the inventory.
    
    So for example, let's say your ItemsArr looks like:
    
    ["potion","sword","armor","cape"]
    Idx: 0________1_______2_______3
    
    and your inventory array has a sword and armor and looks like this: 
    
    [1,2]
    
    When you use [code:4b9qp1hs]IventoryArr: Push to front: ItemsArr.IndexOf("potion")[/code:4b9qp1hs]
    
    Then your InventoryArr would look like:
    
    [0,1,2]
    
    If you then use [code:4b9qp1hs]IventoryArr: Push to front: ItemsArr.IndexOf("cape")[/code:4b9qp1hs]
    
    Your InventoryArr would look like:
    
    [3,0,1,2]
    
    Then to display items, you loop through your InventoryArr and pull items from your ItemsArr using the item IDs stored in your inventory array.
    
    The 5x5 is only a display change, not a fundamental data structure property.  So you would address the 5x5 property in your display loop using a row variable and incrementing it every 5.
    
    Like this: https://drive.google.com/open?id=0B-xiq ... jB6ZmtoaVk
    

    wow! you're really helping me out! i did the same thing as your events:

    prnt.sc/dh2ig5

    it's almost working as i wanted, however, i have no idea why when i open the inventory (the player has to press "I" for it to appear) there's already an item in the first slot!

    prnt.sc/dh2ils

    and it's even more bizarre that when i debug the game, i can see that not only this already created item but also all the other itens that i create are being created and deleted so fast that you can't even see it being destroyed and created again, how would i possibly fix those issues?

  • Make sure you InventoryArr is cleared and set to 0 X-size (Set Size 0,1,1) otherwise, the array value defaults to 0. Also, make sure you destroy all of the items sprites upon entering the inventory so that you display loop can work with a clear inventory.

    I actually had the same problem when I was testing this capx too.

    Another option is to exclude the 0 index from your items array and put a condition in your loop that bypasses any 0 values.

    all the other items that i create are being created and deleted so fast that you can't even see it being destroyed and created again

    I am not sure what this means?

    Keep in mind though, that every global event will run every tick (or as fast as possible); so if you have an unconditioned destroy event, it will continually destroy your items.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)