"How do I ZScript?"

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!
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
Gutawer
Posts: 469
Joined: Sat Apr 16, 2016 6:01 am
Preferred Pronouns: She/Her

Re: "How do I ZScript?"

Post by Gutawer »

That means it's in a ZDoom dev version (and forever will be, with ZDoom's death), GZDoom has had it in stable for a while now.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49252
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: "How do I ZScript?"

Post by Graf Zahl »

The Wiki is a bit behind, it still lists ZDoom 2.8.1 as the baseline.
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia

Re: "How do I ZScript?"

Post by Matt »

sonic_HD87 wrote:It doesn't matter if it says "development version only"?
For future reference, if in doubt, click on the number to get to the changelog post, and check the date, and compare it to the date of the latest GZDoom release.
User avatar
krokots
Posts: 296
Joined: Tue Jan 19, 2010 5:07 pm

Re: "How do I ZScript?"

Post by krokots »

How can I easily check current state of an actor? ACS have "CheckActorState", but I didn't find anything in ZScript or Decorate.
User avatar
Gutawer
Posts: 469
Joined: Sat Apr 16, 2016 6:01 am
Preferred Pronouns: She/Her

Re: "How do I ZScript?"

Post by Gutawer »

krokots wrote:How can I easily check current state of an actor? ACS have "CheckActorState", but I didn't find anything in ZScript or Decorate.

Code: Select all

if (CurState == ResolveState("See")) {
    // ...
}
To get other actors' states, you can use pointers as always.
User avatar
krokots
Posts: 296
Joined: Tue Jan 19, 2010 5:07 pm

Re: "How do I ZScript?"

Post by krokots »

Gutawer wrote:
krokots wrote:How can I easily check current state of an actor? ACS have "CheckActorState", but I didn't find anything in ZScript or Decorate.

Code: Select all

if (CurState == ResolveState("See")) {
    // ...
}
To get other actors' states, you can use pointers as always.
Thanks, exactly what I needed.

Actually, there seems to be some problems with this method.

Making a blind spell, which set monster state to "blinded" on it's spawn state, and then on active state it checks if the monster is still on "blinded" state.
The spell's target is the monster.

Code: Select all

		Spawn:
			S010 A 0 NoDelay 
			{
				A_PlaySound ("Spells/Blind"); 
				target.setStateLabel("Blinded");
				if(target.curState==target.resolveState("Blinded"))
				{
					A_Log("Target is blinded");
				}
			}
		Active:
			TNT1 A 0 
			{
				if(target.CurState != target.ResolveState("Blinded"))
				{
					A_Log("Not blinded anymore");
					return ResolveState("Null");
				}
				return ResolveState("Active");
			}
Unfortunately, on the second loop it goes through the check (as if the target's state is not "Blinded").
Fortunately tho, I found (in this thread) another method which works:

Code: Select all

 if(!(inStateSequence(target.Curstate, target.resolvestate("Blinded"))))
I don't know why this works and other does not.
User avatar
Accensus
Banned User
Posts: 2383
Joined: Thu Feb 11, 2016 9:59 am

Re: "How do I ZScript?"

Post by Accensus »

How to GetUDMF*** in ZScript? I mean, what are the parameters? GetUDMF***("SomeCustomUDMFValueNameHere"); ?
User avatar
Arctangent
Posts: 1235
Joined: Thu Nov 06, 2014 1:53 pm

Re: "How do I ZScript?"

Post by Arctangent »

So, I'm trying to think out how to do a third person thing, preferably using ZScript, and one thing I want to do is to make the player move in the direction they're moving while keeping the camera always pointed in the way they're aiming - with extra points if the player has a turn speed, as what I'm planning would have typical attack animations long enough for such turning to only give a minor amount of "circling" when going from moving 180 degrees and otherwise just be a nice visual effect.

Issue is, of course, is making it so that the player - the one getting the actual turn inputs - doesn't have their angle be immediately affected, but the camera instead. I figure one way to do it might be making the camera the player with the actual body being a true pawn, but I dunno how I feel about how proper that is, especially considering that would mean shoving +NOINTERACTION on a player.

Also, not quite ZScript related, but what's a good camera angle for a shooting thing, anyway? Over-the-shoulder is a natural choice, but that has the issue of having projectiles not actually follow the crosshair over long distances. As far as behind-the-back goes, I've had issues making sure that the crosshair can actually be in the center of the screen without the player's body blocking it.
User avatar
Gutawer
Posts: 469
Joined: Sat Apr 16, 2016 6:01 am
Preferred Pronouns: She/Her

Re: "How do I ZScript?"

Post by Gutawer »

RE: which camera angle to use (can't help with the first part, sorry) -
With over-the-shoulder, presuming you can get the view angle & pitch of the camera (hopefully possible, depending on how you implement the camera), you can then use LineAttack to do a raytracer (as described by Nash a page back) and determine where the player is actually aiming. From there, you can use trigonometry to offset projectiles & hitscans so they hit where the player is actually aiming. That will make attacks follow the crosshair even in over-the shoulder.
User avatar
Major Cooke
Posts: 8218
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: GZBoomer Town

Re: "How do I ZScript?"

Post by Major Cooke »

Arctangent: We'll talk on Discord.
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia

Re: "How do I ZScript?"

Post by Matt »

What does "exact" do in FindState?
User avatar
sonic_HD87
Posts: 287
Joined: Sat Mar 23, 2013 4:32 pm
Location: Venezuela

Re: "How do I ZScript?"

Post by sonic_HD87 »

krokots wrote:Fortunately tho, I found (in this thread) another method which works:

Code: Select all

 if(!(inStateSequence(target.Curstate, target.resolvestate("Blinded"))))
I don't know why this works and other does not.
It seems that InStateSequence is used to check if an actor's state (arg1) matches the given state (arg2), since is a bool function. I think that using target.CurState == Target.ResolveState("Blind") is doing something else.

And if i got it wrong, well that's good since there's no documentation for those functions.
User avatar
Nash
 
 
Posts: 17510
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

Re: "How do I ZScript?"

Post by Nash »

This is probably ultra basic and I'm just dumb but:

How do I normalize GetPlayerInput's INPUT_FORWARDMOVE and SIDEMOVE's output into range [-1.0, 1.0]? I mean, I want to use values between -1.0 to 1.0, not -/+10k++ or whatever it usually is.

EDIT: nvm got it

Code: Select all

            double input = GetPlayerInput(INPUT_SIDEMOVE);
            double normalizedInput = 1.f * input / 10240.;
 
User avatar
Major Cooke
Posts: 8218
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: GZBoomer Town

Re: "How do I ZScript?"

Post by Major Cooke »

Code: Select all

// Slowing down?
			if ((udirget & BT_SPEED) || uwings)		
			{	
				// Forwards or backwards?
				udirforward = GetPlayerInput(MODINPUT_FORWARDMOVE) / 6400.0;
				// Left or right?
				udirside = -GetPlayerInput(MODINPUT_SIDEMOVE) / 6144.0;
			}
			else
			{
				// Forwards or backwards?
				udirforward = GetPlayerInput(MODINPUT_FORWARDMOVE) / 12800.0;
				// Left or right?
				udirside = -GetPlayerInput(MODINPUT_SIDEMOVE)  / 10240.0;
			}
This is the values for all the movements in case you need it.
User avatar
krokots
Posts: 296
Joined: Tue Jan 19, 2010 5:07 pm

Re: "How do I ZScript?"

Post by krokots »

Is there any equivalent of PickActor on ZScript?

Return to “Scripting”