Spoiler:Code: Select all
//face a specified vector. NEGATIVE Z IS DOWN. //Lib.FaceVector(self,(-20,90,-10),10,10,true); static void FaceVector(actor self,vector3 v,double maxangle=0,double maxpitch=0,bool relative=false){ double nangle=atan2(v.y,v.x); vector2 v2=(v.x,v.y); double abshorz=v2.length(); double npitch=-atan2(v.z,abshorz); //cap angle double dangle=nangle-self.angle; if((abs(dangle)<360-maxangle)&&(abs(dangle)>maxangle)&&(maxangle>0)){ if(abs(dangle)>180) dangle-=360; dangle=clamp(dangle,-maxangle,maxangle); nangle=self.angle+dangle; } //cap pitch dangle=npitch-self.pitch; if((abs(dangle)>maxpitch)&&(maxpitch>0)){ dangle=clamp(dangle,-maxpitch,maxpitch); npitch=self.pitch+dangle; } //apply: add if relative, replace if not if(relative){ self.angle+=nangle; self.pitch+=npitch; }else{ self.angle=nangle; self.pitch=npitch; } }
ZScript "Standard Library" - Brainstorming
Forum rules
The Projects forums are only for projects. If you are asking questions about a project, either find that project's thread, or start a thread in the General section instead.
Got a cool project idea but nothing else? Put it in the project ideas thread instead!
Projects for any Doom-based engine (especially 3DGE) are perfectly acceptable here too.
Please read the full rules for more details.
The Projects forums are only for projects. If you are asking questions about a project, either find that project's thread, or start a thread in the General section instead.
Got a cool project idea but nothing else? Put it in the project ideas thread instead!
Projects for any Doom-based engine (especially 3DGE) are perfectly acceptable here too.
Please read the full rules for more details.
-
- 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: ZScript "Standard Library" - Brainstorming
I spent so long working this out that I totally forgot what I needed it for, but it seems like a good thing to have just in case:
Spoiler:
Last edited by Matt on Sun Jan 29, 2017 1:54 am, edited 7 times in total.
-
-
- Posts: 17478
- Joined: Mon Oct 27, 2003 12:07 am
- Location: Kuala Lumpur, Malaysia
Re: ZScript "Standard Library" - Brainstorming
Just throwing these here so that they don't get lost - for the person who's eventually going to compile these together.
Make cardboard-like monsters that auto-orient themselves on top of slopes (like in the game "Darwinia"):
And a tweak of the same code, tailored to be more suitable for flat sprites/models that are used for "fake decals" (blood splats, impact decals, grunge decals etc).
In this tweak, I also modularized the code into a "Physics" class. I guess you can use this as an example of how to create a class of shared/common functions.
All code written by ZZYZX!
Make cardboard-like monsters that auto-orient themselves on top of slopes (like in the game "Darwinia"):
Code: Select all
// Written by ZZYZX
class SlopedThing : Candelabra
{
Default
{
+FLATSPRITE;
//+ROLLCENTER;
}
private void SetToSlope(double dang)
{
vector3 fnormal = CurSector.floorplane.normal;
vector2 fnormalp1 = (fnormal.x != 0 || fnormal.y != 0) ? (fnormal.x, fnormal.y).Unit() : (0, 0);
vector2 fnormalp2 = ((fnormal.x, fnormal.y).Length(), fnormal.z);
double fang = atan2(fnormalp1.y, fnormalp1.x); // floor angle (not pitch!)
double fpitch = atan2(fnormalp2.x, fnormalp2.y); // floor pitch
double ddiff1 = cos(fang-(dang-90));
double ddiff2 = cos(fang-dang);
self.pitch = fpitch*ddiff2-90;
self.roll = -fpitch*ddiff1;
self.angle = dang;
}
override void PostBeginPlay()
{
Super.PostBeginPlay();
}
override void Tick()
{
double dang = (level.time*3)%360;
//dang = 45;
SetToSlope(dang);
Super.Tick();
}
}
In this tweak, I also modularized the code into a "Physics" class. I guess you can use this as an example of how to create a class of shared/common functions.
Code: Select all
//===========================================================================
//
// GENERIC PHYSICS CLASS
//
//===========================================================================
// Written by ZZYZX
// Modified by Nash Muhandes
class Physics
{
static void AlignToSlope(Actor self, double dAng, double dPitch)
{
vector3 fNormal = self.CurSector.FloorPlane.Normal;
vector2 fNormalP1 = (fNormal.X != 0 || fNormal.Y != 0) ? (fNormal.X, fNormal.Y).Unit() : (0, 0);
vector2 fNormalP2 = ((fNormal.X, fNormal.Y).Length(), fNormal.Z);
double fAng = atan2(fNormalP1.Y, fNormalP1.X); // floor angle (not pitch!)
double fPitch = -atan2(fNormalP2.X, fNormalP2.Y); // floor pitch
double dDiff1 = sin(fAng - (dAng + dPitch));
double dDiff2 = cos(fAng - dAng);
self.Pitch = fPitch * dDiff2 + dPitch;
self.Roll = fPitch * dDiff1;
self.Angle = dAng;
}
}
// Example usage of the Physics class
class Z_BloodSpot : Z_BloodBase
{
bool bSloped;
override void Tick()
{
if (!bSloped)
{
Physics.AlignToSlope(self, self.Angle, 0.f);
bSloped = true;
}
Super.Tick();
}
// ... states go here
}
-
-
- Posts: 17478
- Joined: Mon Oct 27, 2003 12:07 am
- Location: Kuala Lumpur, Malaysia
Re: ZScript "Standard Library" - Brainstorming
Also, hate to be that guy, but we're probably going to need to document some coding standards? Perhaps something like this wiki? Things like naming conventions, [cough cough] Allman VS K&R... ;D
-
- Posts: 8202
- Joined: Sun Jan 28, 2007 3:55 pm
- Preferred Pronouns: He/Him
- Location: QZDoom Maintenance Team
Re: ZScript "Standard Library" - Brainstorming
Project HOERS is coming along nicely I see. 
What we need is for Xaser to make the github so these won't be lost. Or I could.

