ZScript "Standard Library" - Brainstorming

Post your example zscripts/ACS scripts/etc here.
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.
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: ZScript "Standard Library" - Brainstorming

Post by Matt »

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.
User avatar
Nash
 
 
Posts: 17439
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: ZScript "Standard Library" - Brainstorming

Post by Nash »

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"):

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();
    }
}
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.

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
}
All code written by ZZYZX!
User avatar
Nash
 
 
Posts: 17439
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: ZScript "Standard Library" - Brainstorming

Post by Nash »

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
User avatar
Major Cooke
Posts: 8176
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: ZScript "Standard Library" - Brainstorming

Post by Major Cooke »

Project HOERS is coming along nicely I see. :P

What we need is for Xaser to make the github so these won't be lost. Or I could.
User avatar
Rachael
Posts: 13571
Joined: Tue Jan 13, 2004 1:31 pm
Preferred Pronouns: She/Her
Contact:

Re: ZScript "Standard Library" - Brainstorming

Post by Rachael »

Major Cooke wrote:Project HOERS
Still making me laugh.

Be careful what images you post in a thread for an unnamed project. :twisted:
User avatar
ZZYZX
 
 
Posts: 1384
Joined: Sun Oct 14, 2012 1:43 am
Location: Ukraine
Contact:

Re: ZScript "Standard Library" - Brainstorming

Post by ZZYZX »

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.
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: ZScript "Standard Library" - Brainstorming

Post by Matt »

I'm still in favour of Eruanna's original "Handy Open Example Repository System"
User avatar
Major Cooke
Posts: 8176
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: ZScript "Standard Library" - Brainstorming

Post by Major Cooke »

Eruanna wrote: Still making me laugh.

Be careful what images you post in a thread for an unnamed project. :twisted:
At the beginning of ZScript, everyone was a hoers. Except for Graf, who is the engineer of the feeding lots.

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.
User avatar
ibm5155
Posts: 1268
Joined: Wed Jul 20, 2011 4:24 pm
Contact:

Re: ZScript "Standard Library" - Brainstorming

Post by ibm5155 »

Hmm, so is this gonna be a "Zscript Pill" :roll: :lol:
Because hell I need one
User avatar
Rachael
Posts: 13571
Joined: Tue Jan 13, 2004 1:31 pm
Preferred Pronouns: She/Her
Contact:

Re: ZScript "Standard Library" - Brainstorming

Post by Rachael »

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.
User avatar
ibm5155
Posts: 1268
Joined: Wed Jul 20, 2011 4:24 pm
Contact:

Re: ZScript "Standard Library" - Brainstorming

Post by ibm5155 »

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
User avatar
Xaser
 
 
Posts: 10772
Joined: Sun Jul 20, 2003 12:15 pm
Contact:

Re: ZScript "Standard Library" - Brainstorming

Post by Xaser »

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. :P
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49073
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: ZScript "Standard Library" - Brainstorming

Post by Graf Zahl »

Xaser wrote: The Heresiarch is a fun one for when you get to the messy stage. :P
Corrected that for you. :P
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.
User avatar
ibm5155
Posts: 1268
Joined: Wed Jul 20, 2011 4:24 pm
Contact:

Re: ZScript "Standard Library" - Brainstorming

Post by ibm5155 »

Xaser 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. :P
Oh that helped alot, ty :D

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 :p
User avatar
Xaser
 
 
Posts: 10772
Joined: Sun Jul 20, 2003 12:15 pm
Contact:

Re: ZScript "Standard Library" - Brainstorming

Post by Xaser »

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.
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.


...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. :P
Post Reply

Return to “Script Library”