"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!)
User avatar
kodi
 
 
Posts: 1355
Joined: Mon May 06, 2013 8:02 am

Re: "How do I ZScript?"

Post by kodi »

Do player actors necessarily have to inherit from PlayerPawn, or can I do

Code: Select all

class ModName_BaseActor : actor
{
stuff;
}

class ModName_PlayerActor : ModName_BaseActor
{
playerpawn stuff;
}

User avatar
Major Cooke
Posts: 8197
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 »

You can only do playerpawn stuff if you have an actual playerpawn to work with. It can be done either way but know that you'll have to find A player pawn with the latter.
User avatar
Nash
 
 
Posts: 17468
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

Re: "How do I ZScript?"

Post by Nash »

Code: Select all

            for (let i = index, a = borderAngle / 45.; a < 180.; i--, a += 45.)
            {
            }
I can't do this in ZScript? acc.exe allowed it... (specifically the last I-- and a += do not work; I can only assign one variable at the end here but not both. The initializer works fine)
User avatar
ZZYZX
 
 
Posts: 1384
Joined: Sun Oct 14, 2012 1:43 am
Location: Ukraine

Re: "How do I ZScript?"

Post by ZZYZX »

Please don't write code like that. It's unreadable.
Is it that hard to declare the variable outside?
User avatar
Nash
 
 
Posts: 17468
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

Re: "How do I ZScript?"

Post by Nash »

Sure, I can declare them outside, but declaring the variables isn't the problem... the problem is assigning the two variables at the end.

Also, hopefully a simpler question: when you read an Actor's angle, the number can go below 0 and above 360. How do I wrap the values around so that I can reliably only get results between 0 and 360?
User avatar
ZZYZX
 
 
Posts: 1384
Joined: Sun Oct 14, 2012 1:43 am
Location: Ukraine

Re: "How do I ZScript?"

Post by ZZYZX »

Code: Select all

double ang = angle;
if (ang < 0) ang = 360.0-(ang % 360);
else ang = ang % 360;
Something like that. There might be a native function that does it however, and I'm not sure that % works on doubles in ZScript (in most languages it doesn't, but I remember that it kinda worked...)
In case % doesn't work,

Code: Select all

while (ang < 0) ang+=360; while(ang >= 360) ang-=360;
User avatar
Nash
 
 
Posts: 17468
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

Re: "How do I ZScript?"

Post by Nash »

Thanks! Actually just doing this will normalize it nicely.

Code: Select all

double pa = CPlayer.mo.Angle % 360;
 
User avatar
Major Cooke
Posts: 8197
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 »

Note that doesn't take into account if going from positive to negative. I.e. from 2 to -2, that won't handle it.

In the engine's case it's nothing to worry about because it automatically normalizes it when negative... I think.
User avatar
DenisBelmondo
Posts: 380
Joined: Fri Jun 06, 2008 6:26 pm
Location: Two-Key Return

Re: "How do I ZScript?"

Post by DenisBelmondo »

Sorry to interrupt the backend talk, but does anyone know if an EventHandler has a function that can check a thing's state? I want to check to see if the currently dead actor has entered its xdeath state. In this context, e.thing.health < -e.thing.GetSpawnHealth() doesn't necessarily do the job since an actor's gibhealth property could change depending on its own gibhealth property or the gameinfo property. I apologize if this question has been asked already, I'm not sure what to search for in exact terms.
Migrating the question to this topic. Is it possible (yet)?
User avatar
Jimmy
 
 
Posts: 4725
Joined: Mon Apr 10, 2006 1:49 pm
Preferred Pronouns: He/Him

Re: "How do I ZScript?"

Post by Jimmy »

Is it possible to make a super rudimentary backpack item that just configures the MaxAmount of all types of ammo as I see fit?

And will this work via ACS script like the ammo change of a backpack apparently doesn't?


EDIT: [no]
Last edited by Jimmy on Tue Mar 28, 2017 10:50 am, edited 1 time in total.
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 »

@Jimmy - answering on ZDoom Discord
User avatar
Major Cooke
Posts: 8197
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 »

Share it here too so others can see it.

But yes, the max amount of any item can be modified on a whim.
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 »

Turns out the issue was completely unrelated, some actor was replacing the wrong actor and it was fucking everything up, heh
User avatar
Jimmy
 
 
Posts: 4725
Joined: Mon Apr 10, 2006 1:49 pm
Preferred Pronouns: He/Him

Re: "How do I ZScript?"

Post by Jimmy »

i am basically the best at the zdooms
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

Re: "How do I ZScript?"

Post by Matt »

DenisBelmondo wrote:does anyone know if an EventHandler has a function that can check a thing's state? I want to check to see if the currently dead actor has entered its xdeath state. In this context, e.thing.health < -e.thing.GetSpawnHealth() doesn't necessarily do the job since an actor's gibhealth property could change depending on its own gibhealth property or the gameinfo property. I apologize if this question has been asked already, I'm not sure what to search for in exact terms.
Not that I know an eventhandler from a hole in the ground at this point, but would something like

Code: Select all

if(thing.instatesequence(thing.curstate,thing.resolvestate("xdeath")))
work?


EDIT: Question of my own: is it possible to access an actor-defined variable in ACS somehow?

Return to “Scripting”