Fluid Motion [Updated 1/2/22]

Post your example zscripts/ACS scripts/etc here.
Forum rules
The Projects forums are only for projects. If you are asking questions about a project, either find that project's thread, or start a thread in the General section instead.

Got a cool project idea but nothing else? Put it in the project ideas thread instead!

Projects for any Doom-based engine (especially 3DGE) are perfectly acceptable here too.

Please read the full rules for more details.
Hey Doomer
Posts: 283
Joined: Sat Sep 25, 2021 3:38 am

Fluid Motion [Updated 1/2/22]

Post by Hey Doomer »

ZDoom can have various 3D water effects that are more or less convincing, which of course don't affect existing maps. Otherwise fluids are flat and somewhat disappointing textures. So this is my minimalist take to improve that.

Zscript:

Code: Select all

class fm_PostProcessor : LevelPostProcessor
{
	// add sector tags by flat name
	protected void Apply(Name checksum, String mapname)
	{
		Array<string> fluids = {
			"NUKAGE1",
			"NUKAGE2",
			"NUKAGE3",
			"FWATER1",
			"FWATER2",
			"FWATER3",
			"FWATER4"
		};
		int start = Cvar.FindCVar("fm_start").GetInt();
		int FLOOR = 0;
		TexMan texture;
		for (int i = 0; i < Level.Sectors.Size(); i++)
		{
			textureid floorid = Level.Sectors[i].GetTexture(FLOOR);
			if (fluids.Find(texture.GetName(floorid)) != fluids.Size())
			{
				AddSectorTag(i, start);
				start++;
			}
		}
		Cvar.FindCVar("fm_end").SetInt(start);
	}
}
The purpose above is to attach a different tag to each sector with a fluid flat and store the tag range in cvars. I didn't see a simpler way to do this on an existing map. Note that fm_end isn't really the end of the tag sequence but one beyond, which is deliberate. I also only add this to NUKAGE and FWATER textures, which can be changed by using different textures in the Array declaration. Slime is, well, slimy and not noisy. I suppose blood is another matter, but that would need a different sound. That's possible but beyond this minimalist scope.

ACS:

Code: Select all

script "fluidmotion" ENTER
{
    // cvars
    int fm_start = GetCVar("fm_start");
    int fm_end = GetCVar("fm_end");

    for (int tag = fm_start; tag < fm_end; tag++)
    {
        if (Random(0,1) == 0)
        {
            SoundSequenceOnSector(tag, "FluidMotion0", SECSEQ_INTERIOR);
        }
        else
        {
            SoundSequenceOnSector(tag, "FluidMotion1", SECSEQ_INTERIOR);
        }
        Floor_Waggle(tag, Random(16,64), Random(4,16), 0, 0);
    }
}
All this does is loop through the range of affected tags and add a sound sequence and Floor_Waggle to the sector. Floor_Waggle is silent and doesn't play platform/floor up and down sounds. That means a sound sequence can be applied to these sectors. This isn't fancy at all. I chose two small, random water sounds.

SNDSEQ:

Code: Select all

:FluidMotion0
	volumerand 0 30
	playuntildone fm_splash
	delayrand 17 47
	playuntildone fm_pour
	delayrand 17 47
	restart
end

:FluidMotion1
	volumerand 0 30
	playuntildone fm_pour
	delayrand 17 47
	playuntildone fm_splash
	delayrand 17 47
	restart
end
This crudely introduces random elements. It should work on ZDoom water 3D floor effects, too. I suppose it will break if a fluid texture rises and flats change (as in the small chainsaw courtyard in E1M2), since the ACS only fires once.

Update 1/2/22
Spoiler:

Return to “Script Library”