A_SelectWeapon Issue

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
User avatar
Grey-Wolf
Posts: 179
Joined: Sun Jul 15, 2018 4:59 pm
Graphics Processor: nVidia (Modern GZDoom)

A_SelectWeapon Issue

Post by Grey-Wolf »

Hello there! I'm new here and still learning the basics of scripting, so I'm very inexperienced right now.

What I'm trying to do is to make the player switch from a weapon to another while pressing a button, but only if the player is currently holding a specific weapon at that time.

Thing is that A_SelectWeapon doesn't seem to work in my actor.

Code: Select all

ChangeWeapon:
        TNT1 A 0 A_TakeInventory("Change", 1)
        TNT1 A 0 A_ZoomFactor(1.0)
        TNT1 A 0 A_Takeinventory("Zoomed",1)
        TNT1 A 0 A_Takeinventory("ADSmode",1)
        TNT1 A 0 A_JumpIfInventory("AmmoSlug", 1, "SlugSwitch")
        Goto NoUpgrades

     NoAmmo:
        TNT1 A 0 A_Print("You have no slug rounds.", 2)
        SHTN A 3
        Goto Ready
    
     SlugSwitch:
        TNT1 A 0 A_Print("Slug rounds loaded", 2)
        TNT1 A 0 A_SelectWeapon("SlugShotgun")
        Stop
        
    }
}
When I press the button defined by that "Change", the message "slug rounds loaded" actually appears, so that part is working as intended. But as for the weapon switch, the player just remains stuck with no weapons in his hands and unable to switch even to normal weapons. I tried to change "SlugShotgun" with other pre-existing and working weapons, but the same issue is present. Any advice?
User avatar
Apeirogon
Posts: 1606
Joined: Mon Jun 12, 2017 12:57 am

Re: A_SelectWeapon Issue

Post by Apeirogon »

Did you have slug shotgun in inventory?
User avatar
Grey-Wolf
Posts: 179
Joined: Sun Jul 15, 2018 4:59 pm
Graphics Processor: nVidia (Modern GZDoom)

Re: A_SelectWeapon Issue

Post by Grey-Wolf »

Yes, I even tried to change SlugShotgun with the starting pistol and other weapons in player's inventory, but the problem remains.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49252
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: A_SelectWeapon Issue

Post by Graf Zahl »

Try to give your A_SelectWeapon state a delay longer than 0.
User avatar
Grey-Wolf
Posts: 179
Joined: Sun Jul 15, 2018 4:59 pm
Graphics Processor: nVidia (Modern GZDoom)

Re: A_SelectWeapon Issue

Post by Grey-Wolf »

Code: Select all

SlugMode:
		TNT1 A 0 A_Print("Slug rounds loaded", 2)
		TNT1 A 2 A_SelectWeapon("SlugShotgun")
		Stop
		
Like this? Nothing changes sadly...
User avatar
Apeirogon
Posts: 1606
Joined: Mon Jun 12, 2017 12:57 am

Re: A_SelectWeapon Issue

Post by Apeirogon »

Than post more code.
User avatar
Grey-Wolf
Posts: 179
Joined: Sun Jul 15, 2018 4:59 pm
Graphics Processor: nVidia (Modern GZDoom)

Re: A_SelectWeapon Issue

Post by Grey-Wolf »

Ok so I'm actually modding Brutal Doom RC7 since I'm just experimenting and I would like to play the mod with some of my adjustments.

This is the normal edited shotgun:
Spoiler:
And this is a clone of it, edited to act like the slug variant. I made a clone because I wanted to have them use completely different armor types rather than converting the normal ammotype "AmmoShell" to slugs when you switch firing mode.
Spoiler:
I tried to copy/paste the "deselect" section before the actual A_SelectWeapon function, but now it just shows the animation of the switching weapon, without actually changing it.

EDIT: I actually changed very little from the original code, you can see it using a compare plugin for Notepad++ or similar tools.
User avatar
Grey-Wolf
Posts: 179
Joined: Sun Jul 15, 2018 4:59 pm
Graphics Processor: nVidia (Modern GZDoom)

Re: A_SelectWeapon Issue

Post by Grey-Wolf »

SOLVED.
Blue Shadow
Posts: 5046
Joined: Sun Nov 14, 2010 12:59 am

Re: A_SelectWeapon Issue

Post by Blue Shadow »

It's a good thing to mention how you solved it, in case someone runs in the same problem as you did and wants a solution.

Return to “Scripting”