"How do I ZScript?"
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!)
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!)
Re: "How do I ZScript?"
"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>).
-
- Posts: 33
- Joined: Wed Mar 16, 2016 4:19 pm
Re: "How do I ZScript?"
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>).
It worked! Thanks"Return ResolveState" instead of "Goto" statements
- 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?"
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.
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:
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.
Code: Select all
native static vector3, int G_PickDeathmatchStart();
native static vector3, int G_PickPlayerStart(int pnum, int flags = 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
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.
Re: "How do I ZScript?"
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!".
Currently attempting to access variables inside states just gives a "Self pointer used in ambiguous context; VM execution may abort!".
Re: "How do I ZScript?"
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);
...
}
}
Re: "How do I ZScript?"
Thanks dude, managed to figure it out just as soon as you posted.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); ... } }
Re: "How do I ZScript?"
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...
- 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?"
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?
What's the fastest way to tell how many separate instances of the same inventory item are attached to the same owner?
Re: "How do I ZScript?"
Can you post some code?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
- Graf Zahl
- Lead GZDoom+Raze Developer
- Posts: 49056
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: "How do I ZScript?"
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.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...
- 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?"
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?
- Graf Zahl
- Lead GZDoom+Raze Developer
- Posts: 49056
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: "How do I ZScript?"
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.
But regardless, class data being immutable is something I won't change.
- 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?"
Summon a bunch of these and let them hit you:Nash wrote:Can you post some code?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
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;
}
}
Re: "How do I ZScript?"
That makes sense.Graf Zahl wrote:But regardless, class data being immutable is something I won't change.
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?Graf Zahl wrote:The proper way to disable item drops is to replace the class with a non-dropping variant.
- 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?"
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.
This sort of guessing-game for the sake of compatibility with other possible-but-unascertained mods is a game no one wins.