"How do I ZScript?"

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!
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
Ed the Bat
Posts: 3060
Joined: Thu May 03, 2012 1:18 pm
Location: Maryland, US

Re: "How do I ZScript?"

Post by Ed the Bat »

I'd like to change the music that a level will play. Like, if I have this:

Code: Select all

class MusicHandler : StaticEventHandler
{
	override void WorldLoaded(WorldEvent e) 
	{
		S_ChangeMusic("",0,true,true);
	}
}
...this should mute the music for the level. It does, but I still hear the first note or two of the music before it gets muted. Sounds crappy. Is there a better way to do this?
User avatar
Major Cooke
Posts: 8221
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: GZBoomer Town

Re: "How do I ZScript?"

Post by Major Cooke »

You mean when playing midi?
User avatar
Ed the Bat
Posts: 3060
Joined: Thu May 03, 2012 1:18 pm
Location: Maryland, US

Re: "How do I ZScript?"

Post by Ed the Bat »

Would something be different if the song wasn't MIDI?
User avatar
Major Cooke
Posts: 8221
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: GZBoomer Town

Re: "How do I ZScript?"

Post by Major Cooke »

No idea but last I checked the SetMusic function in ACS doesn't have this issue. I wonder, is it reproducable in ACS as it is with S_ChangeMusic?
User avatar
Ed the Bat
Posts: 3060
Joined: Thu May 03, 2012 1:18 pm
Location: Maryland, US

Re: "How do I ZScript?"

Post by Ed the Bat »

I did used to have this issue when I was using ACS SetMusic. I just always presumed this was because the OPEN script (all of ACS, really) didn't run until after the music began playing.
User avatar
Major Cooke
Posts: 8221
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: GZBoomer Town

Re: "How do I ZScript?"

Post by Major Cooke »

Hmmm. You use regular FMOD or something else? I use fluidsynth so I don't get this sort of issue.
User avatar
Jaxxoon R
Posts: 772
Joined: Sun May 04, 2014 7:22 pm

Re: "How do I ZScript?"

Post by Jaxxoon R »

Is there a right way to clip an actor's angle to within a certain range, based off the angle of its master? I've been toying with head tracking using multipart 3D monsters, and so far I've gotten a quick and dirty version that can return the creature's head to a neutral position if it tries to follow the player out of its range or if it loses the player from its line-of-sight. Only problem is that it tends to jitter at certain angles for whatever reason.

Code: Select all

		See:
			JAXX A 1 {
				A_Warp(AAPTR_MASTER,0,0,37,0,WARPF_INTERPOLATE|WARPF_USECALLERANGLE|WARPF_NOCHECKPOSITION);
				A_Facetarget(20,20,0,0,FAF_TOP,-10);
				if(self.angle<master.angle-90||self.angle>master.angle+90)
					{
					return ResolveState("DontSee");
					}
				return ResolveState(null);
			}
			JAXX A 0 A_JumpIfTargetInLOS("See",90);
		DontSee:
			JAXX A 1 {
				A_Warp(AAPTR_MASTER,0,0,37,0,WARPF_INTERPOLATE|WARPF_USECALLERANGLE|WARPF_NOCHECKPOSITION);
				if(self.angle<master.angle-1||self.angle>master.angle+1)
					{
					A_SetAngle(master.angle);
					}
				}
			JAXX A 0 A_JumpIfTargetInLOS("See",90);
			Loop;
I've tried a few other ways of doing this, but they each seem to have their own problems. One of which was overriding Tick with this instead:

Code: Select all

if(self.angle<master.angle-80)
					{
					A_SetAngle(master.angle-80);
					}
		if(self.angle>master.angle+80)
					{
					A_SetAngle(master.angle+80);
					}
But that just caused the head to be clamped incorrectly, where regardless of which end of the range the head passed, it was set to the same angle (-80?). I've been at this on and off all this evening and I'm about all out of ideas.
User avatar
Ed the Bat
Posts: 3060
Joined: Thu May 03, 2012 1:18 pm
Location: Maryland, US

Re: "How do I ZScript?"

Post by Ed the Bat »

