Jump to content


switching weps

  • Please log in to reply
3 replies to this topic

#1 GreenhornGames


    GMC Member

  • GMC Member
  • 901 posts
  • Version:GM:Studio

Posted 08 March 2012 - 02:11 PM

i have one obj_player which uses space to shoot. how do i add a weapon switch function which makes him use different weapons? (he has default weapon but when he picks up a new one, he can then has 2 weapons and can freely choose which one to use).
  • 0

#2 ramses12



  • GMC Member
  • 5769 posts
  • Version:GM8.1

Posted 08 March 2012 - 02:17 PM

Make a variable to store the player's current/active weapon, and a button to change that; if you want to have the ability to choose from only two weapons, the variable will probably hold only 0 or 1. When shooting, create a different projectile if the active weapon is 1 than the projectile created if the active weapon was 0.
  • 0

#3 GreenhornGames


    GMC Member

  • GMC Member
  • 901 posts
  • Version:GM:Studio

Posted 08 March 2012 - 02:32 PM

do i also need a variable which determines if player is allowed to use the weapon? when he picks up the weapon then a variable, for ex. "blazerunlocked" is 1, then the code checks if "blazerunlocked" is 1, and then thats the active weapon, then it checks if which weapon is active and it creates the right missile.
  • 0

#4 Southman


    I simply am not here

  • GMC Member
  • 1662 posts
  • Version:GM:Studio

Posted 08 March 2012 - 03:19 PM

In some object, initialize an array to store the gun variables, such as firing rate, sprite, power, etc.

Global.numberofguns=number of guns you plan to add

Global.gun[0,0]=sprite to use 
Global.gun[0,1]=some other variable 

Global.gun[1,0]=sprite to use
Etc, etc
First part of the array is the id for the individual gun, the second part is for the variables you plan to assign to that gun.

Now, in the player character, make a variable called current_gun, or whatever, and make it equal to a gun id that you made before.

Let's say you're using the mouse wheel to cycle through the guns.

In the mouse scroll up event, add this
If current_gun+1<=global.numberofguns{

And for the mouse wheel down, just switch it for -1. So if current_gun-1>=0 subtract 1 else the current gun equals the global.numberofguns.

Then when you're doing things like drawing the gun, do something like this.


Or whatever.
Sorry, this is all off the top of my head, and I can't test it because im at school. And my iPod changed some things to uppercase, so just fix that.

Hope I helped
  • 0