Jump to content


Photo

switching weps


  • Please log in to reply
3 replies to this topic

#1 GreenhornGames

GreenhornGames

    GMC Member

  • GMC Member
  • 791 posts
  • Version:GM8

Posted 08 March 2012 - 01:57 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

ramses12

    6

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

Posted 08 March 2012 - 02:03 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

GreenhornGames

    GMC Member

  • GMC Member
  • 791 posts
  • Version:GM8

Posted 08 March 2012 - 02:18 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

Southman

    I simply am not here

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

Posted 08 March 2012 - 03:05 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{
Current_gun+=1
}else{
Current_gun=0
}

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.

Draw_sprite(global.gun[current_gun,0],image_index,x,y)

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users