"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
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 »

You can assign a string which gets converted according to the general color naming logic, any integer number and through color() either RGB or ARGB.
You can also access the single color channels with .a, .r, .g and .b.
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 »

Aha. Found this in strife statusbar, and was ninja-chucked.

Code: Select all

		Color green1 = Color(255, 180, 228, 128);	// light green
		Color green2 = Color(255, 128, 180, 80);	// dark green

		Color blue1 = Color(255, 196, 204, 252);	// light blue
		Color blue2 = Color(255, 148, 152, 200);	// dark blue

		Color gold1 = Color(255, 224, 188, 0);	// light gold
		Color gold2 = Color(255, 208, 128, 0);	// dark gold

		Color red1 = Color(255, 216, 44,  44);	// light red
		Color red2 = Color(255, 172, 28,  28);	// dark red
Oh, so we can do this as well?

Code: Select all

 Color test = Color(128, 256, 92);
and that translates to using just RGB?
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 »

Yes. But keep in mind that some code needs a non-0 alpha to work, but the 3 value constructor must set alpha to 0 for historic reasons.
User avatar
Death Egg
Posts: 198
Joined: Tue Aug 14, 2012 10:16 pm

Re: "How do I ZScript?"

Post by Death Egg »

I'm trying to convert the code here to ZScript but I'm stuck on this bit:

Code: Select all

else xsp -= minimum(absolute(xsp), frc)*sign(xsp);
Here's my current converted version:

Code: Select all

else vx -= min(abs(vx), PLAYER_MOVE_SPEED)*sgn(vx);
What would the equivalent for sign be in ZScript? And did I convert minimum and absolute correctly? Only 'sgn' gives me an error so far.
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 »

In this case the best thing is to use clamp:

vx -= clamp(vx, -PLAYER_MOVE_SPEED, PLAYER_MOVE_SPEED);
User avatar
ZZYZX
 
 
Posts: 1384
Joined: Sun Oct 14, 2012 1:43 am
Location: Ukraine

Re: "How do I ZScript?"

Post by ZZYZX »

Sign is usually something like this: (v>=0?1:-1)
Sometimes 0 also returns 0. Not sure what's intended in this particular case.

And yes, clamp works best.
User avatar
Beed28
Posts: 598
Joined: Sun Feb 24, 2013 4:07 pm
Location: United Kingdom

Re: "How do I ZScript?"

Post by Beed28 »

I am trying to use an EventHandler to spawn an actor when a map is loaded. Like here, for example:

Code: Select all

class MyHandler : EventHandler
{
	override void WorldLoaded(WorldEvent e)
	{
		Spawn("ActorIwantToSpawn", pos, NO_REPLACE);
	}
}
I just cannot get it to work, at all. Every time I try to, GZDoom crashes with "Call to unknown function 'Spawn'". There's literally nothing on the wiki and there's literally no examples floating about that I could find.
User avatar
Ed the Bat
Posts: 3060
Joined: Thu May 03, 2012 1:18 pm
Graphics Processor: nVidia with Vulkan support
Location: Maryland, US

Re: "How do I ZScript?"

Post by Ed the Bat »

User avatar
Beed28
Posts: 598
Joined: Sun Feb 24, 2013 4:07 pm
Location: United Kingdom

Re: "How do I ZScript?"

Post by Beed28 »

Got it to work. Here's what I used:

Code: Select all

Actor.Spawn("ActorIWantToSpawn", (0,0,0), NO_REPLACE);
Cheers.
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 »

How do you change an actor's decal?

EDIT: Better off using [wiki]A_SprayDecal[/wiki] instead...
Last edited by Matt on Mon Apr 03, 2017 11:59 am, edited 1 time in total.
User avatar
DenisBelmondo
Posts: 381
Joined: Fri Jun 06, 2008 6:26 pm
Location: Two-Key Return

Re: "How do I ZScript?"

