"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
sonic_HD87
Posts: 287
Joined: Sat Mar 23, 2013 4:32 pm
Location: Venezuela

Re: "How do I ZScript?"

Post by sonic_HD87 »

There is an equivalent of GetPlayerInput but on ZScript?
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 »

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 there any way to do a simple tracer in ZScript? I.e. take a vector, send out a ray from that vector at a pitch & angle and get the Vector3 of wherever it collides with something (in 1 tick), be it wall or solid actor?
User avatar
Nash
 
 
Posts: 17433
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: "How do I ZScript?"

Post by Nash »

The best you'll get for now is AimLineAttack and LineAttack, and you can only use it to retrieve actors. You can't retrieve lines or sectors because the generic TraceResult isn't exported.

The difference between the two is that LineAttack also takes in pitch, and you can specify puffs to spawn and the damage.

Here's a test Demon that will run around looking for Z_TeleportMarkers to "use", by firing a trace in front of it every tic. When the trace hits a Z_TeleportMarker, it will "use" the thing.

Code: Select all

class Z_Demon : Demon replaces Demon
{
    void UseTeleportMarkers(void)
    {
        double useDist = 64.f,
                vDist = 35.f;

        // find things to use
        FTranslatedLineTarget t;
        AimLineAttack(Self.Angle, useDist, t, vDist, ALF_FORCENOSMART | ALF_CHECKCONVERSATION | ALF_PORTALRESTRICT);
        bool usable = (t.LineTarget != null && t.LineTarget is "Z_TeleportMarker");

        if (usable)
        {
            int tmID = t.LineTarget.TID,
            tmDest = t.LineTarget.args[0];
            vector3 destPos;

            if (tmDest != 0)
            {
                // find the actor with the matching TID
                ActorIterator it = ActorIterator.Create(tmDest);
                Actor a = it.Next ();
                if (a)
                {
                    destPos = a.Pos;

                    // some adjustment needed
                    // to do: handle blocked/congested destination more gracefully
                    double posAdjust = 40.f;
                    destPos = (destPos.X + Cos(a.Angle) * posAdjust, destPos.Y + Sin(a.Angle) * posAdjust, destPos.Z);
                }

                // to do: add fade out/fade in
                Self.Angle = a.Angle;
                Self.Pitch = 0;
                Self.SetXYZ(destPos);
            }
        }
    }

    override void Tick(void)
    {
        UseTeleportMarkers();
        Super.Tick();
    }
}
In your case, if you want to retrieve the position, you'd use

Code: Select all

Vector3 myPos = t.LineTarget.Pos;
 
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49056
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: "How do I ZScript?"

Post by Graf Zahl »

Trace should be exported but its implementation requires some C-isms to fully support its features, and that doesn't exist.
User avatar
Nash
 
 
Posts: 17433
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: "How do I ZScript?"

Post by Nash »

Code: Select all

struct FCharacter
{
    String characterClass; // used to be the DECORATE class
    int refID;

    // the name that's shown in dialogs
    String firstName, lastName, nickName;

    // default base container to attach to this character
    String defaultContainerClass;

    // holds refID of this character's container
    int containerID;

    // NPC, zombie or player?
    int characterType;

    // only 1 copy of this character allowed, ever. subsequent spawns will fail and print a warning
    bool isUnique;

    // protected = cannot be killed by anything except players
    // essential = cannot be killed, ever
    int deathProtection;

    int sex;
    int ethnicity;

    // only for players
    // hair and face stuff only appear in paperdoll screen
    int hairType, facialHairType,
        hairLength, facialHairLength;
    int faceType;

    // high muscle value adds strength bonuses
    // eat too much will cause bloating which increases fat value (makes movement slower, stamina runs out faster)
    // question: should these be implemented as (de)buffs instead of player properties?
    int muscle, fat;

    // which dialog set does this NPC have
    // (conversation ID)
    int dialogSet;

    // which schedule/AI script to follow
    // (for idle behavior or sleep/travel schedules.
    // can also be given by dialogs to perform scripted scenes)
    int AIPackage;

    // which user script to run when this character dies
    String deathScript;

