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

Post by Kinsie »

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.
D2JK
Posts: 545
Joined: Sat Aug 30, 2014 8:21 am

Re: "How do I ZScript?"

Post by D2JK »

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.
User avatar
cotton_disciple
Posts: 55
Joined: Fri Jul 03, 2015 4:22 am
Location: Russian Federation

Re: "How do I ZScript?"

Post by cotton_disciple »

How to get powerup.duration as integer for statusbar?

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.
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 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)
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")
will give you a pointer to the item.
Jitan
Posts: 44
Joined: Tue Oct 04, 2011 6:32 am

Re: "How do I ZScript?"

Post by Jitan »

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.
In Zscript Its seems S_PauseSound used to pause the sound while S_S_ResumeSound(false) used to resume the music/sound effect ?
I unable to confirm this.
User avatar
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?"

Post by Kinsie »

Jitan wrote:
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.
In Zscript Its seems S_PauseSound used to pause the sound while S_S_ResumeSound(false) used to resume the music/sound effect ?
I unable to confirm this.
Removing those lines disabled the music pausing. The sound remained frozen.
User avatar
vidumec
Posts: 61
Joined: Sat Apr 15, 2017 2:38 am

Re: "How do I ZScript?"

Post by vidumec »

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

Code: Select all

if ( blablabla &&  Player.CurrentWeapon.InStateSequence(Player.CurrentWeapon.CurState, Player.CurrentWeapon.ResolveState("Fire") ) )
{
do some stuff
}
edit: it also seems that InStateSequence can't be used withing statusbar scripts because of the scope :(
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 »

Something like this should do what you want:

Code: Select all

if (CPlayer.FindPSprite(PSprite.FLASH)) {
    // flash is active since the PSprite exists
}
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:

Code: Select all

let flashPSprite = CPlayer.FindPSprite(PSprite.FLASH);
if (CPlayer.ReadyWeapon && flashPSprite &&
    CPlayer.ReadyWeapon.InStateSequence(flashPSprite.CurState, CPlayer.ReadyWeapon.ResolveState("Flash"))) {
	
    // do whatever
}
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

let weapPSprite = CPlayer.FindPSprite(PSprite.WEAPON);
if (CPlayer.ReadyWeapon && weapPSprite &&
    CPlayer.ReadyWeapon.InStateSequence(weapPSprite.CurState, CPlayer.ReadyWeapon.ResolveState("Fire"))) {
	
    // do whatever
}
User avatar
vidumec
Posts: 61
Joined: Sat Apr 15, 2017 2:38 am

Re: "How do I ZScript?"

Post by vidumec »

thanks a lot, looks like truly everything is possible with zscript! That seems to be it, but now i have another problem, which is

Code: Select all

Can't call play function InStateSequence from ui context
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.
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 »

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 :(
User avatar
ZZYZX
 
 
Posts: 1384
Joined: Sun Oct 14, 2012 1:43 am
Location: Ukraine
Contact:

Re: "How do I ZScript?"

Post by ZZYZX »

That's probably an oversight in GZDoom since informational functions aren't supposed to be play... (idk)
User avatar
vidumec
Posts: 61
Joined: Sat Apr 15, 2017 2:38 am

Re: "How do I ZScript?"

Post by vidumec »

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...
User avatar
Xaser
 
 
Posts: 10774
Joined: Sun Jul 20, 2003 12:15 pm
Contact:

Re: "How do I ZScript?"

Post by Xaser »

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:

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);
}
Plunk this in a class or make a static version somewhere, and there you go.
User avatar
vidumec
Posts: 61
Joined: Sat Apr 15, 2017 2:38 am

Re: "How do I ZScript?"

Post by vidumec »

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 )
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;
			}
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]"
Locked

Return to “Scripting”