How do I change weapons

Just started using Construct 2? Post your questions here

Post » Wed Jan 28, 2015 2:28 am

I must be blind, but i cannot seem to find any tutorial that would explain how do you do a weapon change system to a game. To be more spesific, id like the player to have a maximum of two weapons and to be able to change them with the mouse scroll. I fiddled around some and managed to get the player to grab a weapon that it walks over to, but im clueless on how you would change the type of ammo it shoots. Say a pistol shoots one bullet at a time and a shotgun gives out a burst of pellets.

Cheers!
B
7
S
1
Posts: 93
Reputation: 632

Post » Wed Jan 28, 2015 2:38 am

Create a variable (Weapon) associated with the weapon type. Then create statements with dual conditions.

Button > On click > Player > Spawn Object > Bullet
System > Weapon = "Gun"

Button > On click > Player > Spawn Object > Many Bullets
System > Weapon = "Shotgun"

When the mouse scroll changes, changes the value of the variable or when he picks up a new weapon.

Hope this helps
Image
B
75
S
23
G
3
Posts: 673
Reputation: 9,273

Post » Fri Jan 30, 2015 2:26 am

Message: Juicy is not yet permitted to post plain text URLS (300 rep required). 1 URLS removed. Why?
Well i got all the way up to getting the player to fire two types of ammo (with different mousebuttons :/ ) but the sroll change just doesnt seem to open up for me. Could i see a working example somewhere perhaps?thats as far as i got :oops:
B
7
S
1
Posts: 93
Reputation: 632

Post » Fri Jan 30, 2015 9:46 pm

So a bit of an update as i've veered a little bit closer to the answer it seems. I finally got the two weapons to change with mousescroll and shoot their own bullets. A few problems reside.

For some reason, when i shoot at the enemy with the shotgun, all of the pellets dissapear as soon as one hits an enemy. I dont understand why since i've put a destroy order on each pellet separately if they hit the enemy.

The bigger issue is still with the weapon change. I got it to work kinda fine. The only thing is, now if i use the mousescroll before even taking a weapon from the ground, they switch places (scroll up, shotgun dissapears and rilfe appers and vice versa) how can i get the scroll switching to work only after i've actually piced up the weapons?
B
7
S
1
Posts: 93
Reputation: 632

Post » Sat Jan 31, 2015 6:51 pm

You're on the right track. Your problem is in your reasoning process.
Did you understand and use variables as I outlined to defines which weapon fires?
The reason all your pellets are being destroyed at once is because of the sequencing of your code.

Try

Pellet > On collision with(whatever) > Destroy pellet

Can you PM me with a link to your capx and I'll download it and take a look. I know what the mechanics of your issues is, I'm just not understanding how use the scrolling.

And is it only 2 weapons you need to switch between or do you need more than 2?
Image
B
75
S
23
G
3
Posts: 673
Reputation: 9,273

Post » Sun Feb 01, 2015 4:13 pm

Thanks for your time, ill pm you. In the long haul, id like the game to be more versatile and have more than two weapons, but im just learning the program and just trying to figure out how the thing works so for now two weapons will suffice untill i get the knack of it :) The idea i have is however so that the player can only carry a maximum of two weapons at a time and could drop them to change into another (say an enemy weapon for example)

Edit: Seems like im not allowed to PM just yet. I put the files on dropbox so you should be able to see it from the address below

Code: Select all
https://dl.dropboxusercontent.com/u/73502848/ryss%C3%A4n%20kosto%20ver2/New%20project.caproj
B
7
S
1
Posts: 93
Reputation: 632

Post » Tue Feb 03, 2015 10:44 pm

Since it's been almost three days without any answer, i'm hoping no one takes offence if i bump this thread as im still at a loss. Weapons on the ground dissapear without before picking them up and another one is that if both weapons are picked up, i dont know how to make the one currently selected to stay and the one picked up to dissapear (as to go to your inventory sort of).

Also as TheDom asked if i need only the two weapons or more, is there a crucial difference in this? just wondering if im making the whole thing somehow wrong if id like to make another game with more weapons in the future with the same principle.

Quite supprised actually that it seems a bit hard to get an answer for this. I was almost sure there have been a million games made with the same idea as far as the multiple weapons go and my question would have been aswered with a sigh of "not this question again..." :)
B
7
S
1
Posts: 93
Reputation: 632

Post » Thu Feb 05, 2015 12:16 pm

Juicy sorry for late reply here try this
You do not have the required permissions to view the files attached to this post.
B
245
S
39
G
15
Posts: 1,946
Reputation: 40,276

Post » Sat Feb 07, 2015 7:07 pm

Thanks for that, but it doesnt still quite address my problem. The original question i figured out allready, i just need to iron out a few kinks still. Perhaps the file link i posted would better explain my dilemma. I'm thinking now that i would maybe need an inventory system to the game for this and therefore maybe this question is not suited in the beginners forum?
(even though im am very very beginner still)
B
7
S
1
Posts: 93
Reputation: 632


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 1 guest