Is there a way to add automatic weapon switching with decorate?
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.
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!)
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!)
-
- Posts: 26
- Joined: Mon Nov 18, 2024 3:08 pm
Is there a way to add automatic weapon switching with decorate?
I have a few mods, that while very cool, for some reason do not change weapons when empty. It boggles my mind as to why this is, but I figure it can be changed; is there an easy fix for this, and how would I go about changing it? I admit I know very little about decorate but I figure I could copy and paste some code okay.. assuming its that easy
-
-
- Posts: 1693
- Joined: Wed May 13, 2009 3:15 am
- Graphics Processor: nVidia with Vulkan support
Re: Is there a way to add automatic weapon switching with decorate?
Most likely, this is due to the effects of the AMMO_OPTIONAL flag. This flag is often used for reloadable weapons because it is necessary for most reloading methods to work properly. I'm not aware of a DECORATE-only solution that avoids its usage. In case of ZScript, there are ways, but integrating any complex piece of code into an existing mod is not a trivial task.
-
- Posts: 26
- Joined: Mon Nov 18, 2024 3:08 pm
Re: Is there a way to add automatic weapon switching with decorate?
Hey, thanks for the reply. The mods do indeed use reloading.. And yes, Zscript is a little out of my depth, bummer there is no decorate method.Player701 wrote: ↑Sat Nov 30, 2024 2:31 pm Most likely, this is due to the effects of the AMMO_OPTIONAL flag. This flag is often used for reloadable weapons because it is necessary for most reloading methods to work properly. I'm not aware of a DECORATE-only solution that avoids its usage. In case of ZScript, there are ways, but integrating any complex piece of code into an existing mod is not a trivial task.
Would you happen to know if there is a simple way to add automatic reloading in DECORATE? (have a feeling it may not be for similar reasons, but who knows)
-
-
- Posts: 1693
- Joined: Wed May 13, 2009 3:15 am
- Graphics Processor: nVidia with Vulkan support
Re: Is there a way to add automatic weapon switching with decorate?
Not entirely sure what you meant by "automatic" here? If it's just playing some animation after firing a certain number of shots, then you can use A_CheckForReload in combination with A_ResetReloadCounter. See the linked wiki pages for details and examples.
A full-fledged reloading system, on the other hand, would be much more complex, and its implementation is going to depend on the exact set of features you want it to have. If that sounds too scary, you can also use my reloading system with DECORATE-based weapons - knowledge of ZScript is generally not required, but you should probably read the included manual before doing any coding yourself. If you still have questions, please post them in the linked thread instead of here.
-
- Posts: 26
- Joined: Mon Nov 18, 2024 3:08 pm
Re: Is there a way to add automatic weapon switching with decorate?
I meant specifically for mods that feature a reloading system - so that when it's empty and you try to fire another shot it will auto reload, rather than waiting for a press of a button.
But anyway, thanks again for the help! I'll take a look at your mod and see if I can't learn something from it more generally
But anyway, thanks again for the help! I'll take a look at your mod and see if I can't learn something from it more generally
-
-
- Posts: 1693
- Joined: Wed May 13, 2009 3:15 am
- Graphics Processor: nVidia with Vulkan support
Re: Is there a way to add automatic weapon switching with decorate?
That would depend on the implementation details of a specific mod, but it should likely be doable with a few calls to A_JumpIfInventory in the beginning of the weapon's Fire state. Can't say much more without seeing the code, however.
-
- Posts: 26
- Joined: Mon Nov 18, 2024 3:08 pm
Re: Is there a way to add automatic weapon switching with decorate?
Well, now that I'm looking at it, it kinda looks like a headache. Here's an example of one of the weapons, but realistically I can live without the reloads (or just play mods that auto reload) I don't want to wear you out with all the requests --
Anyway.. If you still feel like it, have a look:
Anyway.. If you still feel like it, have a look:
Code: Select all
ACTOR ProphetPistol : Weapon replaces Pistol
{
Scale 0.25
+NOALERT
+AMMO_OPTIONAL
+NOAUTOFIRE
+NOEXTREMEDEATH
Weapon.SelectionOrder 500
Inventory.PickupSound "weapons/prophetreload3"
Inventory.PickupMessage "You got the 'Prophet' high-caliber handgun!"
Weapon.AmmoType "Clip"
Weapon.AmmoGive 32
Weapon.AmmoUse 1
Weapon.Kickback 150
Weapon.AmmoType2 "ProphetInClip"
AttackSound "weapons/prophetfire"
//Weapon.UpSound "weapons/susanclose"
Obituary "%o bowed down to %k's prophecy of lead."
States
{
Spawn:
VUPP A -1
Loop
Ready:
VUPX LK 1
VUPX J 1 A_PlayWeaponSound("weapons/susanclose")
VUPX IHGFEDCBA 1
VUPG A 0 A_FireCustomMissile("LaserSightSpawner", 0, 0, 0, 4)
//VUPG A 0 A_FireBullets(0, -1, 1, 0, "ProphetLasersight", 0)
VUPG A 1 A_WeaponReady
Goto Ready+12
Deselect:
TNT1 A 0 A_PlaySound("weapons/holster")
VUPD ABCDE 1
VUPG A 1 A_Lower
Wait
Select:
TNT1 A 0 SetPlayerProperty(0,1,2) //Instant Weapon Switch
TNT1 A 0 ACS_Execute(882,0,2,0,0) //Current Weapon Indicator
VUPG A 1 A_Raise
Loop
Fire:
VUPG A 0 A_JumpIfInventory("ProphetInClip", 1, 2)
VUPG A 1 A_PlaySound("weapons/dryfire")
goto Ready+12
//True Fire:
VUPG A 0 A_GunFlash
VUPG A 0 A_FireCustomMissile("CheapAlert",0,0,0,0) //Alert Monsters
VUPG A 0 A_TakeInventory("ProphetInClip",1)
VUPF A 1 BRIGHT A_FireBullets(0,0,1,15,"Puff2",0)
VUPG E 1 A_FireCustomMissile("ProphetCasingSpawner", -3, 0, 0, 0)
VUPG DCBAAA 1
goto Ready+12
AltFire:
//Reloading Sequence
VUPG A 0 A_JumpIfInventory("ProphetInClip", 0, 2)
VUPG A 0 A_JumpIfInventory("Clip", 1, 2)
VUPG A 0
goto Ready+12
VUPG A 1 A_PlaySound("weapons/prophetreload1")
VUPG A 0 A_JumpIfInventory("ProphetInClip", 1, 3)
VUPG B 1 A_FireCustomMissile("SpentClip1", 3, 0, 5, 0)
VUPG A 0 A_Jump(256, 2)
VUPF B 1 A_FireCustomMissile("SpentClip1", 3, 0, 5, 0)
VUPG CDE 1
VUPG E 12
VUPG F 1 A_PlaySound("weapons/prophetreload2")
VUPG GH 1
VUPR ABCD 1
VUPR N 0 A_TakeInventory("Clip",1)
VUPR N 0 A_GiveInventory("ProphetInClip",1)
VUPR N 0 A_JumpIfInventory("ProphetInClip",0,2)
VUPR N 0 A_JumpIfInventory("Clip",1,2)
VUPR N 0
Goto AltFire+25
VUPR N 0
Goto AltFire+19
VUPR E 7 A_PlaySound("weapons/prophetreload3")
VUPR FGHIJK 1
goto Ready+12
Flash:
TNT1 A 0 BRIGHT A_FireCustomMissile("PistolSmokeSpawner",0,0,8,6)
TNT1 A 0 A_FireCustomMissile("LaserSightSpawner", 0, 0, random(-4,4), random(-4,4))
TNT1 A 1 BRIGHT A_Light2
TNT1 A 0 A_FireCustomMissile("LaserSightSpawner", 0, 0, random(-3,3), random(-3,3))
TNT1 A 1 BRIGHT A_Light1
TNT1 A 0 A_FireCustomMissile("LaserSightSpawner", 0, 0, random(-2,2), random(-2,2))
TNT1 A 1 BRIGHT A_Light0
TNT1 A 1 A_FireCustomMissile("LaserSightSpawner", 0, 0, random(-1,1), random(-1,1))
TNT1 AAAA 1 A_FireCustomMissile("LaserSightSpawner",0, 0, 0, 4)
Stop
}
}
ACTOR ProphetInClip : Ammo
{
Inventory.MaxAmount 8
Inventory.Icon NULLA0
States
{
Spawn:
TNT1 A 4
loop
}
}
-
-
- Posts: 1693
- Joined: Wed May 13, 2009 3:15 am
- Graphics Processor: nVidia with Vulkan support
Re: Is there a way to add automatic weapon switching with decorate?
Ah, I remember that one
Here, the reloading sequence is implemented in place of a secondary attack (alt-fire), so we will jump directly there - provided the player has enough ammo, of course.
Find these lines:
and change them to the following:
Not tested, but I think it should work. All these numeric offsets make the code extremely volatile - just one line in the wrong place, and everything might fall apart...
Exactly. This code seems to be written back when custom state labels weren't supported, but I have to assume that your GZDoom version is not as ancient as the mod itself is.
Here, the reloading sequence is implemented in place of a secondary attack (alt-fire), so we will jump directly there - provided the player has enough ammo, of course.
Find these lines:
Code: Select all
Fire:
VUPG A 0 A_JumpIfInventory("ProphetInClip", 1, 2)
VUPG A 1 A_PlaySound("weapons/dryfire")
goto Ready+12
//True Fire:
...
Code: Select all
Fire:
VUPG A 0 A_JumpIfInventory("ProphetInClip", 1, "TrueFire")
VUPG A 0 A_JumpIfInventory("Clip", 1, "AltFire")
VUPG A 1 A_PlaySound("weapons/dryfire")
goto Ready+12
TrueFire:
...