"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!)
- Kinsie
- Posts: 7402
- Joined: Fri Oct 22, 2004 9:22 am
- Graphics Processor: nVidia with Vulkan support
- Location: MAP33
- Contact:
Re: "How do I ZScript?"
Has anyone looked into removing that thing where sound gets disabled when the time freeze powerup is active? I was able to disable the pausing of music, but came up blank on everything else.
Re: "How do I ZScript?"
Heh, thanks Gutawer... I'll give that a try.
I suspected the solution was more complicated than previously, but it would have taken me a good while to figure that out.
I suspected the solution was more complicated than previously, but it would have taken me a good while to figure that out.
- cotton_disciple
- Posts: 55
- Joined: Fri Jul 03, 2015 4:22 am
- Location: Russian Federation
Re: "How do I ZScript?"
How to get powerup.duration as integer for statusbar?
EDIT: found. use something like InvulnerabilitySphere
EDIT: found. use something like InvulnerabilitySphere
Code: Select all
CPlayer.mo.GetEffectTicsForItem(powerupgiver)
Last edited by cotton_disciple on Thu May 18, 2017 11:21 am, edited 2 times in total.
- 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?"
How do you search for a specific item in the player's inventory and interact with its properties?
(I think there was an answer for this upthread but I recall that answer involving a rather expensive-looking ThinkerIterator)
(I think there was an answer for this upthread but I recall that answer involving a rather expensive-looking ThinkerIterator)
Re: "How do I ZScript?"
Code: Select all
<actor>.FindInventory("class name")
Re: "How do I ZScript?"
In Zscript Its seems S_PauseSound used to pause the sound while S_S_ResumeSound(false) used to resume the music/sound effect ?Kinsie wrote:Has anyone looked into removing that thing where sound gets disabled when the time freeze powerup is active? I was able to disable the pausing of music, but came up blank on everything else.
I unable to confirm this.
- Kinsie
- Posts: 7402
- Joined: Fri Oct 22, 2004 9:22 am
- Graphics Processor: nVidia with Vulkan support
- Location: MAP33
- Contact:
Re: "How do I ZScript?"
Removing those lines disabled the music pausing. The sound remained frozen.Jitan wrote:In Zscript Its seems S_PauseSound used to pause the sound while S_S_ResumeSound(false) used to resume the music/sound effect ?Kinsie wrote:Has anyone looked into removing that thing where sound gets disabled when the time freeze powerup is active? I was able to disable the pausing of music, but came up blank on everything else.
I unable to confirm this.
Re: "How do I ZScript?"
Im trying to make a dynamic crosshair, that reacts when player shoots.
1. Is there a way to make it react to A_GunFlash of any weapon?
2. Is there some other way to know when player actor is shooting? Like when player's sprite gets illuminated by A_Gunflash?
3. If neither are possible, then how about making it react when player's weapon enters a "Fire"/"Hold" state? In which case, how do i point InStateSequence to player's current weapon actor? Like
edit: it also seems that InStateSequence can't be used withing statusbar scripts because of the scope 
1. Is there a way to make it react to A_GunFlash of any weapon?
2. Is there some other way to know when player actor is shooting? Like when player's sprite gets illuminated by A_Gunflash?
3. If neither are possible, then how about making it react when player's weapon enters a "Fire"/"Hold" state? In which case, how do i point InStateSequence to player's current weapon actor? Like
Code: Select all
if ( blablabla && Player.CurrentWeapon.InStateSequence(Player.CurrentWeapon.CurState, Player.CurrentWeapon.ResolveState("Fire") ) )
{
do some stuff
}

