"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
Death Egg
Posts: 198
Joined: Tue Aug 14, 2012 10:16 pm

Re: "How do I ZScript?"

Post by Death Egg »

From this tutorial of converting Sonic physics to other engines:

Code: Select all

p -= ((p div 0.125) / 256); //"div" is division ignoring any remainder
What would the equivalent for "div" in this situation be for ZScript?
User avatar
AFADoomer
Posts: 1324
Joined: Tue Jul 15, 2003 4:18 pm
Contact:

Re: "How do I ZScript?"

Post by AFADoomer »

You'll want to cast that portion of the equation as an int and use normal division.

Something like:

Code: Select all

p -= int(p / 0.125) / 256;
That'll essentially force the engine to divide p by 0.125, then disregard the non-integer part of the result (the remainder).
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 »

Why not multiply by 8?
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 »

How do you get a player's name?
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 »

Vaecrius wrote:How do you get a player's name?

Code: Select all

player.GetUserName()
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 offset all attacks on a PlayerPawn by a certain angle/pitch, sorta like you can change the Z offset with AttackZOffset?
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 »

Only via the functions like A_FireProjectile's parameters. You'll have to set up your own system, aka no layman way around it.
User avatar
Death Egg
Posts: 198
Joined: Tue Aug 14, 2012 10:16 pm

Re: "How do I ZScript?"

Post by Death Egg »

How can I stop a boolean value from changing under certain conditions? In this example while the player is crouched using Nash's Side Scrolling engine, I don't want the player to be able to change the direction they're facing on a whim.
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 »

Make a function that will only change it based on conditions which you set inside of it. If you mean to stop external access from changing it, make the boolean private in addition, and ensure the function is accessible.

This is assuming it's a completely you-made boolean. If you mean an internal boolean, you'll have to get a little more creative.
User avatar
Nash
 
 
Posts: 17439
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: "How do I ZScript?"

Post by Nash »

Death Egg wrote:How can I stop a boolean value from changing under certain conditions? In this example while the player is crouched using Nash's Side Scrolling engine, I don't want the player to be able to change the direction they're facing on a whim.
Add a !bIsCrouching condition to the part that sets the player's direction (it's close to the top of MoveSideScrollerPlayer)

Code: Select all

    void MoveSideScrollerPlayer(void)
    {
        // LEFT/RIGHT MOVEMENT /////////////////////////////////////////////////

        double sideInput = GetPlayerInput(INPUT_SIDEMOVE);
        double normalizedSideInput;

        /*
        // You can use the following formula for analog player movement
        // I have analog movement disabled on purpose
        double normalizedInput = SideMove1 * sideInput / 10240.;
        */

        if (sideInput < 0 && !bIsCrouching)
        {
            dir = DIR_Left;
            normalizedSideInput = -SideMove1;
        }
        else if (sideInput > 0 && !bIsCrouching)
        {
            dir = DIR_Right;
            normalizedSideInput = SideMove1;
        }
Can also be done this way

Code: Select all

        if (!bIsCrouching)
        {
            if (sideInput < 0)
            {
                dir = DIR_Left;
                normalizedSideInput = -SideMove1;
            }
            else if (sideInput > 0)
            {
                dir = DIR_Right;
                normalizedSideInput = SideMove1;
            }
        }
 
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 »

How do you tell if a player is in god mode? binvulnerable and !bshootable don't work and I'm out of ideas.
User avatar
Nash
 
 
Posts: 17439
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: "How do I ZScript?"

Post by Nash »

I think there's a variable called cheatflags, I don't exactly remember, do a global search for CF_ and you'll see how it's used throughout the engine.
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 »

Vaecrius wrote:How do you tell if a player is in god mode? binvulnerable and !bshootable don't work and I'm out of ideas.
Nash wrote:I think there's a variable called cheatflags, I don't exactly remember, do a global search for CF_ and you'll see how it's used throughout the engine.
All of the cheat flags are listed in zscript/constants.txt, under "enum EPlayerCheats".
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 »

player.cheats lets me access it. Thanks!
D2JK
Posts: 543
Joined: Sat Aug 30, 2014 8:21 am

Re: "How do I ZScript?"

Post by D2JK »

I've been away for a few months, so I was wondering: using the current version, is it now possible to write a "public" or "global" function that can be called by any actor? I vaguely recall there was some discussion about these months ago and that they might have been also called static functions back then, but I couldn't really find anything useful by searching.

Basically, I want to write a function once and only once, and then call it from any actor without having to copy the function code needlessly.
Locked

Return to “Scripting”