Post by DenisBelmondo »

DenisBelmondo wrote:

Code: Select all

class GibsHandler : EventHandler
{
	override void WorldThingDamaged(WorldEvent e) // WorldThingDamaged works but not WorldThingDied
	{
		if ( e.thing.bIsMonster && !e.thing.bNoBlood && e.thing.InStateSequence(e.thing.CurState, e.thing.ResolveState("XDeath")) ) {
			e.thing.A_SpawnItemEx("GibsHack");
		}
	}
}
With this code, actors like demons and cacodemons spawn the "GibsHack" actor which, as you probably could imagine, looks really bizarre.
I figured I should probably post this here for the benefit of myself and others. There is an extra parameter for e.thing.FindState which I used in place of e.thingResolveState in this context that makes the function search for the state label explicitly rather than approximating it when it can't be found. Here's lines 235 - 250 (at the time of writing) in p_states.cpp of the *zdoom source code:
Spoiler:
With this knowledge, my code now looks like:
Spoiler:
and everything works as intended. Non-XDeath'ing actors don't spawn the GibsHack actor.
User avatar
zrrion the insect
Posts: 2432
Joined: Thu Jun 25, 2009 1:58 pm
Location: Time Station 1: Moon of Glendale

Re: "How do I ZScript?"

Post by zrrion the insect »

Is there a way to change what happens when the player presses the move/jump/crouch keys instead of disabling everything and reimplementing it a different way?
User avatar
JPL
 
 
Posts: 523
Joined: Mon Apr 09, 2012 12:27 pm

Re: "How do I ZScript?"

Post by JPL »

I'm new to ZScript and would like something similar to what I asked the pre-ZScript world last July, trying to figure stuff out on the wiki/docs. To be more specific than I was in that post, here's what I'm after:

- Actor that runs an ACS script when player gets within a radius of it.
- Radius and two string properties are defined per-instance.
- Actor passes the two string properties on to ACS.
- Assume UDMF and zero compat requirements, ie this is a new level-centric mod.
- Doesn't have to work at all in multiplayer.

The (really neat) DECORATE thing that ZZYZX wrote for me in that post from last year used the trick of giving a CustomInventory, but it seems like those sorts of hacks are a thing of the past now. I'm happy to learn and R&D this myself, so if nothing else I'm looking for advice on general approaches.
User avatar
Nash
 
 
Posts: 17508
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

Re: "How do I ZScript?"

Post by Nash »

JPL - can you summarize what exactly was it you were trying to achieve? It looks like a lot of those steps were just workaround-cruft that are unnecessary now and can be skipped, but I'd need a better idea first of what you actually want to make. Based on the limited understanding I have of it now (you just want something to activate when in proximity) I do know for a fact that it's quite simple to do with ZScript... just need more info.
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 »

> Radius and two string properties are defined per-instance.

Code: Select all

override void PostBeginPlay(){
 super.PostBeginPlay();
 A_SetSize(...)
 blahblahblah="Blah blah blah!";
}
> Actor that runs an ACS script when player gets within a radius of it.
Can you elaborate on this? Should it just play once, or every tic that the player is within, and are we talking about the actor's own hitbox radius or with an arbitrary (and perhaps circular) area?

> Actor passes the two string properties on to ACS.
I suspect the following would be applicable:
Vaecrius wrote:is it possible to access an actor-defined variable in ACS somehow?
Graf Zahl wrote:No. The main problem being that ACS has no concept of actors. If you need interaction you should do the bulk of the work in ZScript and then use ScriptCall for interfacing.

(but yes what Nash said. It may be much simpler to re-think the desired end result and rewrite the whole thing.)


zrrion the insect wrote:Is there a way to change what happens when the player presses the move/jump/crouch keys instead of disabling everything and reimplementing it a different way?
What kind of change are you trying for? I can't think of any meaningful qualitative change that would not have to be "reimplemented".

Return to “Scripting”