(zscript) how to get the player's FOV setting?

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!)
Post Reply
User avatar
StalkerBlade
Posts: 34
Joined: Wed Oct 17, 2018 10:55 pm

(zscript) how to get the player's FOV setting?

Post by StalkerBlade »

I've been trying to make a script that will slightly increase then decrease the fov similar to how it would look in a weapon's firing state. I'm trying to clamp the amount of fov to increase so it won't interfere with some other scripts, but I'm having issues with trying to either retrieve or store the player's own actual fov setting.

The script is activated with an inventory item that runs it when given, then removes itself from the player's inventory once it's done. I'm not sure if owner.player.desiredFOV and owner.player.FOV are the same thing, but they seem to give the same results as eachother and are just the updated in-game fov value from what I can tell.

Code: Select all

int counter;
int dfov;
int pfov;

	 override void DoEffect()
	{
	
	dfov = owner.player.desiredFOV;
	pfov = owner.player.FOV;
	 
		if (counter < 4)
		{
		pfov += 2;
		owner.player.setFOV(clamp(pfov, 0, dfov + 8));
		counter++;			
		}
			
		if (counter >= 4 && counter < 7)
		{
		pfov -= 2;
		owner.player.setFOV(clamp(pfov, 0, dfov + 8));
		counter++;	
		}
			
		if (counter == 8)
		{
        owner.RemoveInventory(self);
		} 	  
	 }
I'm still a bit new to zscript and coding in general, so I imagine there's probably a more elegant way of trying to do this than what I'm doing.. :?
User avatar
Player701
 
 
Posts: 1640
Joined: Wed May 13, 2009 3:15 am
Graphics Processor: nVidia with Vulkan support
Contact:

Re: (zscript) how to get the player's FOV setting?

Post by Player701 »

DesiredFOV represents the "target" FOV value, while FOV is the actual FOV currently being used. The game will try to smoothly adjust FOV to a multiple of DesiredFOV and FOVScale of the player's ready weapon. This is how A_ZoomFactor works: unless the ZOOM_INSTANT flag is used, it only changes FOVScale, and the rest of the adjustment is done gradually by player code. Thus, if you want a gradual change, change the value of DesiredFOV only, and if you want the change to be instant, change the value of both. But do keep in mind that this value can be overridden from the console at any time.

Note that SetFOV will not work if the "Allow FOV" gameplay option (DMFlag) is disabled; if you don't want that, simply assign to DesiredFOV directly.
User avatar
StalkerBlade
Posts: 34
Joined: Wed Oct 17, 2018 10:55 pm

Re: (zscript) how to get the player's FOV setting?

Post by StalkerBlade »

I see, that’ll help a good bit on how to properly use the values. One other problem I’m trying to prevent however is the fov “stacking” and not returning back to the players setting value. I’m going to have a similar script to this one that activates while standing on a specific texture and it will also affect the fov the same way; only this script will ‘hold’ the fov at a certain value until the player isn’t on the texture anymore.

I’m not sure if that value is exposed to zscript or not, but I may be able to work around it if it’s not retrievable.
User avatar
Player701
 
 
Posts: 1640
Joined: Wed May 13, 2009 3:15 am
Graphics Processor: nVidia with Vulkan support
Contact:

Re: (zscript) how to get the player's FOV setting?

Post by Player701 »

StalkerBlade wrote: Wed Mar 22, 2023 11:15 amOne other problem I’m trying to prevent however is the fov “stacking” and not returning back to the players setting value.
I could be wrong, but I don't think this can be done in a 100% foolproof way unless you're modifying the ready weapon's FOVScale - and since that's tied to the weapon, it could also be overridden if the weapon implements its own zoom via A_ZoomFactor or if the player changes weapons, and won't work outright if the player is not holding any weapon at all - which is a rare but not impossible scenario in custom mods. IMO, the best way to go would be to suggest a feature to implement FOVScale for arbitrary inventory items (as well as handle it in PlayerPawn). Basically, it'd work the same as GetBlend, where the total blend value is the product of all the values returned by each inventory item the player is holding.
User avatar
StalkerBlade
Posts: 34
Joined: Wed Oct 17, 2018 10:55 pm

Re: (zscript) how to get the player's FOV setting?

Post by StalkerBlade »

I think that would be a pretty useful feature, thanks for the help. Once I get some of my time straitened out I'll see if I can put a suggestion for it together.
Post Reply

Return to “Scripting”