Increasing friction with ZScript

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!)
EmperorGrieferus
Posts: 123
Joined: Wed May 31, 2017 5:39 am

Increasing friction with ZScript

Post by EmperorGrieferus »

Hi, I want to try myself in ZScript, and the first thing I want to do is simply translate this little ACS script.

Code: Select all

Script "Slip reduction" ENTER
 {
  while (1)
   {
	 SetActorProperty(0, APROP_Friction, 0.94);
	 if (GetPlayerInput(-1, INPUT_FORWARDMOVE)  ||  GetPlayerInput(-1, INPUT_SIDEMOVE))
     {
	   SetActorProperty(0, APROP_Friction, 1.0);
	  }
	 Delay(1);
   }
 }
It simply makes movement less slippery. Now, I know about NashMove mod, but I do believe there's more elegant way to do this.
Jarewill
 
 
Posts: 1807
Joined: Sun Jul 21, 2019 8:54 am

Re: Increasing friction with ZScript

Post by Jarewill »

There are two ways to do this.
First is to override Tick in your player class, this will make it only your-mod-specific:

Code: Select all

	Override void Tick(){
		Super.Tick();
		friction=0.94;
		If(player.cmd.forwardmove || player.cmd.sidemove){
			friction=1;
		}
	}
The other is to create a new item and do the same with in the item's DoEffect override:

Code: Select all

Class FrictionItem : Inventory{
	Override void DoEffect(){
		Super.DoEffect();
		//This time we will use the owner pointer.
		If(!owner || !owner.player){Destroy();}
		owner.friction=0.94;
		If(owner.player.cmd.forwardmove || owner.player.cmd.sidemove){
			owner.friction=1;
		}
	}
}
Now to automatically give this item to the player, you will want to use an event handler, like so:

Code: Select all

Class FrictionHandler : EventHandler{
	Override void PlayerEntered(PlayerEvent e){
		let playe = players[e.PlayerNumber].mo;
		If(!playe.FindInventory("FrictionItem")){playe.GiveInventory("FrictionItem",1);}
	}
}
Make sure to also include the event handler in MAPINFO:

Code: Select all

GameInfo{
	AddEventHandlers = "FrictionHandler"
}
EmperorGrieferus
Posts: 123
Joined: Wed May 31, 2017 5:39 am

Re: Increasing friction with ZScript

Post by EmperorGrieferus »

Thank you very much! I'm gonna test it!
I considered translating the ACS script to ZScript because of camera jerking concerns.
You see, when I shortly used earlier version of Nash's Q-Tilt, which was written in ACS, I'd always get camera jerking the second I'd start circlestrafing (I know it's because ACS is tickrate-dependant, but anyway).
And from Tilt++ promotional, the whole thing looks really smooth, so I decided, why not move it to ZScript, even though I'm pretty conservative, thus I think that majority of mods can be made with only Decorate and ACS.

Tl;dr, I know.
EmperorGrieferus
Posts: 123
Joined: Wed May 31, 2017 5:39 am

Re: Increasing friction with ZScript

Post by EmperorGrieferus »

So, about the first one.
Should it contain something else? Because when I tried to launch it, it failed because it couldn't find class.
The second one also failed, because it couldn't recognize the "owner.player.cmd.forwardmove/sidemove" part.
Jarewill
 
 
Posts: 1807
Joined: Sun Jul 21, 2019 8:54 am

Re: Increasing friction with ZScript

Post by Jarewill »

Oh right, you need to specify a ZScript version in the first line of the file, for example: version "4.0"

And regarding the first one, it needs to be within your player class, like:

Code: Select all

Class MyPlayer : DoomPlayer{
	//The code goes here
}
EmperorGrieferus
Posts: 123
Joined: Wed May 31, 2017 5:39 am

Re: Increasing friction with ZScript

Post by EmperorGrieferus »

Jarewill wrote: Wed Dec 27, 2023 2:03 pm Oh right, you need to specify a ZScript version in the first line of the file, for example: version "4.0"

And regarding the first one, it needs to be within your player class, like:

Code: Select all

Class MyPlayer : DoomPlayer{
	//The code goes here
}
That's the problem: I specified the version.
Maybe, it's because the version I use doesn't support this exact command. However, I can't find anything like this in wiki.
EmperorGrieferus
Posts: 123
Joined: Wed May 31, 2017 5:39 am

Re: Increasing friction with ZScript

Post by EmperorGrieferus »

So, after digging through Player_t, I've finally found the necessary natives. However, I don't really know what's the difference between Move1 and Move2.

UPD: Even these doesn't work. Maybe, I should try "GetPlayerInput", though I doubt.
EmperorGrieferus
Posts: 123
Joined: Wed May 31, 2017 5:39 am

Re: Increasing friction with ZScript

Post by EmperorGrieferus »

I decided to perform an experiment, and...
Let's just say that my hopes are ruined. GZDoom, Eternity and even Unity Port show a hardly noticeable stuttering when you turn and strafe at the same time, Crispy Doom smoothes it which looks even weirder, and only DSDA-Doom showed no sign of it (Perhaps, this is because of interpolation algorithm used by first four ports).
I request to close this topic and I apologize for any inconvenience. Jarewill, big Russian spasibo for tutorial. I'll consult with you in DMs.
User avatar
merlin86
Posts: 137
Joined: Tue Jan 29, 2008 4:02 am
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 11 Pro
Graphics Processor: nVidia with Vulkan support

Re: Increasing friction with ZScript

Post by merlin86 »

For the stuttering problem I've noticed the following things:
- prefer GSync if your gpu and monitor supports that
- always choose performance mode for your GPU / CPU
- Lock, if it's possible from the program, the fps in multiple of 35 fps and stay under the refresh rate of your monitor ( for example my monitor is 144 Hz so usually for me are 140 fps )
- Prefer the dxgi swap chain from your driver settings if your gpu supports that
- prefer vulkan instead of openGL if possible
- update the gpu drivers and install all the updates for your OS

I've followed those suggestions and I have a smooth experience in nugget doom and latest gzdoom.
EmperorGrieferus
Posts: 123
Joined: Wed May 31, 2017 5:39 am

Re: Increasing friction with ZScript

Post by EmperorGrieferus »

1) I will see if my GTX 1050 Ti has this
2) Yessir!
3) I've chosen 70 fps, since this was the framerate Doom was intended to play in
4) I couldn't find it in NVIDIA Control Panel. Details required!
5) Not possible. Besides, AFAIK implementation of Vulkan on NVIDIA devices is rather buggy
6) I'm on it, OS is updated
Last edited by EmperorGrieferus on Fri Dec 29, 2023 4:47 pm, edited 2 times in total.
User avatar
merlin86
Posts: 137
Joined: Tue Jan 29, 2008 4:02 am
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 11 Pro
Graphics Processor: nVidia with Vulkan support

Re: Increasing friction with ZScript

Post by merlin86 »

4) The one highlighted: https://i.imgur.com/o8A5roZ.png , if not present, it means your drivers are old or GTX series does not support the DXGI swapchain (maybe only on Windows 11 / 10 ? )
5) Yeah, I know that with my RTX 4070, April drivers had a lot of problems, December drivers look better for Vulkan
EmperorGrieferus
Posts: 123
Joined: Wed May 31, 2017 5:39 am

Re: Increasing friction with ZScript

Post by EmperorGrieferus »

As it turns out, my display doesn't support DP, which, idealistically, should support G-Sync.
If you need, my display is Philips PHL273V7QDS.

Return to “Scripting”