Major Cooke wrote:Hmmm. You use regular FMOD or something else? I use fluidsynth so I don't get this sort of issue.
I just tried a fluidsynth setup, and it takes about a second to begin playing music. That may explain why you don't hear any music playing before it gets changed/muted.
User avatar
Major Cooke
Posts: 8221
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: GZBoomer Town

Re: "How do I ZScript?"

Post by Major Cooke »

Yeah, takes about half a second for me. But it utterly stops all music and prevents any leftovers from playing, so I guess it's FMOD's fault.
Jaxxoon R wrote:Is there a right way to clip an actor's angle to within a certain range, based off the angle of its master? I've been toying with head tracking using multipart 3D monsters, and so far I've gotten a quick and dirty version that can return the creature's head to a neutral position if it tries to follow the player out of its range or if it loses the player from its line-of-sight. Only problem is that it tends to jitter at certain angles for whatever reason.
The reason why the comparison in your second code piece isn't working is because you're comparing the raw angle instead of the relative. To do that, try something like this.

NOTE: I haven't been able to test the code so it might not work right off the bat. You'll probably have to play around with it. I.e. I don't know if the Normalized180 is actually necessary but I used it in a piece of code before and it fixed a certain issue.

Code: Select all

double delta = -deltaangle(Normalized180(angle), Normalized180(master.angle))
double anglimit = 80; //could just define this as a constant in the actor global scope.
if (abs(delta) > anglimit)
{
	if (delta > 0)	angle  = master.angle - anglimit;
	else			angle = master.angle + anglimit;
}
User avatar
Jaxxoon R
Posts: 772
Joined: Sun May 04, 2014 7:22 pm

Re: "How do I ZScript?"

Post by Jaxxoon R »

Thanks, I think it works now.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49252
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: "How do I ZScript?"

Post by Graf Zahl »

Ed the Bat wrote:I'd like to change the music that a level will play. Like, if I have this:

Code: Select all

class MusicHandler : StaticEventHandler
{
	override void WorldLoaded(WorldEvent e) 
	{
		S_ChangeMusic("",0,true,true);
	}
}
...this should mute the music for the level. It does, but I still hear the first note or two of the music before it gets muted. Sounds crappy. Is there a better way to do this?

You may try as much as you like - the music gets started BEFORE the events are being processed and runs asynchronously so any result you get is entirely random. FMod acts different from OpenAL, MIDI different from streaming formats and so on, and MIDI even differs between synths. The only safe way to ensure that no music plays at all is through MAPINFO.
User avatar
Ed the Bat
Posts: 3060
Joined: Thu May 03, 2012 1:18 pm
Location: Maryland, US

Re: "How do I ZScript?"

Post by Ed the Bat »

That's disappointing, since MAPINFO is so static. I wouldn't be able to, say, have the music chosen at random, or run conditional checks to see what actors exist or what mods are loaded.

Guess I'll keep doing this the hard way with a batch file and dozens of separate wads.
User avatar
ZZYZX
 
 
Posts: 1384
Joined: Sun Oct 14, 2012 1:43 am
Location: Ukraine

Re: "How do I ZScript?"

Post by ZZYZX »

You can disable the music in MAPINFO and enable it with ZScript. What Graf is saying is that you don't want to rely on tic-to-tic precision. If you want that, you might want to use sounds, not music.
User avatar
Ed the Bat
Posts: 3060
Joined: Thu May 03, 2012 1:18 pm
Location: Maryland, US

Re: "How do I ZScript?"

Post by Ed the Bat »

What I really wanted was a more elegant and automated way to blank out songs that I hate, so I wouldn't have to rely so much on batch files. Hearing a note before I begin playing makes me feel sloppy.

Anyhow, new question... is there a way to read the contents of a player's StartItem list?
User avatar
kodi
 
 
Posts: 1361
Joined: Mon May 06, 2013 8:02 am

Re: "How do I ZScript?"

Post by kodi »

I have a bullet puff that spawns a 3d model energy shield effect when it hits certain actors.

How do I get the Z angle between the puff and the center of the victim(it's Tracer) and adjust the value to set it as the shield actors pitch, making it face the puff?

Code: Select all

atan2(tracer.z+(tracer.height*0.5)-self.z,1.0)
is as far as I've stumbled myself.[/s]
Nevermind; I'm a dummy. Solved it.

Return to “Scripting”