ZScript "Standard Library" - Brainstorming

Post your example zscripts/ACS scripts/etc here.

Re: ZScript "Standard Library" - Brainstorming

Postby Matt » Sat Jan 28, 2017 8:50 pm

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
Matt
Putting the XD into *xdeath since 2007
 
Joined: 04 Jan 2004
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia

Re: ZScript "Standard Library" - Brainstorming

Postby Nash » Sat Jan 28, 2017 9:37 pm

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 allExpand view
// Written by ZZYZX
class SlopedThing : Candelabra
{
    Default
    
{
        +FLATSPRITE;
        //+ROLLCENTER;
    }

    private void SetToSlope(double dang)
    {
        vector3 fnormal = CurSector.floorplane.normal;
        vector2 fnormalp1 = (fnormal.!= 0 || fnormal.!= 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 allExpand view
//===========================================================================
//
// 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.!= 0 || fNormal.!= 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
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Github ID: nashmuhandes

Re: ZScript "Standard Library" - Brainstorming

Postby Nash » Sat Jan 28, 2017 9:45 pm

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
Nash
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Github ID: nashmuhandes

Re: ZScript "Standard Library" - Brainstorming

Postby Major Cooke » Sat Jan 28, 2017 10:27 pm

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
Major Cooke
QZDoom Maintenance Team
 
Joined: 28 Jan 2007

Re: ZScript "Standard Library" - Brainstorming

Postby Rachael » Sun Jan 29, 2017 12:20 am

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
Rachael
Webmaster
 
Joined: 13 Jan 2004
Discord: Rachael#3767
Twitch ID: madamerachelle
Github ID: madame-rachelle
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Re: ZScript "Standard Library" - Brainstorming

Postby ZZYZX » Sun Jan 29, 2017 1:09 am

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
ZZYZX
le chat du rabbin
 
 
 
Joined: 14 Oct 2012
Location: Ukraine
Discord: ZZYZX#1394
Github ID: jewalky

Re: ZScript "Standard Library" - Brainstorming

Postby Matt » Sun Jan 29, 2017 1:53 am

I'm still in favour of Eruanna's original "Handy Open Example Repository System"
User avatar
Matt
Putting the XD into *xdeath since 2007
 
Joined: 04 Jan 2004
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia

Re: ZScript "Standard Library" - Brainstorming

Postby Major Cooke » Sun Jan 29, 2017 5:41 pm

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
Major Cooke
QZDoom Maintenance Team
 
Joined: 28 Jan 2007

Re: ZScript "Standard Library" - Brainstorming

Postby ibm5155 » Sun Jan 29, 2017 7:41 pm

Hmm, so is this gonna be a "Zscript Pill" :roll: :lol:
Because hell I need one
User avatar
ibm5155
Just Spooky
 
Joined: 20 Jul 2011

Re: ZScript "Standard Library" - Brainstorming

Postby Rachael » Sun Jan 29, 2017 9:33 pm

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
Rachael
Webmaster
 
Joined: 13 Jan 2004
Discord: Rachael#3767
Twitch ID: madamerachelle
Github ID: madame-rachelle
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Re: ZScript "Standard Library" - Brainstorming

Postby ibm5155 » Mon Jan 30, 2017 11:37 am

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
ibm5155
Just Spooky
 
Joined: 20 Jul 2011

Re: ZScript "Standard Library" - Brainstorming

Postby Xaser » Mon Jan 30, 2017 1:49 pm

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
Xaser
anarchivist
 
 
 
Joined: 20 Jul 2003

Re: ZScript "Standard Library" - Brainstorming

Postby Graf Zahl » Mon Jan 30, 2017 2:29 pm

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
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: ZScript "Standard Library" - Brainstorming

Postby ibm5155 » Mon Jan 30, 2017 2:41 pm

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
ibm5155
Just Spooky
 
Joined: 20 Jul 2011

Re: ZScript "Standard Library" - Brainstorming

Postby Xaser » Mon Jan 30, 2017 2:47 pm

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
User avatar
Xaser
anarchivist
 
 
 
Joined: 20 Jul 2003

PreviousNext

Return to Script Library

Who is online

Users browsing this forum: No registered users and 0 guests