Re: "How do I ZScript?"
Something like this should do what you want:
Basically, weapon sprites aren't actually tied to the weapon that uses the sprites, but instead the PSprite layer on the player. In this case, we look for PSprite.FLASH which only exists as a layer if the gun is in any flash state. If you want to be very explicit and test only for the Flash state, you could do:
Testing firing on the actual gun layer itself (which I'd recommend over testing the flash layer, as not all weapons actually use flashes) would go like this:
Code: Select all
if (CPlayer.FindPSprite(PSprite.FLASH)) {
// flash is active since the PSprite exists
}
Code: Select all
let flashPSprite = CPlayer.FindPSprite(PSprite.FLASH);
if (CPlayer.ReadyWeapon && flashPSprite &&
CPlayer.ReadyWeapon.InStateSequence(flashPSprite.CurState, CPlayer.ReadyWeapon.ResolveState("Flash"))) {
// do whatever
}
Code: Select all
let weapPSprite = CPlayer.FindPSprite(PSprite.WEAPON);
if (CPlayer.ReadyWeapon && weapPSprite &&
CPlayer.ReadyWeapon.InStateSequence(weapPSprite.CurState, CPlayer.ReadyWeapon.ResolveState("Fire"))) {
// do whatever
}
Re: "How do I ZScript?"
thanks a lot, looks like truly everything is possible with zscript! That seems to be it, but now i have another problem, which is
so how would i go about using InStateSequence or "play" functions in general inside statusbar scripts, which use, as i understand, "ui" scope? Using "clearscope" or "play" before function breaks "CPlayer" and makes that function unaccessable by the main statusbar script.
Code: Select all
Can't call play function InStateSequence from ui context
Re: "How do I ZScript?"
Oops, looks like I didn't do nearly enough testing there, sorry. I kinda just wrote the code in a play scope and then changed everything over to CPlayer once I noticed you were doing this in a statusbar, and I guess that that doesn't actually work X_X
Unfortunately though, I don't know how to get around that, sorry
Unfortunately though, I don't know how to get around that, sorry

Re: "How do I ZScript?"
That's probably an oversight in GZDoom since informational functions aren't supposed to be play... (idk)
Re: "How do I ZScript?"
bah, i also tried to have a separate play class do "InStateSequence" checking and then returning the result to some global variable, but then i got the similar error with "Get" when trying to retrieve that variable inside statusbar class...
Re: "How do I ZScript?"
Random question: in ACS, it's possible to print a keybinding to the screen by Print/StrParam-ing a string with a "k:" prefix, e.g. Print(k:"+use") will print "E" if I have Use bound to the 'E' key.
Is there a ZScript equivalent for this? Trying to show something like this on the HUD, but I can't find anything relevant in wiki-or-forum-land.
[EDIT] Figured it out. Here, have a handy function:
Plunk this in a class or make a static version somewhere, and there you go.
Is there a ZScript equivalent for this? Trying to show something like this on the HUD, but I can't find anything relevant in wiki-or-forum-land.
[EDIT] Figured it out. Here, have a handy function:
Code: Select all
/*
* Quick function to get a key name from a command.
*/
string GetKeyName(string command) {
int k1, k2;
[k1, k2] = Bindings.GetKeysForCommand(command);
return KeyBindings.NameKeys(k1, k2);
}
Re: "How do I ZScript?"
megaedit No29:
So, by the end of the day i figured out how to spawn actors using event handlers, and how to circumwent the unability to read an ever changing variable from statusbar script, but now i have a following problem, this script ( or rather actor )
crashes the game with "Access Violation" after it prints out the message. Supposedly, doing "player.***" is wrong, but whats the correct way then?
when i throw in a
then it just keeps spamming that message, meaning the "player" is always null, but how is this even possible
edit: comeon guys, i have everything else implemented and just need a bit of help with this last thing
edit2: i think i found out, the correct way is "players[0]"
So, by the end of the day i figured out how to spawn actors using event handlers, and how to circumwent the unability to read an ever changing variable from statusbar script, but now i have a following problem, this script ( or rather actor )
Spoiler:
crashes the game with "Access Violation" after it prints out the message. Supposedly, doing "player.***" is wrong, but whats the correct way then?
when i throw in a
Code: Select all
if (player == null)
{
Console.Printf("Player doesn't exist.");
return;
}
edit: comeon guys, i have everything else implemented and just need a bit of help with this last thing
edit2: i think i found out, the correct way is "players[0]"