"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
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 »

And that is why I stated I can't really improve on the lightning effects in D4D in terms of interpolation.
User avatar
JPL
 
 
Posts: 523
Joined: Mon Apr 09, 2012 12:27 pm
Contact:

Re: "How do I ZScript?"

Post by JPL »

Gez wrote:
JPL wrote:- choose a random monster from the level's population, give it a special key (dropped on death) and some stat boosts that make it visually distinct and harder to kill.
What if the monster is out of reach? Like that imp just before the exit door in MAP01? Or the imps in the center cage in E1M9?
Nash wrote:Fire a line trace to let the player telekinetically pick the key up? :P

Or maybe some fancy effect where the key homes in on you like the Revenant's missile, except it goes through walls and other Actors.
Yep, this is what I was thinking would be needed to turn it into a proper mod. Thanks again for the help starting!
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 return (or, if possible, alter) the maximum amount of an inventory or ammo item carryable by the player?
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 »

Code: Select all

<Actor>.FindInventory("class name").MaxAmount;
Remember to check that the pointer exists before getting its MaxAmount, since that can cause a crash.
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 »

Unknown function MaxAmount
Is this only available after 3.0.1?Oh, right, it's not a read-only function, no parentheses.

Thanks!
Last edited by Matt on Mon May 22, 2017 2:55 pm, 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 »

MaxAmount isn't a function, it's an int on the Inventory class.
D2JK
Posts: 543
Joined: Sat Aug 30, 2014 8:21 am

Re: "How do I ZScript?"

Post by D2JK »

In ZScript, is it generally possible for a monster to commit aimed line/projectile/rail attacks against shootable actors other than its current target? In one such a case for a rail attack, I temporarily stored the current target in a new pointer and restored it afterwards, but I was wondering if a more direct way to do this exists, or if one is planned in the future.

Edit:

Another quick question: is it not possible to override the Tick() function for selected weapons? I'm asking because this doesn't seem to work:

Code: Select all

Override Void Tick()
 {
  if (GetPlayerInput(INPUT_BUTTONS)  &  BT_SPEED)
   A_LogInt(level.maptime);
  Super.Tick();
 }
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 »

For rails, not sure I can really help there but I know you can do LineAttack.

Don't use Tick on the weapon. Instead, make an overlay.
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 »

If a weapon has non-constant variables (i.e. int MyVar), do they reset when the weapon is switched away from or are they kept?

If reset, that means I'll have to use a thinker for it. Hmmm...
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 »

D2JK wrote:Another quick question: is it not possible to override the Tick() function for selected weapons? I'm asking because this doesn't seem to work:

Code: Select all

Override Void Tick()
 {
  if (GetPlayerInput(INPUT_BUTTONS)  &  BT_SPEED)
   A_LogInt(level.maptime);
  Super.Tick();
 }
This doesn't work because in that function "self" means the weapon, so getplayerinput will not return anything.

You'll have to check for an owner, then get owner.getplayerinput, something like this:

Code: Select all

Override Void Tick()
 {
  if (owner && owner.GetPlayerInput(INPUT_BUTTONS)  &  BT_SPEED)
   A_LogInt(level.maptime);
  Super.Tick();
 }
But if all you want is something for a currently selected weapon, then there's no point in doing this instead of using an overlay. (The above example would log the maptime if you held +speed no mattter what you had selected, as long as this weapon was in your inventory somewhere; in fact this could even be an inventory or ammo item) This would be useful for a weapon that does things passively whether or not it's selected (edit: or even in anyone's inventory), though (e.g., cooling down, regenerating bees, etc.).

EDIT: example re: bees:
Spoiler:
Edited per MC's comment below - this version will continue to regenerate ammo even while the weapon is dropped (using DoEffect() here would cause regeneration to happen only while the weapon was being carried - which could be what you want, if you're making a weapon that's charged by your life force or something).
Last edited by Matt on Wed May 24, 2017 2:23 pm, edited 4 times in total.
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 »

Except you should be using DoEffect() instead, last I checked. Every inventory actor has this, and it's always called for owned inventory. Weapon inherits from StateProvider which inherits from Inventory after all.
User avatar
JPL
 
 
Posts: 523
Joined: Mon Apr 09, 2012 12:27 pm
Contact:

Re: "How do I ZScript?"

Post by JPL »

Ran into a crash (segfault) with the mod I'm working on, and I made a tiny test case (PK3 attached) with nothing but the behavior that's crashing. I've only been working with ZScript for a few days so I'm fairly sure it's a simple mistake.

Basically I have a HUD mod that does this:
Spoiler:
and an EventHandler that does this:
Spoiler:
As you can see I declare the UI's testMonster variable in the "play" scope because it can't be read from the UI scope... is there a simpler way to do this? And what's the correct way to create and destroy such references from EventHandler code? I couldn't find any code examples or documentation specifically about this on the wiki. BTW the docs on the wiki are really coming along, they've been very useful to me so far, keep up the good work!
Attachments
hudtest.pk3
(1.31 KiB) Downloaded 18 times
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 »

You cannot access statusbar like that at all. Instead, the world function should give the player a pointer for the statusbar to constantly check upon, and then have the statusbar retrieve it from the player instead.

...Or you could send a network event. That is one of the very few functions that has the ability to cross the UI and Play boundaries.

And, thanks!
User avatar
JPL
 
 
Posts: 523
Joined: Mon Apr 09, 2012 12:27 pm
Contact:

Re: "How do I ZScript?"

Post by JPL »

Major Cooke wrote:You cannot access statusbar like that at all. Instead, the world function should give the player a pointer for the statusbar to constantly check upon, and then have the statusbar retrieve it from the player instead.
Can this be done without creating a PlayerPawn subclass? Thus far I've been able to do everything with the EventHandler and StatusBar...
...Or you could send a network event. That is one of the very few functions that has the ability to cross the UI and Play boundaries.
I see the code here describes how to talk to EventHandler from UI, but what about the other way round? I want the UI to know about the position of an object in the world.
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 »

Give CPlayer.mo an inventory item with custom properties. Then do CPlayer.mo.FindInventory and dig for its contents in there. That's one way.
Locked

Return to “Scripting”