Problem with aiming

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.

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
Posts: 41
Joined: Fri Jun 09, 2017 4:06 am
Location: Land of salo, gorilka and borsch (a.k.a. Ukraine)

Problem with aiming

Post by DenTheUA »

So I am actually working on a project, and I've done a weapon with sights.

The problem is that when I press the altfire button first time, gun becames aimed, but when I press Altfire second time, it doesn't go to Ready state, but instead it flickers and stays aimed.

Here's my lump:
User avatar
Jekyll Grim Payne
Posts: 1012
Joined: Mon Jul 21, 2008 4:08 am
Preferred Pronouns: He/Him
Graphics Processor: nVidia (Modern GZDoom)

Re: Problem with aiming

Post by Jekyll Grim Payne »

Two things I can tell you right away. First, man, this formatting is really hard to read. Second, it's not a good idea to make the zooming state a 0-tic one (and in your case your zoom out state's length is 0). If you hold a button even for a bit, it'll zoom out, go into ready state and then right into zoom in state. Can't say anything else definite , but I threw together this and it works fine:

Code: Select all

actor PistolZoom : Pistol
Weapon.SlotNumber 2
			TNT1 A 0 A_JumpIfInventory("Zoomed",1,3)
			PISG A 5 A_ZoomFactor(3)
			TNT1 A 0 A_GiveInventory("Zoomed",1)
			goto ready
			TNT1 A 0 A_ZoomFactor(1)
			PISG A 5 A_TakeInventory("Zoomed",1)
			goto ready

Actor Zoomed : Inventory
	inventory.maxamount 1

Return to “Scripting”