How do I Make An Ammo System?

  • 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?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • well your player needs a few instance variables.

    player.currentclip

    player.clips

    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[/code:30xcwrya]
  • if you want to make a manual reload you would just do that nested IF outside

    //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[/code:1f8j2k58]
    
    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.
  • if you want to make a manual reload you would just do that nested IF outside

    //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[/code:3bng2rep]
    
    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!

  • 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/

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