"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
ZzZombo
Posts: 315
Joined: Mon Jul 16, 2012 2:02 am

Re: "How do I ZScript?"

Post by ZzZombo »

"goto" is static, thus it never considers any child overrides of the target state. You should use a jumping function, as they resolve dynamically. Like A_Jump(256,<state>).
Pink Baron
Posts: 33
Joined: Wed Mar 16, 2016 4:19 pm

Re: "How do I ZScript?"

Post by Pink Baron »

ZzZombo wrote:"goto" is static, thus it never considers any child overrides of the target state. You should use a jumping function, as they resolve dynamically. Like A_Jump(256,<state>).
"Return ResolveState" instead of "Goto" statements
It worked! Thanks :D
User avatar
Major Cooke
Posts: 8170
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 »

Kinsie, I did some further digging. I'm not entirely positive about this but hopefully Graf can put in some words of wisdom to correct me where I'm wrong.

Code: Select all

native static vector3, int G_PickDeathmatchStart();
native static vector3, int G_PickPlayerStart(int pnum, int flags = 0);
Both of these will return the angle and the coordinates of the player start. If the player starts do not exist, it returns a vector of (0,0,0) and an angle of 0.

G_PickPlayerStart's pnum is the player number. I.e. a player start of 1 will get the player's playing start, but be careful -- this will include the players actual spawn point. This also includes voodoo dolls, so it wouldn't hurt to do a safety check for playerpawns being at those locations upon map start.

There's two flags for this:

Code: Select all

PPS_FORCERANDOM
PPS_NOBLOCKINGCHECK
I believe it's self explanatory enough but if you need clarification on the flags, let me know.

So if you just want the very base player starts I think it's reasonable to call that function for players 1-4 and that should be good.
User avatar
Zergeant
Posts: 107
Joined: Tue Aug 31, 2010 7:19 am
Location: Sweden

Re: "How do I ZScript?"

Post by Zergeant »

Is there any way to have your own variables with Weapons? I could really use int and bool to check a few things, and also not have to rely on dummy inventory items.

Currently attempting to access variables inside states just gives a "Self pointer used in ambiguous context; VM execution may abort!".
D2JK
Posts: 543
Joined: Sat Aug 30, 2014 8:21 am

Re: "How do I ZScript?"

Post by D2JK »

It will work when you add an invoker. prefix whenever you refer to your variable in the weapon states:

Code: Select all

Class MyWeapon : Weapon
 {
  int MyVariable;
  States
   {
    Fire:
     TNT1 A 0 A_LogInt(invoker.MyVariable);
     ...
   }
 }
User avatar
Zergeant
Posts: 107
Joined: Tue Aug 31, 2010 7:19 am
Location: Sweden

Re: "How do I ZScript?"

Post by Zergeant »

D2JK wrote:It will work when you add an invoker. prefix whenever you refer to your variable in the weapon states:

Code: Select all

Class MyWeapon : Weapon
 {
  int MyVariable;
  States
   {
    Fire:
     TNT1 A 0 A_LogInt(invoker.MyVariable);
     ...
   }
 }
Thanks dude, managed to figure it out just as soon as you posted.
User avatar
JPL
 
 
Posts: 523
Joined: Mon Apr 09, 2012 12:27 pm
Contact:

Re: "How do I ZScript?"

Post by JPL »

Is there a reason DropItem.Probability is marked as read-only in base.txt? I tried to modify it from some ZScript (to turn off all enemy drops by setting it to 0) and found I couldn't. I removed the readonly keyword from it in base.txt and it worked fine, are there any negative repercussions to doing so? I assume it was set that way on purpose for some reason. Otherwise I could submit a PR but it's a trivial change...
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 »

I just learned today that if you have multiple different instances of a pickup each call attachtoowner() directly, you'll end up with each of them as a separate entry on printinv. I want to exploit this for reasons.

What's the fastest way to tell how many separate instances of the same inventory item are attached to the same owner?
User avatar
Nash
 
 
Posts: 17434
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: "How do I ZScript?"

Post by Nash »

Vaecrius wrote:I just learned today that if you have multiple different instances of a pickup each call attachtoowner() directly, you'll end up with each of them as a separate entry on printinv
Can you post some code?
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 »

JPL wrote:Is there a reason DropItem.Probability is marked as read-only in base.txt? I tried to modify it from some ZScript (to turn off all enemy drops by setting it to 0) and found I couldn't. I removed the readonly keyword from it in base.txt and it worked fine, are there any negative repercussions to doing so? I assume it was set that way on purpose for some reason. Otherwise I could submit a PR but it's a trivial change...
DropItems are per-class data, not per-item. If you change it, you change it for all instances of a given class. Per-class data should always be considered read-only by a mod.
User avatar
zrrion the insect
Posts: 2411
Joined: Thu Jun 25, 2009 1:58 pm
Location: Time Station 1: Moon of Glendale

Re: "How do I ZScript?"

Post by zrrion the insect »

It sounds like changing it for all instances of a given class is exactly what JPL wants to do though, so why should that sort of thing always be considered read-only?
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 »

The proper way to disable item drops is to replace the class with a non-dropping variant.
But regardless, class data being immutable is something I won't change.
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 »

Nash wrote:
Vaecrius wrote:I just learned today that if you have multiple different instances of a pickup each call attachtoowner() directly, you'll end up with each of them as a separate entry on printinv
Can you post some code?
Summon a bunch of these and let them hit you:

Code: Select all

class parasite:inventory{
	override void touch(actor other){}
	default{
		+rollsprite
		monster;
		speed 4;height 4;radius 4;
		inventory.pickupmessage "A parasite has latched on to you. Check printinv for details.";
	}
	override void postbeginplay(){
		super.postbeginplay();
		speed=random(1,8);
		scale=(frandom(0.3,1.3),frandom(0.3,1.3));
		roll=random(-20,20);
	}
	states{
	spawn:
		BAL1 A 10 A_Look();
		wait;
	see:
		BAL1 AB 2 {vel.z+=4;}
		BAL1 ABAB 2;
	see2:
		BAL1 AB 2 A_Chase();
		loop;
	melee:
		BAL1 CDE 3;
		BAL1 A 0{
			if(target&&!target.bkilled&&target.health>0){
				AttachToOwner(target);
				target.A_Log(string.format("\cg%s",pickupmessage()),true);
			}
		}goto see;
	}
}
EDIT: Added some randomization for the appearance of each one to show that when you try to drop one, it's the same one that had attached itself to you and that its variable settings remain intact.
User avatar
JPL
 
 
Posts: 523
Joined: Mon Apr 09, 2012 12:27 pm
Contact:

Re: "How do I ZScript?"

Post by JPL »

Graf Zahl wrote:But regardless, class data being immutable is something I won't change.
That makes sense.
Graf Zahl wrote:The proper way to disable item drops is to replace the class with a non-dropping variant.
This is what I was trying to avoid... I don't want to have to include a ShotgunGuy, ChaingunGuy etc replacement because other mods could replace those, when all I want is for them not to drop weapon pickups. Is that my only option?
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 »

Those mods might well rely on the existing dropping behaviour for other functions, so if you changed it upstream like that you'd break those mods.

This sort of guessing-game for the sake of compatibility with other possible-but-unascertained mods is a game no one wins.
Locked

Return to “Scripting”