Altfire to change weapon

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

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.

Altfire to change weapon

Postby YeeTee2 » Tue Feb 23, 2021 10:46 am

How do I make this pistol's altfire change it into a different custom weapon?
You do not have the required permissions to view the files attached to this post.
YeeTee2
 
Joined: 07 Feb 2021

Re: Altfire to change weapon

Postby Jarewill » Tue Feb 23, 2021 11:13 am

Use A_SelectWeapon for that:
Code: Select allExpand view
Altfire:
    TNT1 A 0 A_SelectWeapon("Pistol2")
    Goto Ready //Required to go to the ready state (or call A_WeaponReady) to switch weapons  
Jarewill
 
 
 
Joined: 21 Jul 2019

Re: Altfire to change weapon

Postby YeeTee2 » Tue Feb 23, 2021 11:17 am

Would tapping altfire again switch it back?
YeeTee2
 
Joined: 07 Feb 2021

Re: Altfire to change weapon

Postby Mikk- » Tue Feb 23, 2021 11:21 am

Not unless you defined it to do so in the other weapon.
User avatar
Mikk-
yooooooooooo
 
Joined: 30 Jun 2009
Location: Somewhere off Kanagawa
Discord: Mikk0451#3922

Re: Altfire to change weapon

Postby YeeTee2 » Tue Feb 23, 2021 11:24 am

How would I do that?
YeeTee2
 
Joined: 07 Feb 2021

Re: Altfire to change weapon

Postby YeeTee2 » Tue Feb 23, 2021 11:25 am

No, wait. I just got what you meant
YeeTee2
 
Joined: 07 Feb 2021

Re: Altfire to change weapon

Postby YeeTee2 » Tue Feb 23, 2021 11:29 am

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
YeeTee2
 
Joined: 07 Feb 2021

Re: Altfire to change weapon

Postby Jarewill » Tue Feb 23, 2021 12:10 pm

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.
Jarewill
 
 
 
Joined: 21 Jul 2019

Re: Altfire to change weapon

Postby YeeTee2 » Tue Feb 23, 2021 12:22 pm

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?
YeeTee2
 
Joined: 07 Feb 2021

Re: Altfire to change weapon

Postby Jarewill » Tue Feb 23, 2021 1:22 pm

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 allExpand view
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.
Jarewill
 
 
 
Joined: 21 Jul 2019

Re: Altfire to change weapon

Postby YeeTee2 » Wed Feb 24, 2021 1:21 pm

Yeah, it doesn't seem to work
YeeTee2
 
Joined: 07 Feb 2021

Re: Altfire to change weapon

Postby Jarewill » Wed Feb 24, 2021 2:16 pm

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 allExpand view
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 allExpand view
GameInfo
{
    PlayerClasses = "DoomPlayer2"
Jarewill
 
 
 
Joined: 21 Jul 2019

Re: Altfire to change weapon

Postby YeeTee2 » Thu Feb 25, 2021 4:42 am

http://www.mediafire.com/file/7ww74fcd4 ... n.pk3/file
This is the whole pk3. I have made a new player class for it all
YeeTee2
 
Joined: 07 Feb 2021

Re: Altfire to change weapon

Postby Jarewill » Thu Feb 25, 2021 5:21 am

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.
Jarewill
 
 
 
Joined: 21 Jul 2019

Re: Altfire to change weapon

Postby YeeTee2 » Thu Feb 25, 2021 7:06 am

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
YeeTee2
 
Joined: 07 Feb 2021

Next

Return to Scripting

Who is online

Users browsing this forum: m8f, Mikk- and 1 guest