What we need is for Xaser to make the github so these won't be lost. Or I could.
-
- Posts: 13884
- Joined: Tue Jan 13, 2004 1:31 pm
- Preferred Pronouns: She/Her
Re: ZScript "Standard Library" - Brainstorming
Still making me laugh.Major Cooke wrote:Project HOERS
Be careful what images you post in a thread for an unnamed project.

-
-
- Posts: 1384
- Joined: Sun Oct 14, 2012 1:43 am
- Location: Ukraine
Re: ZScript "Standard Library" - Brainstorming
HOERS=
Spoiler:Or
Spoiler:Although it'd be nice to have someone who actually has English as their native language to make up a proper matching name.
-
- 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: ZScript "Standard Library" - Brainstorming
I'm still in favour of Eruanna's original "Handy Open Example Repository System"
-
- Posts: 8202
- Joined: Sun Jan 28, 2007 3:55 pm
- Preferred Pronouns: He/Him
- Location: QZDoom Maintenance Team
Re: ZScript "Standard Library" - Brainstorming
At the beginning of ZScript, everyone was a hoers. Except for Graf, who is the engineer of the feeding lots.Eruanna wrote: Still making me laugh.
Be careful what images you post in a thread for an unnamed project.
99% of the first few tries, Hoers pushing buttons receive explosions and epic facemelting, as if they just pissed on a dinosaur frying electrical fence. The screams are usually 5-10 times louder than this one.
-
- Posts: 1268
- Joined: Wed Jul 20, 2011 4:24 pm
Re: ZScript "Standard Library" - Brainstorming
Hmm, so is this gonna be a "Zscript Pill"
Because hell I need one


