I don't think A_Chase has been exported to script, so you can't really use it as a base.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?
"How do I ZScript?"
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!)
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!)
-
Kinsie
- Posts: 7402
- Joined: Fri Oct 22, 2004 9:22 am
- Graphics Processor: nVidia with Vulkan support
- Location: MAP33
Re: "How do I ZScript?"
-
ZZYZX
-

- Posts: 1384
- Joined: Sun Oct 14, 2012 1:43 am
- Location: Ukraine
Re: "How do I ZScript?"
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.
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.
-
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?"
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.
+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;
}
}-
Graf Zahl
- Lead GZDoom+Raze Developer

- Posts: 49252
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: "How do I ZScript?"
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
-
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?"
You can certainly 'reinvent' it using functions and the likes that it uses.Kinsie wrote:I don't think A_Chase has been exported to script, so you can't really use it as a base.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?
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);
}
-
Graf Zahl
- Lead GZDoom+Raze Developer

- Posts: 49252
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: "How do I ZScript?"
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.
-
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?"
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.
-
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?"
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.)
-
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?"
It's also missing float height adjustment, I just realized. Two things for me to work on then!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.
-
Gutawer
- Posts: 469
- Joined: Sat Apr 16, 2016 6:01 am
- Preferred Pronouns: She/Her
Re: "How do I ZScript?"
Is it possible to overload an operator inside a struct?
-
Graf Zahl
- Lead GZDoom+Raze Developer

- Posts: 49252
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: "How do I ZScript?"
No.
What do you want to do?
What do you want to do?
-
Gutawer
- Posts: 469
- Joined: Sat Apr 16, 2016 6:01 am
- Preferred Pronouns: She/Her
Re: "How do I ZScript?"
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?
EDIT: Also, is there a function/operator for raising a number to a power?
-
4thcharacter
- Banned User
- Posts: 1183
- Joined: Tue Jun 02, 2015 7:54 am
Re: "How do I ZScript?"
Alright, thanks. How about the other question? What are the other notable things ZScript can do?
-
Kinsie
- Posts: 7402
- Joined: Fri Oct 22, 2004 9:22 am
- Graphics Processor: nVidia with Vulkan support
- Location: MAP33
Re: "How do I ZScript?"
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).4thcharacter wrote:Alright, thanks. How about the other question? What are the other notable things ZScript can do?
Here it is in ZScript. Ta-da.
-
ZZYZX
-

- Posts: 1384
- Joined: Sun Oct 14, 2012 1:43 am
- Location: Ukraine
Re: "How do I ZScript?"
Mmm, 1138 line tada... I wouldn't use that to persuade people into using ZScript really. 