Page 1 of 1

Destroy "Bulletpuff" on Liquid Terrain?

Posted: Sat Nov 03, 2018 4:53 pm
by MrJohnny
Is there a way to completely avoid spawning any puff actors once a hitscan comes into contact with liquid terrain?

Re: Destroy "Bulletpuff" on Liquid Terrain?

Posted: Sat Nov 03, 2018 11:14 pm
by Matt
Here's the liquid floor checking code that I think I took from Nash (and apolgies to the actual source if not).

Code: Select all

version "3.6"

struct MiscFunctions play{
    //seeing if you're standing on a liquid texture
    static const string lq[]={
        "MFLR8_4","MFLR8_2", //I think some of these are snake floors or sand
        "SFLR6_1","SFLR6_4", //or something - the original code is for putting out fires
        "SFLR7_1","SFLR7_4", //please delete as appropriate
        "FWATER1","FWATER2","FWATER3","FWATER4",
        "BLOOD1","BLOOD2","BLOOD3",
        "SLIME1","SLIME2","SLIME3","SLIME4",
        "SLIME5","SLIME6","SLIME7","SLIME8"
    };
    static bool CheckLiquidTexture(actor caller){
        int lqlength=lq.size();
        let fp=caller.floorpic;
        for(int i=0;i<lqlength;i++){
            TextureID tx=TexMan.CheckForTexture(lq[i],TexMan.Type_Flat);
            if (tx&&fp==tx){
                return true;
            }
        }
        return false;
    }
}

//Then you can put something like:

class BulletSplashless:BulletPuff replaces BulletPuff{
    override void postbeginplay{
        if(MiscFunctions.CheckLiquidTexture(self)&&pos.z-floorz<4){
            destroy();
            return;
        }
        super.postbeginplay();
    }
} 

Re: Destroy "Bulletpuff" on Liquid Terrain?

Posted: Sun Nov 04, 2018 4:21 am
by MrJohnny
Sorry to be a bother, but would you mind fixing this up into something that's functional? I can make things work if I at least have an example of how to put this to use. I tried putting it together, but the zscript format is just something I'm not accustomed to.

Re: Destroy "Bulletpuff" on Liquid Terrain?

Posted: Mon Nov 05, 2018 7:57 am
by Apeirogon
Create file with name zscript, put in in the root of the pack and copy paste in it both code block.

But you must put first one in definition of some class.
Like

Code: Select all

class thing
{
    first block of a code here
}
so that gzdoom load it properly.

Re: Destroy "Bulletpuff" on Liquid Terrain?

Posted: Mon Nov 05, 2018 1:17 pm
by Matt
I think my edits to my post should make it runnable, though I haven't tested it yet.

Re: Destroy "Bulletpuff" on Liquid Terrain?

Posted: Mon Nov 05, 2018 3:23 pm
by MrJohnny
Thanks, I wasn't sure what to write at the beginning of that first block of code. However, it throws this error.

Code: Select all

Script error, "zscript.txt:ZSCRIPT" line 30: 
Unexpected '{'
Expecting ';' or ','
I marked line 30 for the sake of convenience. Not sure what the problem is.

Code: Select all

class BulletSplashless:BulletPuff replaces BulletPuff{
    override void postbeginplay{                             // LINE 30
        if(MiscFunctions.CheckLiquidTexture(self)){
            destroy();
            return;
        }
        super.postbeginplay();
    }
}

Re: Destroy "Bulletpuff" on Liquid Terrain?

Posted: Mon Nov 05, 2018 3:48 pm
by Apeirogon
Add () between "postbeginplay" and "{"

Re: Destroy "Bulletpuff" on Liquid Terrain?

Posted: Mon Nov 05, 2018 4:58 pm
by MrJohnny
Alright, solved that problem. Now there's a couple of other little boogers.

Code: Select all

Script error, "zscript.txt:ZSCRIPT" line 15:
self used outside of a member function
Script error, "zscript.txt:ZSCRIPT" line 17:
Unknown identifier 'lqlength'

