Incremental weapon Zooming?
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. This forum is archived - please use this set of forums to ask new questions.
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. This forum is archived - please use this set of forums to ask new questions.
Incremental weapon Zooming?
You know how in most games that have a weapon with a sniper scope you can do this:
Press alt-fire to start zooming. The longer you hold alt-fire, the more zoomed in you are until you reach max-zoom. When you let go of of the alt-fire button you stay zoomed in at whatever magnification you were when you released the button. If you hit alt-fire again, you are taken back to normal zoom (and any special crosshairs etc are removed).
Well, can anyone figure out how to do something like that in Zdoom? I can do a lot of it. I can get alt-fire to zoom the weapon in and I can get a second press of the button to cancel the zoom and go back to normal view. That's pretty easy. What I can't figure out is how to get the zoom to increment whilst you hold alt-fire and stop incrementing when you release it. Any ideas?
Press alt-fire to start zooming. The longer you hold alt-fire, the more zoomed in you are until you reach max-zoom. When you let go of of the alt-fire button you stay zoomed in at whatever magnification you were when you released the button. If you hit alt-fire again, you are taken back to normal zoom (and any special crosshairs etc are removed).
Well, can anyone figure out how to do something like that in Zdoom? I can do a lot of it. I can get alt-fire to zoom the weapon in and I can get a second press of the button to cancel the zoom and go back to normal view. That's pretty easy. What I can't figure out is how to get the zoom to increment whilst you hold alt-fire and stop incrementing when you release it. Any ideas?
- XutaWoo
- Posts: 4005
- Joined: Sat Dec 30, 2006 4:25 pm
- Location: beautiful hills of those who are friends
- Contact:
Re: Incremental weapon Zooming?
AltHold with a lot of inventory trickery.
- Ryan Cordell
- Posts: 4349
- Joined: Sun Feb 06, 2005 6:39 am
- Preferred Pronouns: No Preference
- Operating System Version (Optional): Windows 10
- Graphics Processor: nVidia (Modern GZDoom)
- Location: Capital of Explodistan
Re: Incremental weapon Zooming?
Well, if you're familiar with charging a weapon with the primary Fire state, than you could try using something like this and work around it, perhaps? This is taken straight from the Disinter cannon's weapon code for The Order. I hope it can help in any way. o.oEnjay wrote:You know how in most games that have a weapon with a sniper scope you can do this:
Press alt-fire to start zooming. The longer you hold alt-fire, the more zoomed in you are until you reach max-zoom. When you let go of of the alt-fire button you stay zoomed in at whatever magnification you were when you released the button. If you hit alt-fire again, you are taken back to normal zoom (and any special crosshairs etc are removed).
Well, can anyone figure out how to do something like that in Zdoom? I can do a lot of it. I can get alt-fire to zoom the weapon in and I can get a second press of the button to cancel the zoom and go back to normal view. That's pretty easy. What I can't figure out is how to get the zoom to increment whilst you hold alt-fire and stop incrementing when you release it. Any ideas?
Code: Select all
Hold:
PLGC A 0 A_JumpIfInventory("TO_DisinterCannon_Charge",1,"Hold.Final")
PLGC A 5 A_PlaySound("weapon/disintercannon/charging",CHAN_WEAPON,1.0,0,ATTN_NORM)
PLGC A 12 OFFSET(15,20)
PLGC A 12 OFFSET(16,21)
PLGC A 12 OFFSET(17,22)
PLGC A 12 OFFSET(18,23)
PLGC A 12 OFFSET(19,24)
PLGC A 2 A_GiveInventory("TO_DisinterCannon_Charge",1)
Hold.Final:
PLGC A 0 A_PlaySound("weapon/disintercannon/charged",CHAN_WEAPON,1.0,1,ATTN_NORM)
PLGC A 2 OFFSET(20,24)
PLGC A 2 OFFSET(31,28)
PLGC A 2 OFFSET(24,30)
PLGC A 2 OFFSET(19,31)
PLGC A 2 OFFSET(32,26)
PLGC A 2 OFFSET(29,25)
PLGC A 1 A_Refire
Fire:
PLGC A 0 A_JumpIfInventory("TO_DisinterCannon_Charge",1,"Fire.Final")
PLGC A 0 A_StopSound(CHAN_WEAPON)
PLGC B 3 BRIGHT A_FireCustomMissile("TO_DisinterCannon_Projectile",0,1,0,0)
PLGC B 0 A_FireCustomMissile("TO_GF-DC",0,0,0,0)
PLGC C 2 BRIGHT A_PlaySound("weapon/disintercannon/fire",CHAN_WEAPON,1.0,0,ATTN_NORM)
PLGC A 1 A_TakeInventory("TO_DisinterCannon_Charge",1)
PLGC A 8 A_Refire
Goto Ready
Fire.Final:
PLGC A 9 OFFSET(24,24)
PLGC B 4 BRIGHT OFFSET(24,24) A_FireCustomMissile("TO_DisinterCannon_ChargedProjectile",0,1,0,0)
PLGC C 3 BRIGHT OFFSET(24,24) A_PlaySound("weapon/disintercannon/chargedfire",CHAN_WEAPON,1.0,0,ATTN_NORM)
PLGC A 10 A_TakeInventory("TO_DisinterCannon_Charge",1)
Goto Ready
ACTOR TO_DisinterCannon_Charge : Inventory
{
Game Strife
Inventory.MaxAmount 1
- INVBAR
}Re: Incremental weapon Zooming?
Ah yes, charging weapons. They must do something similar. Thanks. 
Re: Incremental weapon Zooming?
OK, so this is what I have by way of a test. It seems to work but it strikes me that it might not be as efficient as it should be. So, if anyone fancies having a look over it to see if it can be improved I'd be much obliged.
There are a few A_Print instructions in there and there are also a bunch of crosshair changes. These are just placeholders to help me keep a track of things whilst testing.
If I can get this working, then I will adapt it to be used with an actual weapon instead of just binos.
There are a few A_Print instructions in there and there are also a bunch of crosshair changes. These are just placeholders to help me keep a track of things whilst testing.
Code: Select all
// --------------------------------------------------------------------------
//
// Binoculars
//
// --------------------------------------------------------------------------
ACTOR NJBinoculars : DoomWeapon 22313
{
Game Doom
Weapon.SelectionOrder 10000 //high to avoid autoswitch
weapon.slotnumber 9
Scale 0.15
+WEAPON.DONTBOB
+WEAPON.NOALERT
+WEAPON.EXPLOSIVE
+WEAPON.NO_AUTO_SWITCH
Inventory.PickupSound "misc/i_pkup"
Inventory.Pickupmessage "Picked up a pair of binoculars"
States
{
Ready:
BINO A 0 A_ZoomFactor(2.0)
BINO A 0 A_SetCrosshair (1)
BINO A 0 A_TakeInventory ("ZoomerBinos", 10)
BINO A 1 A_WeaponReady
goto ready +3
//Only needed because the weapon automatically goes to ready when initially selected and I don't want to give "UnZoomerBinos" there
ZoomedReady:
BINO A 0 A_GiveInventory ("UnZoomerBinos", 1)
BINO A 1 A_WeaponReady
goto ready +3
Deselect:
BINO A 0 A_PlayWeaponSound("weapons/weaponlower0")
BINO A 1 A_ZoomFactor(1.0)
TNT1 A 0 A_Lower
TNT1 A 1 A_Lower
Goto Deselect +2
Select:
TNT1 A 0 A_PlayWeaponSound("weapons/weaponraise0")
TNT1 A 0 A_Raise
TNT1 A 1 A_Raise
Goto Select +1
Fire:
BINO A 0 A_PlaySound ("Scope") //make a sound
BINO A 0 A_JumpIfInventory("UnZoomerBinos", 1, "Zoom2") //go to unzooming function
BINO A 0 A_GiveInventory ("ZoomerBinos", 1) //whatever happens now, we are zooming
BINO A 0 A_JumpIfInventory("ZoomerBinos", 7, "Zoom16")
BINO A 0 A_JumpIfInventory("ZoomerBinos", 6, "Zoom14")
BINO A 0 A_JumpIfInventory("ZoomerBinos", 5, "Zoom12")
BINO A 0 A_JumpIfInventory("ZoomerBinos", 4, "Zoom10")
BINO A 0 A_JumpIfInventory("ZoomerBinos", 3, "Zoom8")
BINO A 0 A_JumpIfInventory("ZoomerBinos", 2, "Zoom6")
BINO A 0 A_JumpIfInventory("ZoomerBinos", 1, "Zoom4")
BINO A 4
BINO A 1 A_Refire
goto Ready
Zoom2:
BINO A 0 A_Print("2 times Zoom")
BINO A 4
BINO A 1 A_Refire
BINO A 0 A_TakeInventory ("UnZoomerBinos", 10)
goto Ready
Zoom4:
BINO A 0 A_SetCrosshair (2)
BINO A 0 A_Print("4 times Zoom")
BINO A 0 A_ZoomFactor(4.0)
BINO A 2
BINO A 1 A_Refire
goto ZoomedReady
Zoom6:
BINO A 0 A_SetCrosshair (3)
BINO A 0 A_Print("6 times Zoom")
BINO A 0 A_ZoomFactor(6.0)
BINO A 2
BINO A 1 A_Refire
goto ZoomedReady
Zoom8:
BINO A 0 A_SetCrosshair (4)
BINO A 0 A_Print("8 times Zoom")
BINO A 0 A_ZoomFactor(8.0)
BINO A 2
BINO A 1 A_Refire
goto ZoomedReady
Zoom10:
BINO A 0 A_SetCrosshair (5)
BINO A 0 A_Print("10 times Zoom")
BINO A 0 A_ZoomFactor(10.0)
BINO A 2
BINO A 1 A_Refire
goto ZoomedReady
Zoom12:
BINO A 0 A_SetCrosshair (6)
BINO A 0 A_Print("12 times Zoom")
BINO A 0 A_ZoomFactor(12.0)
BINO A 2
BINO A 1 A_Refire
goto ZoomedReady
Zoom14:
BINO A 0 A_SetCrosshair (7)
BINO A 0 A_Print("14 times Zoom")
BINO A 0 A_ZoomFactor(14.0)
BINO A 2
BINO A 1 A_Refire
goto ZoomedReady
Zoom16:
BINO A 0 A_SetCrosshair (8)
BINO A 0 A_Print("16 times Zoom")
BINO A 0 A_ZoomFactor(16.0)
BINO A 5
BINO A 1 A_Refire
goto ZoomedReady
Spawn:
BINP A -1
Stop
}
}
actor ZoomerBinos : Inventory
{
inventory.maxamount 7
}
actor UnZoomerBinos : Inventory
{
inventory.maxamount 1
}Re: Incremental weapon Zooming?
OK, so I've tweaked it a bit and put it in an actual weapon. It seems to work quite well but I'd still welcome any comments for improvement:
One thing I'd quite like to improve, but I'm not sure of the best way to do it, is this:
If you have been zoomed in then press and hold alt-fire, the weapon waits until you have released alt-fire before it unzooms. Removing the A_Refire from the Zoom0 state makes it so the weapon goes to an unzoomed condition much more quickly, but the problem is that if the alt-fire button is still held down, it then immediately goes back into a cycle of zooming and unzooming (making it difficult to actually unzoom and stay unzoomed). I know that it can be improved, I'm just not sure of the best way to do it. I used to have the A_ZoomFactor(1.0) before the A_Refire but that was less satisfying than the way it is now.
Code: Select all
states
{
Ready:
TNT1 A 0 A_JumpIfInventory (ZoomerRail, 1, "ReadyInvis")
PLSG A 1 A_WeaponReady
Goto Ready
ReadyInvis:
BINO B 0 A_GiveInventory ("UnZoomerRail", 1)
BINO B 1 A_WeaponReady(1)
Goto Ready
Deselect:
TNT1 A 0 A_TakeInventory ("ZoomerRail", 10)
TNT1 A 0 A_TakeInventory ("UnZoomerRail", 10)
TNT1 A 0 A_ZoomFactor(1.0)
PLSG A 0 A_PlayWeaponSound("weapons/weaponlower0")
PLSG A 0 A_Lower
PLSG A 1 A_Lower
Goto Deselect +4
//loop
Select:
TNT1 A 0 A_SetCrosshair (14)
PLSG A 0 A_PlayWeaponSound("weapons/weaponraise9")
PLSG A 0 A_Raise
PLSG A 1 A_Raise
Goto Select +2
//loop
Fire:
TNT1 A 0 A_JumpIfInventory (ZoomerRail, 1, "FireInvis1")
PLSG B 4 A_FireCustomMissile("MonsterAlerter",0,0,0,0)
PLSG B 0 A_GunFlash
PLSG B 0 A_FireCustomMissile("BlueFlash",0,0,0,0)
PLSG B 44 A_RailAttack(100,0,1,"68 B1 CC", "FF FF FF", 0, 0, "NJBluePuff2" )
PLSG A 1 A_FireCustomMissile("RailgunCaseSpawn",0,0,2,-2)
PLSG A 3
PLSG A 0 A_ReFire
goto Ready
FireInvis1:
BINO B 4 A_FireCustomMissile("MonsterAlerter",0,0,0,0)
BINO B 0 A_GunFlash
BINO B 0 A_FireCustomMissile("BlueFlash",0,0,0,0)
BINO B 44 A_RailAttack(100,0,1,"68 B1 CC", "FF FF FF", 0, 0, "NJBluePuff2" )
BINO B 1 A_FireCustomMissile("RailgunCaseSpawn",0,0,2,-2)
BINO B 3
BINO B 0 A_ReFire
goto Ready
AltFire:
BINO B 0 A_JumpIfInventory("UnZoomerRail", 1, "Zoom0") //go to unzooming function
BINO B 0 A_GiveInventory ("ZoomerRail", 1) //whatever happens now, we are zooming
BINO B 0 A_JumpIfInventory("ZoomerRail", 7, "Zoom8")
BINO B 0 A_JumpIfInventory("ZoomerRail", 6, "Zoom7")
BINO B 0 A_JumpIfInventory("ZoomerRail", 5, "Zoom6")
BINO B 0 A_JumpIfInventory("ZoomerRail", 4, "Zoom5")
BINO B 0 A_JumpIfInventory("ZoomerRail", 3, "Zoom4")
BINO B 0 A_JumpIfInventory("ZoomerRail", 2, "Zoom3")
BINO B 0 A_JumpIfInventory("ZoomerRail", 1, "Zoom2")
BINO B 4
BINO B 1 A_Refire
goto Ready
Zoom0:
BINO B 4
BINO B 1 A_Refire
BINO B 0 A_PlaySound ("Scope") //make a sound
BINO B 0 A_TakeInventory ("UnZoomerRail", 10)
BINO B 0 A_TakeInventory ("ZoomerRail", 10)
BINO B 0 A_SetCrosshair (14)
BINO B 0 A_ZoomFactor(1.0)
goto Ready
Zoom2:
BINO B 0 A_PlaySound ("Scope") //make a sound
BINO B 0 A_SetCrosshair (72)
BINO B 0 A_ZoomFactor(2.0)
BINO B 2
BINO B 1 A_Refire
goto ReadyInvis
Zoom3:
BINO B 0 A_SetCrosshair (73)
BINO B 0 A_ZoomFactor(3.0)
BINO B 2
BINO B 1 A_Refire
goto ReadyInvis
Zoom4:
BINO B 0 A_SetCrosshair (74)
BINO B 0 A_ZoomFactor(4.0)
BINO B 2
BINO B 1 A_Refire
goto ReadyInvis
Zoom5:
BINO B 0 A_SetCrosshair (75)
BINO B 0 A_ZoomFactor(5.0)
BINO B 2
BINO B 1 A_Refire
goto ReadyInvis
Zoom6:
BINO B 0 A_SetCrosshair (76)
BINO B 0 A_ZoomFactor(6.0)
BINO B 2
BINO B 1 A_Refire
goto ReadyInvis
Zoom7:
BINO B 0 A_SetCrosshair (77)
BINO B 0 A_ZoomFactor(7.0)
BINO B 2
BINO B 1 A_Refire
goto ReadyInvis
Zoom8:
BINO B 0 A_SetCrosshair (78)
BINO B 0 A_ZoomFactor(8.0)
BINO B 2
BINO B 1 A_Refire
goto ReadyInvis
Flash:
TNT1 A 0 A_JumpIfInventory (ZoomerRail, 1, "FlashInvis")
PLSF A 3 bright A_Light1
PLSF B 2 bright A_Light2
PLSF B 1 bright A_Light0
stop
FlashInvis:
TNT1 A 3 bright A_Light1
TNT1 B 2 bright A_Light2
TNT1 B 1 bright A_Light0
stop
Spawn:
PLAS A -1
stop
}If you have been zoomed in then press and hold alt-fire, the weapon waits until you have released alt-fire before it unzooms. Removing the A_Refire from the Zoom0 state makes it so the weapon goes to an unzoomed condition much more quickly, but the problem is that if the alt-fire button is still held down, it then immediately goes back into a cycle of zooming and unzooming (making it difficult to actually unzoom and stay unzoomed). I know that it can be improved, I'm just not sure of the best way to do it. I used to have the A_ZoomFactor(1.0) before the A_Refire but that was less satisfying than the way it is now.
- DBThanatos
- Posts: 3101
- Joined: Fri Apr 14, 2006 3:17 pm
- Location: in "the darkness that lurks in our mind"
Re: Incremental weapon Zooming?
I just tested it, and for now, a quick solution is that you remove the A_ReFire from Zoom0 and add to the weapon definition the "NOAUTOFIRE" flag. Any fire sequence that has A_ReFire will still auto-fire when the button is held (primary fire, and primary "invisible"), but any that doesnt have said action function wont repeat if the button is held (alt fire after reaching Zoom0). I know my explanations are bad, but I guess the result is what counts 
EDIT: Here is the code I used
EDIT: Here is the code I used
Code: Select all
Actor Thinggg : Weapon
{
+NOAUTOFIRE
Scale 1.0
Inventory.PickupMessage "You got a thinggg!"
Obituary "%o was destroyed by %k's thinggg."
states
{
Ready:
TNT1 A 0 A_JumpIfInventory (ZoomerRail, 1, "ReadyInvis")
PLSG A 1 A_WeaponReady
Goto Ready
ReadyInvis:
BINO B 0 A_GiveInventory ("UnZoomerRail", 1)
BINO B 1 A_WeaponReady(1)
Goto Ready
Deselect:
TNT1 A 0 A_TakeInventory ("ZoomerRail", 10)
TNT1 A 0 A_TakeInventory ("UnZoomerRail", 10)
TNT1 A 0 A_ZoomFactor(1.0)
PLSG A 0 A_PlayWeaponSound("weapons/weaponlower0")
PLSG A 0 A_Lower
PLSG A 1 A_Lower
Goto Deselect +4
//loop
Select:
TNT1 A 0 A_SetCrosshair (14)
PLSG A 0 A_PlayWeaponSound("weapons/weaponraise9")
PLSG A 0 A_Raise
PLSG A 1 A_Raise
Goto Select +2
//loop
Fire:
TNT1 A 0 A_JumpIfInventory (ZoomerRail, 1, "FireInvis1")
PLSG B 4 A_FireCustomMissile("MonsterAlerter",0,0,0,0)
PLSG B 0 A_GunFlash
PLSG B 0 A_FireCustomMissile("BlueFlash",0,0,0,0)
PLSG B 44 A_RailAttack(100,0,1,"68 B1 CC", "FF FF FF", 0, 0, "NJBluePuff2" )
PLSG A 1 A_FireCustomMissile("RailgunCaseSpawn",0,0,2,-2)
PLSG A 3
PLSG A 0 //A_ReFire
goto Ready
FireInvis1:
BINO B 4 A_FireCustomMissile("MonsterAlerter",0,0,0,0)
BINO B 0 A_GunFlash
BINO B 0 A_FireCustomMissile("BlueFlash",0,0,0,0)
BINO B 44 A_RailAttack(100,0,1,"68 B1 CC", "FF FF FF", 0, 0, "NJBluePuff2" )
BINO B 1 A_FireCustomMissile("RailgunCaseSpawn",0,0,2,-2)
BINO B 3
BINO B 0 A_ReFire
goto Ready
AltFire:
BINO B 0 A_JumpIfInventory("UnZoomerRail", 1, "Zoom0") //go to unzooming function
BINO B 0 A_GiveInventory ("ZoomerRail", 1) //whatever happens now, we are zooming
BINO B 0 A_JumpIfInventory("ZoomerRail", 7, "Zoom8")
BINO B 0 A_JumpIfInventory("ZoomerRail", 6, "Zoom7")
BINO B 0 A_JumpIfInventory("ZoomerRail", 5, "Zoom6")
BINO B 0 A_JumpIfInventory("ZoomerRail", 4, "Zoom5")
BINO B 0 A_JumpIfInventory("ZoomerRail", 3, "Zoom4")
BINO B 0 A_JumpIfInventory("ZoomerRail", 2, "Zoom3")
BINO B 0 A_JumpIfInventory("ZoomerRail", 1, "Zoom2")
BINO B 4
BINO B 1 A_Refire
goto Ready
Zoom0:
BINO B 4
BINO B 1 //A_Refire
BINO B 0 A_PlaySound ("Scope") //make a sound
BINO B 0 A_TakeInventory ("UnZoomerRail", 10)
BINO B 0 A_TakeInventory ("ZoomerRail", 10)
BINO B 0 A_SetCrosshair (14)
BINO B 0 A_ZoomFactor(1.0)
goto Ready
Zoom2:
BINO B 0 A_PlaySound ("Scope") //make a sound
BINO B 0 A_SetCrosshair (72)
BINO B 0 A_ZoomFactor(2.0)
BINO B 2
BINO B 1 A_Refire
goto ReadyInvis
Zoom3:
BINO B 0 A_SetCrosshair (73)
BINO B 0 A_ZoomFactor(3.0)
BINO B 2
BINO B 1 A_Refire
goto ReadyInvis
Zoom4:
BINO B 0 A_SetCrosshair (74)
BINO B 0 A_ZoomFactor(4.0)
BINO B 2
BINO B 1 A_Refire
goto ReadyInvis
Zoom5:
BINO B 0 A_SetCrosshair (75)
BINO B 0 A_ZoomFactor(5.0)
BINO B 2
BINO B 1 A_Refire
goto ReadyInvis
Zoom6:
BINO B 0 A_SetCrosshair (76)
BINO B 0 A_ZoomFactor(6.0)
BINO B 2
BINO B 1 A_Refire
goto ReadyInvis
Zoom7:
BINO B 0 A_SetCrosshair (77)
BINO B 0 A_ZoomFactor(7.0)
BINO B 2
BINO B 1 A_Refire
goto ReadyInvis
Zoom8:
BINO B 0 A_SetCrosshair (78)
BINO B 0 A_ZoomFactor(8.0)
BINO B 2
BINO B 1 A_Refire
goto ReadyInvis
Flash:
TNT1 A 0 A_JumpIfInventory (ZoomerRail, 1, "FlashInvis")
PLSF A 3 bright A_Light1
PLSF B 2 bright A_Light2
PLSF B 1 bright A_Light0
stop
FlashInvis:
TNT1 A 3 bright A_Light1
TNT1 B 2 bright A_Light2
TNT1 B 1 bright A_Light0
stop
Spawn:
PLAS A -1
stop
}
}
Actor UnZoomerRail : Inventory
{ Inventory.MaxAmount 1 }
Actor ZoomerRail : Inventory
{ Inventory.MaxAmount 8 }
Re: Incremental weapon Zooming?
That sounds nice and simple. I'll check it when I get home. I thought that noautofire was for something else entirely so it just shows what I know. Mind you, I hadn't even remembered about it until you mentioned it so I probably would never have even thought about trying it. Thanks.
Re: Incremental weapon Zooming?
Works like a charm. Brilliant!
Thanks.
Thanks.
