I just moved to GMS2 from 1, I basically started my project over and was trying to pull code from my old game to my new one. the code works perfectly fine in 1 but it just keeps shooting after my first button press now in GMS2
GML:
nearestOpponent = instance_nearest(x,y + z, oHoming)
if (kShoot and onGround) // If shoot button and touching ground..
and distance_to_object(nearestOpponent) < gunrange
and (state = RUN or state = IDLE)
{
if nearestOpponent.x > x
{
facing = RIGHT
}
else
{
facing = LEFT
}
if startammo <=0
{
hit = true; //hit only true to keep player from moving.
state=NOAMMO;
alarm[0] = 5;
}
else
{
if !hit // If Player got a kHit1 input and the hit flag is false...
{
//audio_play_sound(sGunshot, 0, false);
startammo -=1;
hit = true; // ...makes a hit (hit flag to true)
shot = instance_create_depth(nearestOpponent.x,nearestOpponent.y,depth,oHitCollisionGunLegacy); // Create the punch Hit box
shot.depth = depth + 1;
shot.parentId = id; // and store the Player instance id in de Hit box instance to know who made that hit
image_index = 0; // Reset the animation for every hit
state = SHOOT; // Go to SHOOT state
shot.damage = gundamage; // Determines the damage that the hit box will make to enemies
alarm[0] = 5; // Can't hit again until alarm is finished
}}}