skofrant
Member
But look i already swapped that before ... and still can't pick a non-primary weapon
ok below all the code for the weapon exchange system
with the corrections applied ... despite this, I still can't change my weapon ... to magma, even though I take it from the board ... she adds, because the sprte in gui is changing ...
obj_game_controller (perssistent)
create
obj_game_controller (perssistent)
step
obj_game_controller (perssistent)
DRAW GUI
obj_player
create
obj_player
step
Hero event collision (obj_player with an object chest with weapons and ammunition obj_chest)
This object is immediately in the first stage(room)
the hero takes it adds and weapon and the sprite ammo in the gui is displayed, but still cannot shoot magma .. all the time the player has a primary weapon ..
buttons from 1 to 5 do not respond to switching weapons.
obj_magma
create
ok below all the code for the weapon exchange system
with the corrections applied ... despite this, I still can't change my weapon ... to magma, even though I take it from the board ... she adds, because the sprte in gui is changing ...
obj_game_controller (perssistent)
create
GML:
enum e_wep { have,ammo,firerate,dmg_min,dmg_max,ammo_type }
enum e_gun { basic,magma,shotgun,laser,crossbow }
current_weapon = 0;
weapons_total = 5;
var i = 0;
//primary weapon(bullet)
global.wep[0 ,e_wep.ammo_type] = obj_bullet;
global.wep[0, e_wep.have] = false;
global.wep[0 ,e_wep.ammo] = 100; //unlimited
global.wep[0 ,e_wep.firerate] = 5;
global.wep[0 ,e_wep.dmg_min] = 3;
global.wep[0 ,e_wep.dmg_max] = 5;
//magma weapon
global.wep[1 ,e_wep.ammo_type] = obj_magma;
global.wep[1, e_wep.have] = false;
global.wep[1 ,e_wep.ammo] = 30;
global.wep[1 ,e_wep.firerate] = 10;
global.wep[1 ,e_wep.dmg_min] = 3;
global.wep[1 ,e_wep.dmg_max] = 5;
//shotgun weapon
global.wep[2 ,e_wep.ammo_type] = obj_shotgun;
global.wep[2, e_wep.have] = false;
global.wep[2 ,e_wep.ammo] = 20;
global.wep[2 ,e_wep.firerate] = 15;
global.wep[2 ,e_wep.dmg_min] = 3;
global.wep[2 ,e_wep.dmg_max] = 5;
//laser weapon
global.wep[3 ,e_wep.ammo_type] = obj_laser;
global.wep[3, e_wep.have] = false;
global.wep[3 ,e_wep.ammo] = 10;
global.wep[3 ,e_wep.firerate] = 20;
global.wep[3 ,e_wep.dmg_min] = 3;
global.wep[3 ,e_wep.dmg_max] = 5;
//crossbow weapon
global.wep[4 ,e_wep.ammo_type] = obj_crossbow;
global.wep[4, e_wep.have] = false;
global.wep[4 ,e_wep.ammo] = 5;
global.wep[4 ,e_wep.firerate] = 25;
global.wep[4 ,e_wep.dmg_min] = 3;
global.wep[4 ,e_wep.dmg_max] = 5;
obj_game_controller (perssistent)
step
GML:
for(var i=0;i<weapons_total;i++)
if keyboard_check_pressed(ord("1")+i)
if global.wep[i,e_wep.have]
current_weapon = i;
if global.wep[0 ,e_wep.ammo] <= 100
{
global.wep[0 ,e_wep.ammo] = 100;
}
obj_game_controller (perssistent)
DRAW GUI
GML:
//draw_gui event
var box_width = sprite_get_width(mask_explosion); //how wide is each box that will display a weapon?
for (var i = 0; i < weapons_total; i ++){
draw_x = i * box_width;
draw_y = 0; //Assuming sprites origin is drawn from top left
//if you have each weapon image in the same sprite, you can draw them all just using "i"
if ( global.wep[i,e_wep.have] == true ) draw_sprite(spr_weapon, i, draw_x, draw_y);
}
obj_player
create
GML:
attClock = 0;
have = true;
ammo = 10;
firerate = 15;
dmg_min = 3;
dmg_max = 5;
step
GML:
attClock--
var cur = obj_game_controller.current_weapon; // the control object have the index of the current weapon, so we need to fetch that first
if keyboard_check_pressed(ord('X'))
&& attClock <= 0
&& global.wep[cur,e_wep.ammo] > 0{
attClock = global.wep[cur,e_wep.firerate];
global.wep[cur,e_wep.ammo]-=1;
var ins = instance_create(x, y-17,global.wep[cur,e_wep.ammo_type] );
//var ins = instance_create(x, y-17, obj_bullet); // this line here needs some love
ins.hspeed = image_xscale * 15;
ins.dmg = irandom_range(global.wep[cur,e_wep.dmg_min],global.wep[cur,e_wep.dmg_max]);
audio_play_sound(shot_sounds, 1, false); //shot sounds
}
Hero event collision (obj_player with an object chest with weapons and ammunition obj_chest)
This object is immediately in the first stage(room)
the hero takes it adds and weapon and the sprite ammo in the gui is displayed, but still cannot shoot magma .. all the time the player has a primary weapon ..
buttons from 1 to 5 do not respond to switching weapons.
GML:
///weapon magma
global.wep[1,e_wep.have] = true;
global.wep[1,e_wep.ammo] += 30;
obj_magma
create
GML:
gun = e_gun.magma;
Last edited: