How do I switch between weapons with ammo?

0 favourites
  • 3 posts
From the Asset Store
75 sci-fi and futuristic weapon sound effects, from lasers and beam weapons, to space cannons and rifles etc.
  • how can i make it, i tried with arrays but i am stupid and i cant

  • I use dictionaries, but you can use an array too.

    You can create a system that will need a couple of global variables and at least one dictionary.

    Lets say you have two weapons. Create a global variable called weaponState with default value 1 and another global variable called ammoEquipped. weaponState will only ever be 1 or 2, and ammoEquipped contains the ammo for the currently equipped weapon.

    In the dictionary set two keys called ammo1 and ammo2 each with value 100.

    By default player has weapon 1 selected, so weaponState = 1.

    When player fires a bullet subtract 1 from ammoEquipped.

    When player presses keyboard key 2, the value from ammoEquipped is set to dictionary key ammo1, weaponState is set to 2, the value from dictionary key 'ammo2' is loaded into ammoEquipped.

    When weapon is changed by pressing key 1 or 2 on keyboard, you can also switch animations in player sprite to visually show which weapon is equipped.

    EDIT

    Heres a simple example to point you in the right direction weaponSystemBasic_artpunk.c3p

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks for all but i forgot to say - There are weapons you can pick, and you have 2 slots of weapons,

    ex1: Ak47 30/90, RPG 1/2

    ex2: M14 10/20

    and swip between weapons you picked

    I tried with arrays but idk why it didnt work

    imgur.com/a/67nJCAw

    imgur.com/a/kmpOsza

    I was going to do it with arrays but if it's better with dictionaries I have it with dictionaries

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