"How do I 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!)
Locked
D2JK
Posts: 543
Joined: Sat Aug 30, 2014 8:21 am

Re: "How do I ZScript?"

Post by D2JK »

Is it possible to use the BlockingMobj pointer in the A_Warp function somehow? If I try using it directly, eg. A_Warp(BlockingMobj); , I get an error saying a numeric type is expected. Same with A_Warp(GetPointer(BlockingMobj));.

I'm asking because I was wondering if I can now replace the old +HITMASTER/TARGET/TRACER flags.
ZippeyKeys12
Posts: 111
Joined: Wed Jun 15, 2016 2:49 pm

Re: "How do I ZScript?"

Post by ZippeyKeys12 »

Is it preferable to put all player processing* into an EventHandler or simply into the player's Tick().

*It's for reading player input for a stamina bar

EDIT: Is it possible to have custom actor properties store their values in a struct?
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
Contact:

Re: "How do I ZScript?"

Post by Matt »

D2JK: The pointer is not going to be the same sort of pointer A_Warp is looking for. Is there any reason why you have to use A_Warp and not SetOrigin?

ZippeyKeys: If you're just reading input from a player, it seems like you could just have the checks take place in the status bar itself. (I don't know how status bars work but if you can check a custom variable in a playerpawn then surely players.mo.getplayerinput() should work as well).
D2JK
Posts: 543
Joined: Sat Aug 30, 2014 8:21 am

Re: "How do I ZScript?"

Post by D2JK »

"Is there any reason why you have to use A_Warp and not SetOrigin?"

I think A_Warp is easier to work with when you need a relative position/angle. Plus, I think SetOrigin does not interpolate? I could be wrong though.
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 »

SetOrigin has a second argument where you can set whether you want interpolation on or off.
D2JK
Posts: 543
Joined: Sat Aug 30, 2014 8:21 am

Re: "How do I ZScript?"

Post by D2JK »

Gah. For some reason I always assumed the "moving" argument meant whether to keep existing velocities after the move, or to nullify them.
User avatar
Caligari87
Admin
Posts: 6174
Joined: Thu Feb 26, 2004 3:02 pm
Preferred Pronouns: He/Him
Contact:

Re: "How do I ZScript?"

Post by Caligari87 »

Is there any way to check if a way to check if a certain sound is playing? My weapon has some "automatic" sound functions (slide movement) and I don't want to play them if the gunshot sound is already playing, sounds weird.

Alternatively, any way to NOT play a sound if the channel is occupied, instead of overriding it? Seems like that could be a useful flag for A_Playsound().

8-)
ZippeyKeys12
Posts: 111
Joined: Wed Jun 15, 2016 2:49 pm

Re: "How do I ZScript?"

Post by ZippeyKeys12 »

Vaecrius wrote:ZippeyKeys: If you're just reading input from a player, it seems like you could just have the checks take place in the status bar itself. (I don't know how status bars work but if you can check a custom variable in a playerpawn then surely players.mo.getplayerinput() should work as well).

Thanks, I was just wondering if there was a best practice;

EDIT: Spelling, rip;
User avatar
coldcite
Posts: 13
Joined: Sat May 20, 2017 1:59 pm

Re: "How do I ZScript?"

Post by coldcite »

Is there any way I can possibly get an actor's current "sprite texture"?
I'm trying to obtain its real "height" so to speak, as in, an Arch-Vile has a set Height of 56, however its sprites can go up to 76 in some cases, that's the value I'm after.

Consider the following code in the Tick() override for an actor:

Code: Select all

			TextureID SpriteTexture = TexMan.CheckForTexture("VILEA1D1", TexMan.TYPE_Any);
			Int SpriteTexHeight = TexMan.CheckRealHeight(SpriteTexture);
It works alright and returns the proper height for "VILEA1D1" (76), but I couldn't find a way to get whichever the actor is using at that exact moment.
Is there perhaps another (easier) way to accomplish this and I'm over-complicating things?
ZzZombo
Posts: 315
Joined: Mon Jul 16, 2012 2:02 am

Re: "How do I ZScript?"

Post by ZzZombo »

Actor's current state holds it IIRC.
D2JK
Posts: 543
Joined: Sat Aug 30, 2014 8:21 am

Re: "How do I ZScript?"

Post by D2JK »

I have some weapons that are throwable, and won't give more ammo when picked up again. Currently, I do this by setting "AmmoGive" to zero in the actual weapon pickup, and then creating a custom pickup which gives both the weapon and the supposedly included ammo.

But I was wondering: is it possible to customize the ammo give property in a spawned weapon pickup somehow, such as:

Code: Select all

A_SpawnItemEx("Shotgun", flags: SXF_ISTRACER);
if (tracer)
 tracer.<?CODE?> = X;
tracer.ammogive or tracer.weapon.ammogive didn't seem to work.

I also cannot do Class EmptyShotgun : Shotgun { Default { Weapon.AmmoGive 0; } }, because this class would become a new weapon.
User avatar
coldcite
Posts: 13
Joined: Sat May 20, 2017 1:59 pm

Re: "How do I ZScript?"

Post by coldcite »

ZzZombo wrote:Actor's current state holds it IIRC.
Thank you so much!
You pointed exactly in the right direction, here's what I ended up with:

Code: Select all

			Int SpriteTexHeight;
			TextureID SpriteTexture; Bool SpriteFlip; Vector2 SpriteScale;
			[SpriteTexture, SpriteFlip, SpriteScale] = ownerRef.CurState.GetSpriteTexture(ownerRef.SpriteRotation);
			SpriteTexHeight = TexMan.CheckRealHeight(SpriteTexture);
ZzZombo
Posts: 315
Joined: Mon Jul 16, 2012 2:02 am

Re: "How do I ZScript?"

Post by ZzZombo »

No problem. @D2JK, you have to cast the actor in question to the appropriate type, i. e. Weapon in this case. Then you'll be able to access weapon-specific fields.
D2JK
Posts: 543
Joined: Sat Aug 30, 2014 8:21 am

Re: "How do I ZScript?"

Post by D2JK »

Ah, so casting again then. Thanks, I'll try that.
User avatar
coldcite
Posts: 13
Joined: Sat May 20, 2017 1:59 pm

Re: "How do I ZScript?"

Post by coldcite »

It has come to my attention something is wrong when using SetOrigin in actors on top of player activated elevators: actor's Pos.Z will be set to the platform floor no matter what.
Seems to work okay when the platform's raising/lowering is activated automatically, with no player interaction.
(Sorry if my wording is not clear enough, I'll try recording some footage showing this strange behavior)
Locked

Return to “Scripting”