ETHC33
Member
this has happended in multiple places, one when you shoot the pistol(not the rifle) and when you use the shield(it creates two arms on the left side) why is this happening and how do i solve it? ill post the gunstate free(); code
function gunstate_free()
{
image_angle = point_direction(x,y,mouse_x,mouse_y);
#region animation
if (!mouse_check_button(mb_left))
{image_index = 0;
}
if mouse_check_button(mb_left) and (ammo > 0)
{ image_speed = 1;}
else
{
image_speed = 0;
}
#endregion
if (reloadkey)
{
gunstate = GUNSTATE.RELOADING
}
if hasrifle == true
{
if keyboard_check_pressed(ord("1"))
{
prev_gun = Spr_gun;
firingdelay = 5;
}}
if (current_gun == Spr_pistol)
{
current_gun_ammo_maximum = 12;
current_reload = Spr_pistol_reload;
x = obj_player.x -9;
y = obj_player.y -21;
}
if (current_gun == Spr_gun)
{current_reload = Spr_reload;
current_gun_ammo_maximum = 25;
x = obj_player.x -9;
y = obj_player.y -21;
}
#region shield
if (mouse_check_button(mb_right))
{
current_gun = Spr_bullet_shield;
layer = layer_get_id("ladders");
x = obj_player.x + 4;
y = obj_player.y + - 18;
var arm = instance_create_layer(x,y,"gun", Obj_arm); // creates two here
}
else{ current_gun = prev_gun;
layer = layer_get_id("gun")
};
#endregion
recoil = max(0,recoil - 0.5);
firingdelay = firingdelay - 1;
if (mouse_check_button(mb_left)) and (firingdelay < 0) and (current_gun = Spr_gun) and (ammo > 0)
{
image_speed = 0;
recoil = 4;
firingdelay = 5
screenshake(2,10);
audio_play_sound(sn_gunshot,5,false);
ammo -=1;
effect_create_below(ef_smoke, x = lengthdir_x + 25, y, 0, c_gray);
with (instance_create_layer(x,y,"bullet",Obj_bullet))
{
spd = 25;
direction = other.image_angle + random_range(-4,4);
image_angle = direction;
}
x = x - lengthdir_x(recoil,image_angle);
y=y - lengthdir_y(recoil,image_angle);
}
#region pistol
if keyboard_check_pressed(ord("2"))
{
prev_gun = Spr_pistol;
}
if (mouse_check_button(mb_left)) and (firingdelay < 0) and (current_gun = Spr_pistol) and (pistol_ammo >0)
{
recoil = 4;
firingdelay = 8;
screenshake(2,10);
audio_play_sound(sn_gunshot,5,false);
pistol_ammo -=1;
with (instance_create_layer(x,y,"bullet",Obj_pistol_bullet)) //creates two bullets here
{
spd = 25;
direction = other.image_angle + random_range(-4,4);
image_angle = direction;
}
#endregion
x = x - lengthdir_x(recoil,image_angle);
y=y - lengthdir_y(recoil,image_angle);
}
if (image_angle > 90) and (image_angle < 270)
{
image_yscale = -1;
x = obj_player.x +14;
y = obj_player.y - 21;
}
else
{
image_yscale = 1;
}
}
//excuse my ignorance and messy code i'm new to this
function gunstate_free()
{
image_angle = point_direction(x,y,mouse_x,mouse_y);
#region animation
if (!mouse_check_button(mb_left))
{image_index = 0;
}
if mouse_check_button(mb_left) and (ammo > 0)
{ image_speed = 1;}
else
{
image_speed = 0;
}
#endregion
if (reloadkey)
{
gunstate = GUNSTATE.RELOADING
}
if hasrifle == true
{
if keyboard_check_pressed(ord("1"))
{
prev_gun = Spr_gun;
firingdelay = 5;
}}
if (current_gun == Spr_pistol)
{
current_gun_ammo_maximum = 12;
current_reload = Spr_pistol_reload;
x = obj_player.x -9;
y = obj_player.y -21;
}
if (current_gun == Spr_gun)
{current_reload = Spr_reload;
current_gun_ammo_maximum = 25;
x = obj_player.x -9;
y = obj_player.y -21;
}
#region shield
if (mouse_check_button(mb_right))
{
current_gun = Spr_bullet_shield;
layer = layer_get_id("ladders");
x = obj_player.x + 4;
y = obj_player.y + - 18;
var arm = instance_create_layer(x,y,"gun", Obj_arm); // creates two here
}
else{ current_gun = prev_gun;
layer = layer_get_id("gun")
};
#endregion
recoil = max(0,recoil - 0.5);
firingdelay = firingdelay - 1;
if (mouse_check_button(mb_left)) and (firingdelay < 0) and (current_gun = Spr_gun) and (ammo > 0)
{
image_speed = 0;
recoil = 4;
firingdelay = 5
screenshake(2,10);
audio_play_sound(sn_gunshot,5,false);
ammo -=1;
effect_create_below(ef_smoke, x = lengthdir_x + 25, y, 0, c_gray);
with (instance_create_layer(x,y,"bullet",Obj_bullet))
{
spd = 25;
direction = other.image_angle + random_range(-4,4);
image_angle = direction;
}
x = x - lengthdir_x(recoil,image_angle);
y=y - lengthdir_y(recoil,image_angle);
}
#region pistol
if keyboard_check_pressed(ord("2"))
{
prev_gun = Spr_pistol;
}
if (mouse_check_button(mb_left)) and (firingdelay < 0) and (current_gun = Spr_pistol) and (pistol_ammo >0)
{
recoil = 4;
firingdelay = 8;
screenshake(2,10);
audio_play_sound(sn_gunshot,5,false);
pistol_ammo -=1;
with (instance_create_layer(x,y,"bullet",Obj_pistol_bullet)) //creates two bullets here
{
spd = 25;
direction = other.image_angle + random_range(-4,4);
image_angle = direction;
}
#endregion
x = x - lengthdir_x(recoil,image_angle);
y=y - lengthdir_y(recoil,image_angle);
}
if (image_angle > 90) and (image_angle < 270)
{
image_yscale = -1;
x = obj_player.x +14;
y = obj_player.y - 21;
}
else
{
image_yscale = 1;
}
}
//excuse my ignorance and messy code i'm new to this