Jump to content
A 2021 backup has been restored. Forums are closed and work in progress. Join our Discord server for more updates! ×
SoaH City Message Board

Gun Coding Problem? What could be wrong?


Recommended Posts

I'm trying to add guns for Shadow and last night I wrote a script implement this. When Shadow finds a gun in a level it sets gunfound to true meaning you found a gun and it adds gunamount to 52/amount of ammo. And when the player presses key_melee it sets Shadow's action to gun draw meaning he has his gun drawn. And when key_special is pressed while key_melee is pressed his animation changes to action_fire, which is his animation for shooting the gun and it creates an instance for the bullet depending on Shadow's direction. And if key_melee is released Shadow's action is back to action_draw and if key_melee is released then his action is action_normal. Here is my script for what I am trying to do, and it is not working:

if ( place_meeting(x,y,obj_gunicon))
{
gunfound = true;
sound_play(snd_draw);
// If gunfound true
if ( gunfound = true )
{
bulletamount = 52;
if (action == action_normal && key_melee && ground = true)
{
action = action_draw;
sound_play(snd_draw);
if (action == action_draw && key_special && ground = true)
{
if (animation_direction = 1)
{
obj_gunbullet.direction = 90;
instance_create(x,y,obj_gunbullet);
sound_play(snd_9mm);
}else
if (animation_direction = -1)
{
obj_gunbullet.direction = 90;
instance_create(x,y,obj_gunbullet);
sound_play(snd_9mm);
}
}
}
}
else
//If keys is released
if (key_special) = false
{
action = action_draw;
}else
if (key_melee) = false
{
action = action_normal;
}
}[/CODE]

Can anyone help me with this problem it is not working for me?:confused:

Link to comment
Share on other sites

I'd need to know more about how its not working. Does it play a sound when you walk over the gun? Does it do... anything?

Anyway, first thing I'd try is removing this condition:

if (action == action_normal && key_melee && ground = true)

{

And having the proceeding code in the former condition just to check if that might be screwing you up.

Link to comment
Share on other sites

So many seeded if statements... You have to seperate your code into segments rather than mushing them all together. For example, picking up the gun is one action that has nothing to do with shooting it, so if it's seeded inside the pick up gun's if statement it'll become wildly unpredictable.

Anyway, here's the code seperated into actions, but it doesn't have anything to keep you from shooting once per frame by just holding melee and special.

//Pick up gun if you find it
if ( place_meeting(x,y,obj_gunicon))
{
    gunfound = true;
    sound_play(snd_draw);
    bulletamount = 52;
}

//All actions inside need a gun to do
if ( gunfound = true )
{
    //Change to aiming action
    if (action == action_normal && key_melee && ground = true)
    {
        action = action_draw;
        sound_play(snd_draw);
    }

    //Shoot if you're already aiming
    if (action == action_draw && key_special && ground = true)
    {
        if (animation_direction = 1)
        {
            obj_gunbullet.direction = 90;
            instance_create(x,y,obj_gunbullet);
            sound_play(snd_9mm);
        }else
        if (animation_direction = -1)
        {
            obj_gunbullet.direction = 90;
            instance_create(x,y,obj_gunbullet);
            sound_play(snd_9mm);
        }
    }

    //Stop aiming if you're not pressing it
    if (key_melee = false)
    {
        action = action_normal;
    }
}

Edit: But it's always a very good idea to give as much information about how it's not working as you can.

Link to comment
Share on other sites

Thanks Kain this is a great base all I have to do is finish the rest of the coding so it will work perfect.

I'd need to know more about how its not working. Does it play a sound when you walk over the gun? Does it do... anything?

Anyway, first thing I'd try is removing this condition:

if (action == action_normal && key_melee && ground = true)

{

And having the proceeding code in the former condition just to check if that might be screwing you up.

It's working now, it was the way I coded it that screwed it all up.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...