Altfire to change weapon

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!)
YeeTee2
Posts: 29
Joined: Sun Feb 07, 2021 1:36 pm

Altfire to change weapon

Post by YeeTee2 »

How do I make this pistol's altfire change it into a different custom weapon?
Attachments
pistol.txt
(1.89 KiB) Downloaded 19 times
Jarewill
 
 
Posts: 1855
Joined: Sun Jul 21, 2019 8:54 am

Re: Altfire to change weapon

Post by Jarewill »

Use A_SelectWeapon for that:

Code: Select all

Altfire:
    TNT1 A 0 A_SelectWeapon("Pistol2")
    Goto Ready //Required to go to the ready state (or call A_WeaponReady) to switch weapons  
YeeTee2
Posts: 29
Joined: Sun Feb 07, 2021 1:36 pm

Re: Altfire to change weapon

Post by YeeTee2 »

Would tapping altfire again switch it back?
User avatar
Mikk-
Posts: 2274
Joined: Tue Jun 30, 2009 1:31 pm

Re: Altfire to change weapon

Post by Mikk- »

Not unless you defined it to do so in the other weapon.
YeeTee2
Posts: 29
Joined: Sun Feb 07, 2021 1:36 pm

Re: Altfire to change weapon

Post by YeeTee2 »

How would I do that?
YeeTee2
Posts: 29
Joined: Sun Feb 07, 2021 1:36 pm

Re: Altfire to change weapon

Post by YeeTee2 »

No, wait. I just got what you meant
YeeTee2
Posts: 29
Joined: Sun Feb 07, 2021 1:36 pm

Re: Altfire to change weapon

Post by YeeTee2 »

How would I make it switch to the weapon I want without owning it?
The weapon I want the pistol to change to is a lighter, for clarification
Jarewill
 
 
Posts: 1855
Joined: Sun Jul 21, 2019 8:54 am

Re: Altfire to change weapon

Post by Jarewill »

The player has to own the item.
Give it to them in the Altfire using A_GiveInventory.
Beware as that might give the player ammo, otherwise make them start with both weapons.
YeeTee2
Posts: 29
Joined: Sun Feb 07, 2021 1:36 pm

Re: Altfire to change weapon

Post by YeeTee2 »

Well, how could I stop the lighter from being switched to by normal means and stop other weapons from being switched to by normal means when I have the lighter in-hand?
Jarewill
 
 
Posts: 1855
Joined: Sun Jul 21, 2019 8:54 am

Re: Altfire to change weapon

Post by Jarewill »

If you don't assign a slot to the lighter, the player shouldn't be able to switch to it manually.
As for making the lighter unswitchable, you can try this:

Code: Select all

Ready:
    LIGH A 1 A_WeaponReady(WRF_NOSWITCH) //Make the lighter unswitchable
    Loop
Altfire:
    TNT1 A 0 A_SelectWeapon("Pistol") //Queue the pistol to switch to
    Goto Ready2 //Go to the special Ready state
Ready2:
    LIGH A 1 A_WeaponReady //Allow switching again
    Loop
Untested.
YeeTee2
Posts: 29
Joined: Sun Feb 07, 2021 1:36 pm

Re: Altfire to change weapon

Post by YeeTee2 »

Yeah, it doesn't seem to work
Jarewill
 
 
Posts: 1855
Joined: Sun Jul 21, 2019 8:54 am

Re: Altfire to change weapon

Post by Jarewill »

What exactly doesn't seem to work?
I tried it now and it seems to work fine for me.
Can you show your code?

Does the player have both weapons?
Is the correct weapon selected?
Replacing starting the pistol isn't as simple as "Weapon replaces Pistol", the entire player class has to be replaced to give different starting items.
For example:

Code: Select all

ACTOR DoomPlayer2 : DoomPlayer
{
    Player.StartItem "ModdedPistol" //Replace with your pistol
    Player.StartItem "Lighter" //Replace with your lighter
    Player.StartItem "Fist"
    Player.StartItem "Clip", 50
} 
Then you have to add a MAPINFO file and add this to it:

Code: Select all

GameInfo
{
    PlayerClasses = "DoomPlayer2"
} 
YeeTee2
Posts: 29
Joined: Sun Feb 07, 2021 1:36 pm

Re: Altfire to change weapon

Post by YeeTee2 »

http://www.mediafire.com/file/7ww74fcd4 ... n.pk3/file
This is the whole pk3. I have made a new player class for it all
Jarewill
 
 
Posts: 1855
Joined: Sun Jul 21, 2019 8:54 am

Re: Altfire to change weapon

Post by Jarewill »

The sprites in the Ready state of the lighter don't exist, so the lighter isn't even given to the player.
The Ready state uses LIGH sprites (which is what I wrote in the example, but I hoped you'd change them to the correct ones), while the rest of the lighter uses ZIPO sprites.
The altfire of the lighter also selects the vanilla Doom pistol weapon (again, as I wrote) instead of selecting your modded NewPistol weapon.
The lighter also has a SlotNumber defined, so it can be selected manually.
And the first StartItem of the player is the lighter, so they will start with the lighter selected by default.
YeeTee2
Posts: 29
Joined: Sun Feb 07, 2021 1:36 pm

Re: Altfire to change weapon

Post by YeeTee2 »

So I fixed everything, but now kicking with the lighter stops me from being able to switch
Updated file: http://www.mediafire.com/file/v4pd1c5e5 ... n.pk3/file
Post Reply

Return to “Scripting”