Issues with in-game shop.

0 favourites
  • 10 posts
From the Asset Store
Quickly and easily add a Quake-like console to your games
  • Hey guys,

    I’m trying to set up in-game shops for weapons, items and armour. The item shop should be simple because it’ll probably be preset items, it’s the weapon and armour shops I’m struggling with.

    I’m working on the weapon shop first. I’ve set it up so it displays random weapons based on the player’s progression (still amazed I managed to do this without help...). I have a sprite with animations for each weapon, arrays that hold strings (part of the animation name) and the BHT Smart Random plugin to generate the non-repeating random numbers to select a value from the array. The progression system is a simple global variable that ticks up one every time the player hits the end of a level. I’ve just put a “1_” or “2_” on each animation for the weapon levels.


    I’ve already set up the weapon swap system too.


    The problem I’m faced with now is; How to buy and equip the weapons?

    The only way I can see is to have events checking which animation’s playing (“player” is overlapping “Wep_Shop” + “Wep_Shop” is animation “1_Axe” playing== Subtract 30 from Coins + set “Wep_Num_Melee” to 2) but I’m going to have hundreds and hundreds of weapons by the time this game’s finished. I don’t want hundreds of events just for this system. Is there another way this could be done? Do I have to make it from scratch to do it right? Or is the only way to have hundreds of events?

  • When I made an in-game shop, I used global Variables to check if the item was purchased and if it was equipped. So, if (global variable) is = to 1 (1 meaning is purchased), then set (item equip button) visible (or available). Now, if player clicks (or touches) equip button and item equip button is visible (because the button will always be there, just not visible) then (equip item/armor/weapon).

    Hope this helped, Good Luck!

  • Equipping isn't really the problem, I just need to change the variable number and it will select that weapon from the array. The problem is more to do with which animation is playing. That's why I say it could be done with events checking which animation is playing but that seems long and resource intensive.

    I think if I could somehow get the numbers from the BHT Smart Random plugin, save them to an array or something, I could use those numbers to set the variable. I'm really not sure though. That's why I asked haha

  • , If you are planning to have hundreds of weapons you should definitely re-think your approach..

    I would make a "database" of all available weapons:

    You can create this table in Excel, save as text file (.CSV) and import to Construct 2.

    Use CSV plugin to read data from this file, it's pretty simple.

    Another option - XML. But personally I prefer CSV.

    When you have your weapons database, you can select several weapons from it (by current level, shop type) and put them into the shop. Create sprites, set animation, arrange them on the shelves, etc. Set instance variable on each sprite to weapon code.

    So for example you'll have instances with codes "ShortSword_2", "LongSword_2", "LongBow_2".

    When player clicks the long sword sprite, you can retrieve all other information from the CSV by code "LongSword_2". Deduct its price from player's money, update weapon in player's hand, update damage values etc.

    Edit: I just noticed that you are planning to sell armor and other items. You can make similar databases for them.

    Or maybe combine everything in one, but it may become too complex.

    Also, I suggest you learn how to use loops and functions, it will make your life much easier.

  • Wow! Thanks Yeah I've got a lot to learn haha. I'm still fairly new to C2 and I'm not a programmer, I'm an artist.

    The database would definitely work a lot better but wouldn't it still require hundreds of events? Because I would need a sprite for each weapon, correct? So I would still need to check which sprite the player's overlapping. Or am I being an idiot again?

  • No, you would not need a separate sprite for each weapon. You can only have 2 sprites - WeaponShop and WeaponEquipped. Each sprite will have many animations - for example WeaponShop will have "SS1", "SS2", "LS1" etc (see my screenshot above).

    Also, create an instance variable "weapon_code" on these sprites. You can create other instance variables, for example "weapon_price".

    So when you add weapons to your shop, you can pick several weapon codes from the CSV. (on random, or all available for this level or using some other criteria).

    For each weapon code you create an instance of your sprite and assign WeaponShop.weapon_code=(code from CSV), WeaponShop.weapon_price=(price from CSV). And set animation, also retrieved from CSV.

    Now you have a bunch of WeaponShop sprite instances which you can display in the shop.

    When player clicks (or overlaps) any of them, you can easily get weapon code and price from sprite instance variables. And if needed, you can retrieve other data from the CSV.

    You can do all this with only a dozen or so events and sell hundreds of weapons in your shops

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hey dop2000, sorry to be a pain in the ass but I'm still really struggling with this. My mind's glazing over every time I try to figure it out. If it's not too much bother could you make a demo.capx please.

  • Here you go: ... .capx?dl=0

    Needs just a few final touches and I can publish this game <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

  • Thank you so, so much dop2000! That's amazing. I owe you, my friend.

  • No worries!

    Here is a new version with improved graphics and lots of new features: ... .capx?dl=0

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