Issues with in-game shop.

Get help using Construct 2

Post » Fri Oct 13, 2017 8:49 pm

Message: Madave96 can only post plain text URLS until they have 500 rep. 2 URLS modified. Why?
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.
Screenshot: https://imgur.com/a/cBTjP
I’ve already set up the weapon swap system too.
Screenshot: https://imgur.com/a/D3Kqm

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?
B
6
S
2
G
1
Posts: 9
Reputation: 968

Post » Fri Oct 13, 2017 10:02 pm

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!
B
16
S
10
Posts: 13
Reputation: 1,590

Post » Fri Oct 13, 2017 10:18 pm

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
B
6
S
2
G
1
Posts: 9
Reputation: 968

Post » Sat Oct 14, 2017 3:05 am

@Madave96, 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:
Image

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. :)
Image

Did I help to fix a problem in your game? You can buy me a cup of coffee :) If you'd like to hire me, please see this post
B
19
S
9
G
158
Posts: 2,375
Reputation: 84,377

Post » Sat Oct 14, 2017 11:01 am

Wow! Thanks @dop2000. 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?
B
6
S
2
G
1
Posts: 9
Reputation: 968

Post » Sat Oct 14, 2017 11:54 am

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 :)
Image

Did I help to fix a problem in your game? You can buy me a cup of coffee :) If you'd like to hire me, please see this post
B
19
S
9
G
158
Posts: 2,375
Reputation: 84,377

Post » Sun Oct 15, 2017 5:02 pm

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.
B
6
S
2
G
1
Posts: 9
Reputation: 968

Post » Mon Oct 16, 2017 5:29 am

@Madave
Here you go:
https://www.dropbox.com/s/935umb5t98rbg ... .capx?dl=0

Needs just a few final touches and I can publish this game :)
Image

Did I help to fix a problem in your game? You can buy me a cup of coffee :) If you'd like to hire me, please see this post
B
19
S
9
G
158
Posts: 2,375
Reputation: 84,377

Post » Mon Oct 16, 2017 11:32 am

Thank you so, so much @dop2000! That's amazing. I owe you, my friend.
B
6
S
2
G
1
Posts: 9
Reputation: 968

Post » Mon Oct 16, 2017 12:26 pm

No worries!
Here is a new version with improved graphics and lots of new features:
https://www.dropbox.com/s/xo1u70v2zpgu6 ... .capx?dl=0
Image

Did I help to fix a problem in your game? You can buy me a cup of coffee :) If you'd like to hire me, please see this post
B
19
S
9
G
158
Posts: 2,375
Reputation: 84,377


Return to How do I....?

Who is online

Users browsing this forum: facecrime and 11 guests