How do I reload like a shotgun?

0 favourites
  • 5 posts
From the Asset Store
A sound pack containing 132 laser gun sound effects, including mono and stereo versions of audio files.
  • Hello! In my game, when the player reloads a shotgun I want the shells to be individually loaded. Kinda like in real life.

    This is my code, my problem is that it only loads once, ignoring the repeat loop

    For more context "GunSpecs.At(Player.Gun,6)" is the amount a full magazine can hold.

    "GunSpecs.At(Player.Gun,7)" basically means 1.

    The Reloading variable acts as a boolien, so when Reloading=1 then the player cant reload, that way a player cant reload WHILE relaoding.

    So if Reloading doesnt equal 0, then a player cant reload.

    Any help is greatly appreciated.

  • Hello,

    I don't have a solution, I would add a browser addon and do a log in all actions and make sure the conditions are evaluated as expected.

    Another thing, I got confused by the second condition in the first event, Can player.ammo be greater than the guns full magazine? You know best, but to me it looks unnecessary. Looks like that always evaluate as true.

  • Refactor the events so that you set reloading to 1 as you already have, then do a separate event something like:

    Reloading = 1, every x seconds : play sfx etc, add 1 to ammo.

    - If ammo = max, set reloading to 0.

    For tighter control, use the timer behavior and add 1 to ammo on timer. If ammo < max, restart the timer. This way you can stop the timer instantly if needed (like a powerup or on picking up a new weapon).

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • On Key Pressed: is a trigger which runs only once.

    So your "Every X seconds" will not work as intended under a trigger.

    You need to use "Key Is Down" if you want to use the "Every X seconds" in a subEvent.

    I like to use Timers swell as GeoffB recommends.

    Also, (Repeat X Times & Every X seconds) doesn't make much sense, perhaps you should use:

    Key Is down:
    --Your Top Conditions
    ---------Every X seconds: Your Actions
    

    The "Every X seconds" will only run if the top conditions are met.

  • Refactor the events so that you set reloading to 1 as you already have, then do a separate event something like:

    Reloading = 1, every x seconds : play sfx etc, add 1 to ammo.

    - If ammo = max, set reloading to 0.

    For tighter control, use the timer behavior and add 1 to ammo on timer. If ammo < max, restart the timer. This way you can stop the timer instantly if needed (like a powerup or on picking up a new weapon).

    Thank you! This worked perfectly!

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