"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
User avatar
Kinsie
Posts: 7399
Joined: Fri Oct 22, 2004 9:22 am
Graphics Processor: nVidia with Vulkan support
Location: MAP33
Contact:

Re: "How do I ZScript?"

Post by Kinsie »

4thcharacter wrote:I've been really wanting to ask this. How powerful is ZScript? Is it able to manipulate the monsters' movements instead of them going straightly towards the player while walking on left to right a little and shoot from time to time?
I don't think A_Chase has been exported to script, so you can't really use it as a base.
User avatar
ZZYZX
 
 
Posts: 1384
Joined: Sun Oct 14, 2012 1:43 am
Location: Ukraine
Contact:

Re: "How do I ZScript?"

Post by ZZYZX »

You can write a replacement for A_Chase, it's fairly straightforward.
The problem is actually making decisions. From my tests naive approaches to astar (build WxHxZ grid, Z is needed because of 3D floors and cacodemons) cause epic lag both on level start and during chase, so there should be some algorithm to build a node list much like bot nodes. idk I'm too bad at things to do that.
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 »

Thus far I've been happy to just have monsters pursue an oblique point to flank the player and to avoid the most obvious threats that can be avoided. I don't even want to begin thinking about actual pathfinding.

+usespecial does nothing whether I enable it or not.

Code: Select all

class usetest:actor{
	default{
		+usespecial;
		+solid;
	}
	override bool used(actor user){
		A_Log("YAY");
		return false;
	}
	states{
	spawn:
		BEXP B -1;
		stop;
	}
}
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49066
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: "How do I ZScript?"

Post by Graf Zahl »

Nash wrote: Unfortunately the only way to draw things correctly is either through Menus or through a Powerup. If you try to draw from an actor, your text will flicker because the actor tick only runs at 35Hz.

To be more precise, you can only draw while the 2D screen is locked, otherwise you may get fatal errors with the software renderer. At the moment, the menu's Drawer function and the powerup overlay are the only pieces of code that get called in there but some more will come
User avatar
Major Cooke
Posts: 8175
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: "How do I ZScript?"

Post by Major Cooke »

Kinsie wrote:
4thcharacter wrote:I've been really wanting to ask this. How powerful is ZScript? Is it able to manipulate the monsters' movements instead of them going straightly towards the player while walking on left to right a little and shoot from time to time?
I don't think A_Chase has been exported to script, so you can't really use it as a base.
You can certainly 'reinvent' it using functions and the likes that it uses.

This example, from D4D, make monsters always run directly at their target if they can. Otherwise it performs the old A_Chase methods so it can at least navigate around obstacles and stuff that gets in the way.

Code: Select all

//--------------------------------------------------------------------------
//
// D4Chase(melee, missile, flags, max turn)
//
// A_Chase enhanced, + new parameter: Max turn.
// Specifies how much in degrees the monster should turn towards its target.
// -1 will not turn it.
//--------------------------------------------------------------------------
void D4Chase(statelabel melee = "Melee", statelabel missile = "Missile", int flags = 0, double maxturn = 30.0)
{
    int newflags = 0;
    if (GetCvar("D4D_EnhancedChase"))
    {
        if (!target || target.bKilled)
        {    A_Chase(null,null,CHF_DONTMOVE|CHF_DONTTURN|CHF_NODIRECTIONTURN|CHF_NORANDOMTURN|CHF_NOPOSTATTACKTURN);    }
        
        if (A_JumpIfTargetInLOS("Null",360,JLOSF_DEADNOJUMP))
        {
            double ang = angle;
            
            // MUST BE DEFINED IN THE ACTOR USING THIS FUNCTION. Or just replace it with a number/dump the if entirely.
            if (maxturn >= 0.0)
                A_FaceTarget(maxturn,0);
            Vector2 nmpos = Vec2Angle(speed,angle);
            
            // Since we can move straight forward to the target, disable all movement for A_Chase itself.
            // Keep the melee and missile states active, however.
            if (TryMove(nmpos, false))
            {
                newflags = CHF_DONTMOVE|CHF_DONTTURN|CHF_NODIRECTIONTURN|CHF_NOPOSTATTACKTURN;
            }
            else
            {
                angle = ang;
                newflags = 0;
            }
        }
    }
    // Since some flags may be specified ahead of time, combine them with the ones used in here.
    A_Chase(melee, missile, flags|newflags);
}
 
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49066
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: "How do I ZScript?"

Post by Graf Zahl »

Be careful with that! All normal movement splits up the move if the distance is too large, it may clip through walls if the distance between old and new pos is larger than the actor's radius. Of course if you know this cannot happen, there's nothing to worry.
User avatar
Ed the Bat
Posts: 3060
Joined: Thu May 03, 2012 1:18 pm
Graphics Processor: nVidia with Vulkan support
Location: Maryland, US
Contact:

Re: "How do I ZScript?"

Post by Ed the Bat »

I would really love to reinvent A_Chase so that movement is spaced evenly across the total distance, but my impression was that it couldn't be done, and all I could do was call A_Chase more frequently with smaller distances.
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 »

I can post what I've been trying to do so far. It's very hacky and you may need to set +nodropoff elsewhere for faster monsters. The idea is to call the standard movement, then on success reposition the actor back at its previous spot and add velocity moving it in that direction. Note that there aren't any calls to attack or heal states other than melee - those are in a separate function.
Spoiler:
("HDLib.CubeDist" is just a crude way of getting an approximate length of a vector without calling a square root. It returns the longest axis, but if needed also multiplies that number by a pre-defined square root of two if two axes are similar enough.)
User avatar
Major Cooke
Posts: 8175
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: "How do I ZScript?"

Post by Major Cooke »

Graf Zahl wrote:Be careful with that! All normal movement splits up the move if the distance is too large, it may clip through walls if the distance between old and new pos is larger than the actor's radius. Of course if you know this cannot happen, there's nothing to worry.
It's also missing float height adjustment, I just realized. Two things for me to work on then!
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 »

Is it possible to overload an operator inside a struct?
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49066
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: "How do I ZScript?"

Post by Graf Zahl »

No.
What do you want to do?
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 »

Creating a struct for complex numbers. I've got all the maths down and working, but you cannot use +-*/, instead member functions must be used which are a bit unwieldy.
EDIT: Also, is there a function/operator for raising a number to a power?
User avatar
4thcharacter
Posts: 1183
Joined: Tue Jun 02, 2015 7:54 am

Re: "How do I ZScript?"

Post by 4thcharacter »

Alright, thanks. How about the other question? What are the other notable things ZScript can do?
User avatar
Kinsie
Posts: 7399
Joined: Fri Oct 22, 2004 9:22 am
Graphics Processor: nVidia with Vulkan support
Location: MAP33
Contact:

Re: "How do I ZScript?"

Post by Kinsie »

4thcharacter wrote:Alright, thanks. How about the other question? What are the other notable things ZScript can do?
Try making the Heresiarch from Hexen in DECORATE. Stupid block tricks and all. (You can't, because a massive chunk of the Heresiarch's behavior pre-ZScript was hardcoded).

Here it is in ZScript. Ta-da.
User avatar
ZZYZX
 
 
Posts: 1384
Joined: Sun Oct 14, 2012 1:43 am
Location: Ukraine
Contact:

Re: "How do I ZScript?"

Post by ZZYZX »

Mmm, 1138 line tada... I wouldn't use that to persuade people into using ZScript really. :roll:
Locked

Return to “Scripting”