    // stats
        // attributes
    int level,
        health, maxHealth,
        stamina, maxStamina,
        hunger, maxHunger,
        thirst, maxThirst,
        energy, maxEnergy,
        strength,
        mind,
        agility,
        vitality,
        charisma,
        luck,
        // skills
        blade,
        blunt,
        bow,
        unarmed,
        guns,
        electrical,
        carpentry,
        cooking,
        farming,
        sneak,
        perception,
        hunting,
        medicine,
        athletics,
        persuasion;

    // head has been destroyed, this character can no longer turn into a zombie or reanimate
    bool isReallyDead;

    // all zombies have this enabled
    bool isUndead;

    // limb damages are in percent
    int headHealth,
        torsoHealth,
        armLHealth,
        armRHealth,
        legLHealth,
        legRHealth;

    // a list of the refIDs of this character's active effects ((de)buffs)
    int activeEffect[100];

    // currently equipped stuff
    // holds refIDs of items to be equipped
    int curWeapon,
        curLight,
        // clothes
        curGlasses,
        curUnderShirt,
        curShirt,
        curGloves,
        curUnderPants,
        curPants,
        curShoes,
        // armor
        curHelmet,
        curBodyArmor,
        curArmLAmor,
        curArmRArmor,
        curLegLArmor,
        curLegRArmor;
}

class Z_Actor : Actor
{
    Default
    {
    }

    FCharacter stat;

    static int GetHunger (Actor self)
    {
        return self.stat.hunger;
    }

}
 
It says "unknown identifier stat". How do I retrieve the hunger member from the stat struct?
Last edited by Nash on Fri Feb 17, 2017 6:23 am, edited 1 time in total.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49056
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: "How do I ZScript?"

Post by Graf Zahl »

Where's the FCharacter struct?
User avatar
Nash
 
 
Posts: 17433
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: "How do I ZScript?"

Post by Nash »

Oh I didn't post it because I thought it was too long for the forum. But it's there in my ZScript files. It still doesn't work.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49056
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: "How do I ZScript?"

Post by Graf Zahl »

It cannot find 'stat' because you pass in a pointer to 'Actor', ot 'Z_Actor'.
User avatar
Nash
 
 
Posts: 17433
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: "How do I ZScript?"

Post by Nash »

D'oh! Works perfectly now. Thanks! :D
User avatar
Nash
 
 
Posts: 17433
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: "How do I ZScript?"

Post by Nash »

Question @ ZZYZX:

Old way:

Code: Select all

Bind Shift=pukename Script_ActivateSprint

// ACS
script "Script_ActivateSprint" (void) net
{
    // activate sprint mode
}
ZScript events way how? Help me please Event God. :D
User avatar
Expect No Mercy
Posts: 45
Joined: Sun Mar 18, 2012 1:43 am

Re: "How do I ZScript?"

Post by Expect No Mercy »

Xaser wrote: Now, there is one thing you can do currently: make the sprites themselves translucent (i.e. PNG with an alpha channel). These will appear translucent in the GL renderer, and also the Software renderer if using the D3D layer (only available on Windows, though, and users can turn it off if they so desire). Best you can get, but it's better than nothing.
Have tested this now, and it works. But brightmaps didn't work on these. :(
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 »

Nash wrote:The best you'll get for now is AimLineAttack and LineAttack, and you can only use it to retrieve actors. You can't retrieve lines or sectors because the generic TraceResult isn't exported.
Ah, well that's a shame then, to do what I need to do I'd need to get a set of coordinates of where the tracer hit regardless if it hit an actor or a sector/line, so I'll have to find another way.
@Graf - Can I ever expect a tracer function to be exported, or will those C-isms always hold it back?
User avatar
Nash
 
 
Posts: 17433
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: "How do I ZScript?"

Post by Nash »

You can use LineAttack to spawn a puff and retrieve the puff's Vector3 position.
User avatar
sonic_HD87
Posts: 287
Joined: Sat Mar 23, 2013 4:32 pm
Location: Venezuela

Re: "How do I ZScript?"

Post by sonic_HD87 »

Gutawer wrote:Yes, GetPlayerInput. :P
https://zdoom.org/wiki/GetPlayerInput_(DECORATE)
It doesn't matter if it says "development version only"?
Locked

Return to “Scripting”