Because hell I need one
-
- Posts: 13884
- Joined: Tue Jan 13, 2004 1:31 pm
- Preferred Pronouns: She/Her
Re: ZScript "Standard Library" - Brainstorming
ZScript isn't that hard, really. It's just more complicated than anything, since it exposes so many underlying systems that we haven't had access to, before.
-
- Posts: 1268
- Joined: Wed Jul 20, 2011 4:24 pm
Re: ZScript "Standard Library" - Brainstorming
it's more that I work better with examples (and also with a page like this one where I could easy find the function that I need by a simple ctrl+f ...
On my situation, I'm lost in alot of cases like:
-"ok there's a CheckSight function just like the acs one, but instead of passing a tid you need to give it an actor, so should I pass the tid in this case, an actor pointer or do I need some dark magic to get the tid's actor pointer?
-"hmm I can make some global vars in zscript, but can I use some global vars from acs into zscript? (maybe using some c style extern code_"
-"what logic types are supported? switches, do while, for, ..." ?
-Does goto exist, if not what should I use to replace it?
-Where do I put the doom ednum (the number that you use to Spawn stuff and not the name of the object) or it doesn't exist? ...
...
It would be nice to have This wad updated, where all the decorate code is converted to zscript, and maybe some introducion of some new stuff that were added into zscript/zdoom
On my situation, I'm lost in alot of cases like:
-"ok there's a CheckSight function just like the acs one, but instead of passing a tid you need to give it an actor, so should I pass the tid in this case, an actor pointer or do I need some dark magic to get the tid's actor pointer?
-"hmm I can make some global vars in zscript, but can I use some global vars from acs into zscript? (maybe using some c style extern code_"
-"what logic types are supported? switches, do while, for, ..." ?
-Does goto exist, if not what should I use to replace it?
-Where do I put the doom ednum (the number that you use to Spawn stuff and not the name of the object) or it doesn't exist? ...
...
It would be nice to have This wad updated, where all the decorate code is converted to zscript, and maybe some introducion of some new stuff that were added into zscript/zdoom
-
-
- Posts: 10773
- Joined: Sun Jul 20, 2003 12:15 pm
Re: ZScript "Standard Library" - Brainstorming
GZDoom.pk3 itself is a pretty great resource for examples, as most of the actor classes and action functions are scriptified now. If you're not quite sure how to use a function in practice, search through the pk3 (e.g. dump the files from the 'zscript' dir somewhere and use grep/windows-search/etc). Or just poke around some Hexen classes for a bit. The Heresiarch is a fun one for when you get to the intermediate/advanced stage. 

-
- Lead GZDoom+Raze Developer
- Posts: 49204
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: ZScript "Standard Library" - Brainstorming
Corrected that for you.Xaser wrote: The Heresiarch is a fun one for when you get to the messy stage.

Do not use the Heresiarch as a guideline how to do stuff, the code is 10x more convoluted than necessary, mostly on behalf of Raven, but Randi also has a fair share of mess to account for in there.
-
- Posts: 1268
- Joined: Wed Jul 20, 2011 4:24 pm
Re: ZScript "Standard Library" - Brainstorming
Oh that helped alot, tyXaser wrote:GZDoom.pk3 itself is a pretty great resource for examples, as most of the actor classes and action functions are scriptified now. If you're not quite sure how to use a function in practice, search through the pk3 (e.g. dump the files from the 'zscript' dir somewhere and use grep/windows-search/etc). Or just poke around some Hexen classes for a bit. The Heresiarch is a fun one for when you get to the intermediate/advanced stage.

Now I just need to figure out why the heck I'm getting "Attempt to get invalid state " errors from my zscript if the mentioned state isn't on my zscript (It's inside a decorate code but I'm not touching that other actor with my zscript ...
And ofc why other decorate codes are receiving the same error message D: ....
But it's evolving

-
-
- Posts: 10773
- Joined: Sun Jul 20, 2003 12:15 pm
Re: ZScript "Standard Library" - Brainstorming
There's still a lot of useful "hmm, how do I use function 'x'?" tidbits there. It's probably indeed worth clarifying that the algorithm as a whole isn't a particularly wholesome reference, but the parts that make up the whole are handy.Graf Zahl wrote:Do not use the Heresiarch as a guideline how to do stuff, the code is 10x more convoluted than necessary, mostly on behalf of Raven, but Randi also has a fair share of mess to account for in there.
...At this point, all of this is quite off-topic for this thread though. Except in a "make sure not to follow Raven's example in HOERS/ZBoost/MUHMUHFLUH" sort of way.
