How do I Make An Ammo System?

Get help using Construct 2

Post » Thu Aug 03, 2017 5:51 pm

So, what I want is an Ammo system where once you run out of ammo you can reload. If you have the amount of clips. Once you run out of clips then you can shoot the last bit of bullets you have. But you cant reload.

How would I do something like that? :?: :?: :D ;) 8-) :lol:
B
22
S
6
Posts: 26
Reputation: 1,354

Post » Fri Aug 04, 2017 3:12 pm

well your player needs a few instance variables.

player.currentclip
player.clips

Code: Select all
IF press fire button AND player.currentclip > 0 THEN

          //shoot
          spawn bullet
          play.audio("gunshot.ogg")
          subtract 1 from player.currentclip

          //check clip is empty
          IF player.currentclip <= 0 AND player.clips > 0 THEN
               
               //reload
               set player.currentclip to MaxClipSize  //whatever the size your clip is
               subtract 1 from player.clips

           END

ELSE
               
               //gun is empty
               play.audio("click.ogg")

END
B
88
S
29
G
14
Posts: 1,154
Reputation: 15,003

Post » Fri Aug 04, 2017 3:25 pm

if you want to make a manual reload you would just do that nested IF outside


Code: Select all
//make sure the gun isn't already full
IF reload button pressed AND player.currentclip < MaxClipSize
           IF player.clips > 0 THEN
               
               //reload
               set player.currentclip to MaxClipSize  //whatever the size your clip is
               subtract 1 from player.clips

           END
END


the only thing you have to think about is if the player hits reload and their gun is not empty, what do you do with those extra bullets? that's when it get's a little more complicated.
B
88
S
29
G
14
Posts: 1,154
Reputation: 15,003

Post » Fri Aug 04, 2017 5:46 pm

jobel wrote:if you want to make a manual reload you would just do that nested IF outside


Code: Select all
//make sure the gun isn't already full
IF reload button pressed AND player.currentclip < MaxClipSize
           IF player.clips > 0 THEN
               
               //reload
               set player.currentclip to MaxClipSize  //whatever the size your clip is
               subtract 1 from player.clips

           END
END


the only thing you have to think about is if the player hits reload and their gun is not empty, what do you do with those extra bullets? that's when it get's a little more complicated.


Thanks! I'll try when I can!
B
22
S
6
Posts: 26
Reputation: 1,354

Post » Fri Aug 04, 2017 7:07 pm

I wrote a tutorial a while ago for reloading weapons.

Here is the link

https://www.scirra.com/tutorials/9541/h ... -and-sound

Here is the cap sample

http://mythicalnew.byethost7.com/
Like my work? Fallow me on social media, and see my games on the arcade.
B
7
S
5
G
9
Posts: 298
Reputation: 5,357


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 5 guests