"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
Major Cooke
Posts: 8182
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: ZScript-only "How do I..." thread

Post by Major Cooke »

Would it be better if all that just directly placed into Tick() then?
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: ZScript-only "How do I..." thread

Post by Matt »

Ed the Bat wrote:Going back to this topic...
Would anyone be able to teach me how to make a variant of A_RailAttack that honors autoaim?
From Graf's last comment it seems we just need to figure out what all this means from the Wiki:
double AimLineAttack(double angle, double distance, out FTranslatedLineTarget pLineTarget = null, double vrange = 0., int flags = 0, Actor target = null, Actor friender = null);
Actor, int LineAttack(double angle, double distance, double pitch, int damage, Name damageType, class<Actor> pufftype, int flags = 0, out FTranslatedLineTarget victim = null);
I can't access a copy of gzdoom.pk3 right now but I'm assuming this function is scriptified enough that the flags should be in there somewhere.


Also, can a mod maybe move the Darwinia sprite sloping stuff to a separate thread? It can get a little hard to follow a thread like this with something this complex going on at the same time.
User avatar
Major Cooke
Posts: 8182
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: ZScript-only "How do I..." thread

Post by Major Cooke »

First off, it's already solved.

Second, it's a "How do I..." thread where it belongs. We really don't need to be making more as it would've been solved in good time anyway.

Third, it's a great place to look for things that may have been asked already. I say keep it.
User avatar
ZZYZX
 
 
Posts: 1384
Joined: Sun Oct 14, 2012 1:43 am
Location: Ukraine

Re: ZScript-only "How do I..." thread

Post by ZZYZX »

ZScript "How do I..." thread is not going to be simple. The language itself is full of complex and/or internal stuff.
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: ZScript-only "How do I..." thread

Post by Matt »

Guess I'll start the next question then! (notwithstanding I too want to know the answer to Ed's)

I want to do a for loop that goes through all the players on the map to do something to each of them. How would I set up this loop?
User avatar
Ed the Bat
Posts: 3060
Joined: Thu May 03, 2012 1:18 pm
Graphics Processor: nVidia with Vulkan support
Location: Maryland, US

Re: ZScript-only "How do I..." thread

Post by Ed the Bat »

Vaecrius wrote:I want to do a for loop that goes through all the players on the map to do something to each of them. How would I set up this loop?
Now that one, I can answer! In this example, let's say I want to give every player one Clip:

Code: Select all

for(int i=0;i<MAXPLAYERS;i++)
{
	if(playeringame[i])
	{
		players[i].mo.A_GiveInventory("Clip");
	}
}
User avatar
ZZYZX
 
 
Posts: 1384
Joined: Sun Oct 14, 2012 1:43 am
Location: Ukraine

Re: ZScript-only "How do I..." thread

Post by ZZYZX »

Remember to check for .mo not being null. This can happen for spectators for example if ZScript ever gets to Zandronum.
Also under certain circumstances this probably could happen in GZDoom as well.
User avatar
Ed the Bat
Posts: 3060
Joined: Thu May 03, 2012 1:18 pm
Graphics Processor: nVidia with Vulkan support
Location: Maryland, US

Re: ZScript-only "How do I..." thread

Post by Ed the Bat »

Yes, good catch. Always safer to have that net in place, just in case, right?
User avatar
Beed28
Posts: 598
Joined: Sun Feb 24, 2013 4:07 pm
Location: United Kingdom

Re: ZScript-only "How do I..." thread

Post by Beed28 »

How would I be able to remove all ammo and weapons currently present on the map? Using this doesn't seem to work, for example;

Code: Select all

Class ActorController : Actor
{
	int Monster_MaxHP;
	
	Default
	{
		+NOINTERACTION
		+NOTRIGGER
	}
	
	Override void Tick()
	{
		Actor ac;
		let it = ThinkerIterator.Create();
		while (ac = Actor(it.Next()))
		{

		if(ac.GetClass() == "Ammo" || ac.GetClass() == "Weapon")
			{
				ac.A_FadeOut(1.0);
			}

		}
		Super.Tick();
	}
}
User avatar
TheCamaleonMaligno
Posts: 85
Joined: Sun Jun 28, 2015 3:25 pm
Location: Frozen igloo, IN MIDDLE OF THE DESERT!!

Re: ZScript-only "How do I..." thread

Post by TheCamaleonMaligno »

small question: does SXF_TRANSFERPOINTERS transfer custom pointers?
User avatar
ZZYZX
 
 
Posts: 1384
Joined: Sun Oct 14, 2012 1:43 am
Location: Ukraine

Re: ZScript-only "How do I..." thread

Post by ZZYZX »

Should not. Remember classes have different field sets and checking for matching fields would be a bit of an overkill.
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: ZScript-only "How do I..." thread

Post by Matt »

Thanks!
(I assume "&&(players.mo)" would do the trick? Or do I need to add a !=null after the mo?)


Beed: GetClass or CheckClass? Surely there's something in that function that lets you specify whether to check for an inheritance ancestor or not?


Questions:
How does using "GetGravity()" differ from using the word "gravity" (which seems to work)?

What's the difference between the AddInventory and GiveInventory (and GiveAmmo) functions? Does Add bypass pickup states? Do the first two ignore skill-based ammo doubling?
User avatar
Major Cooke
Posts: 8182
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: ZScript-only "How do I..." thread

Post by Major Cooke »

@Beed28, I have just the thing you need.

Only it's a bit ridiculous since that's actually a setup template and what not, but it works. Summon AmmoRemover.
User avatar
Beed28
Posts: 598
Joined: Sun Feb 24, 2013 4:07 pm
Location: United Kingdom

Re: ZScript-only "How do I..." thread

Post by Beed28 »

Ah ha, I figured it out. Cheers.
User avatar
ZZYZX
 
 
Posts: 1384
Joined: Sun Oct 14, 2012 1:43 am
Location: Ukraine

Re: ZScript-only "How do I..." thread

Post by ZZYZX »

Vaecrius wrote:Thanks!
(I assume "&&(players.mo)" would do the trick? Or do I need to add a !=null after the mo?)

Objects implicitly cast to bool like in C, yes.

Vaecrius wrote:What's the difference between the AddInventory and GiveInventory (and GiveAmmo) functions? Does Add bypass pickup states? Do the first two ignore skill-based ammo doubling?

AddInventory takes an Inventory object (possibly created using Spawn()).
GiveInventory takes a class name.

Return to “Scripting”