Destroy "Bulletpuff" on Liquid Terrain?

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!)
Post Reply
MrJohnny
Posts: 212
Joined: Fri Aug 05, 2016 8:41 am

Destroy "Bulletpuff" on Liquid Terrain?

Post by MrJohnny »

Is there a way to completely avoid spawning any puff actors once a hitscan comes into contact with liquid terrain?
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: Destroy "Bulletpuff" on Liquid Terrain?

Post 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();
    }
} 
Last edited by Matt on Tue Nov 06, 2018 11:32 am, edited 5 times in total.
MrJohnny
Posts: 212
Joined: Fri Aug 05, 2016 8:41 am

Re: Destroy "Bulletpuff" on Liquid Terrain?

Post 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.
User avatar
Apeirogon
Posts: 1606
Joined: Mon Jun 12, 2017 12:57 am

Re: Destroy "Bulletpuff" on Liquid Terrain?

Post 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.
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: Destroy "Bulletpuff" on Liquid Terrain?

Post by Matt »

I think my edits to my post should make it runnable, though I haven't tested it yet.
MrJohnny
Posts: 212
Joined: Fri Aug 05, 2016 8:41 am

Re: Destroy "Bulletpuff" on Liquid Terrain?

Post 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();
    }
}
User avatar
Apeirogon
Posts: 1606
Joined: Mon Jun 12, 2017 12:57 am

Re: Destroy "Bulletpuff" on Liquid Terrain?

Post by Apeirogon »

Add () between "postbeginplay" and "{"
MrJohnny
Posts: 212
Joined: Fri Aug 05, 2016 8:41 am

Re: Destroy "Bulletpuff" on Liquid Terrain?

Post 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;
    }
}
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: Destroy "Bulletpuff" on Liquid Terrain?

Post 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.
MrJohnny
Posts: 212
Joined: Fri Aug 05, 2016 8:41 am

Re: Destroy "Bulletpuff" on Liquid Terrain?

Post 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:
User avatar
Player701
 
 
Posts: 1710
Joined: Wed May 13, 2009 3:15 am
Graphics Processor: nVidia with Vulkan support
Contact:

Re: Destroy "Bulletpuff" on Liquid Terrain?

Post 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".
MrJohnny
Posts: 212
Joined: Fri Aug 05, 2016 8:41 am

Re: Destroy "Bulletpuff" on Liquid Terrain?

Post 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:
User avatar
Mikk-
Posts: 2274
Joined: Tue Jun 30, 2009 1:31 pm

Re: Destroy "Bulletpuff" on Liquid Terrain?

Post by Mikk- »

You need to check if the puff is actually hitting the ground
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: Destroy "Bulletpuff" on Liquid Terrain?

Post 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)
MrJohnny
Posts: 212
Joined: Fri Aug 05, 2016 8:41 am

Re: Destroy "Bulletpuff" on Liquid Terrain?

Post 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:
Post Reply

Return to “Scripting”