Code: Select all

struct MiscFunctions play{
    //seeing if you're standing on a liquid texture
    static const string lq[]={
        "MFLR8_4","MFLR8_2", //I think some of these are snake floors or sand
        "SFLR6_1","SFLR6_4", //or something - the original code is for putting out fires
        "SFLR7_1","SFLR7_4", //please delete as appropriate
        "FWATER1","FWATER2","FWATER3","FWATER4",
        "BLOOD1","BLOOD2","BLOOD3",
        "SLIME1","SLIME2","SLIME3","SLIME4",
        "SLIME5","SLIME6","SLIME7","SLIME8"
    };
    static bool CheckLiquidTexture(actor caller){
        int lqlength=lq.size();                  // LINE 15
        let fp=caller.floorpic;
        for(int i=0;i<lqlength;i++){             // LINE 17
            TextureID tx=TexMan.CheckForTexture(lq[i],TexMan.Type_Flat);
            if (tx&&fp==tx){
                return true;
            }
        }
        return false;
    }
}

Re: Destroy "Bulletpuff" on Liquid Terrain?

Posted: Mon Nov 05, 2018 8:23 pm
by Matt
Possibly try replacing lq.size() with MiscFunctions.lq.size()?

I don't see why that would be required but it's the only thing I can imagine being wrong.

Re: Destroy "Bulletpuff" on Liquid Terrain?

Posted: Mon Nov 05, 2018 9:54 pm
by MrJohnny
Darn, it just keeps throwing errors. Here's what it read this time.

Code: Select all

Script error, "zscript.txt:ZSCRIPT" line 18:
self used outside of a member function
Script error, "zscript.txt:ZSCRIPT" line 19:
Unknown identifier 'tx'
Script error, "zscript.txt:ZSCRIPT" line 19:
Unknown identifier 'tx'
This is starting to get a little lengthy, so I'll start putting the code in a spoiler.
Spoiler:

Re: Destroy "Bulletpuff" on Liquid Terrain?

Posted: Tue Nov 06, 2018 6:37 am
by Player701
This looks like a bug to me, since lq is declared within the same type it is used from. I've filed a bug report. Your code can be fixed by changing "lq" in line 18 to "MiscFunctions.lq".

Re: Destroy "Bulletpuff" on Liquid Terrain?

Posted: Tue Nov 06, 2018 10:26 am
by MrJohnny
Thank you, it finally works now. Only one problem remains. The puff actors don't spawn on liquid terrain as expected, but if a hitscan travels above a liquid texture, the puff actor doesn't spawn on any walls that are connected to sectors with liquid textures defined. Here are some screenshots to demonstrate the problem.
Spoiler:

Re: Destroy "Bulletpuff" on Liquid Terrain?

Posted: Tue Nov 06, 2018 10:38 am
by Mikk-
You need to check if the puff is actually hitting the ground

Re: Destroy "Bulletpuff" on Liquid Terrain?

Posted: Tue Nov 06, 2018 11:32 am
by Matt
Mikk- wrote:You need to check if the puff is actually hitting the ground
Edited again. The 4 is because I think puffs spawn just a little behind their impact point and I don't know off the top of my head how much that would affect this.

(didn't touch the thing about the member class problem though, and I agree with Player701 that this looks like a GZDoom bug)

Re: Destroy "Bulletpuff" on Liquid Terrain?

Posted: Tue Nov 06, 2018 12:35 pm
by MrJohnny
Yes! That works perfectly! Thanks for all your help, folks!
Matt wrote:The 4 is because I think puffs spawn just a little behind their impact point and I don't know off the top of my head how much that would affect this.
The puff actors would actually still occasionally spawn even after your edit. But I believe I fixed it by replacing the 4 with 8.

I'm going to post the resulting code I'm using just in case any curious browsers want to take it for a spin.
Spoiler: