How do I create a spawn limit for a certain amount of time?

  • I recently made the beginner game Pokémon themed with many more events. Whenever the right mouse button is held down, the player character shoots ultraballs INFINITELY. But I don't want it to be too over-powered, so I want to know how to make the character shoot 100 ultraballs, then have a timeout for 10 seconds so that the player can't shoot ultraballs, then after those 10 seconds, the player can shoot another 100 ultraballs and so on.

    Also my audio won't work. I want to put music over it, so I put the .ogg file in the music folder, and then do the audio stuff in the event sheet. I preview it, but I cant hear anything. And no I do not have my speakers muted.

    If anyone could help me out with these two things, that will be great!

  • I assume you have something like this:

    Mouse Right button is down : Player -> Spawn ultraball

    You need to add instance variable to your player (say BallCounter) and Timer behavior.

    Then do this:

    Mouse Right button is down 
    player.BallCounter<100 
        Player -> Spawn ultraball
        Add 1 to player.BallCounter
        If player.BallCounter=100 
              player start Timer "Cooldown" for 10 seconds (Once)
    
    Player-> On Timer "Cooldown"
      player.BallCounter=0  
    [/code:1dvpubkb]
    
    However you need to decide what happens if player shoots 80 ultraballs and then releases the button.
    You may want to reset the counter immediately, or after a delay, or maybe decrease it by 10 every second or so.
  • I don't really understand:

    "player.BallCounter<100"

    What do I do there?

  • Wait hold on...

    Do you mean I have to create another condition UNDER the Right mouse button down?

  • No, sorry I don't really understand, I'm still quite new to Construct 2.

  • Yes, exactly, another condition: player->Compare instance variable

  • Ah, so now I get it.

    'player.BallCounter' is the same as 'Player ---> BallCounter < 100'

    Am I correct?

    But thanks anyway, I'll give it a try!

  • I can't get it to work. I got the events set up, but I don't know how to stop the player from spawning more ultraballs when the limit has been reached.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • When the limit is reached, I want the game to ignore the right mouse button being clicked, but only for 10 seconds. How do I do that?

  • Have you tried what I suggested in my first comment?

    Could you post a screenshot of your code?

    Or better yet, share the CAPX file.

  • I don't know how to upload a file, sorry...

    Don't be surprised, I can be dumb lol.

  • Sorry, I cant seem to get the link from google drive, I do have a screenshot of it but I don't really know how to post it.

    How ever i can put the code here in text, if that could help:

    Mouse: Right button is down ---> Player: Spawn Ultraball on layer 1 (image point 1)
    Player: UltraballCounter <100 ---> Player: Add 1 to UltraballCounter[/code:10x7a7x6]
    
    That's what i have so far... hope that helped you?
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)