[ZScript] "Monsters Droppers"

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
User avatar
Ac!d
Posts: 345
Joined: Tue Apr 02, 2019 5:13 am
Location: France

[ZScript] "Monsters Droppers"

Post by Ac!d »

I would like to make my mod compatible with customs monsters pack, but I would like to make a script which work like this :
- If the monster killed is a Zombieman or a inherited actor, he will drop a clip but if he's not, he will drop something else.

Code: Select all

Class ClipDrop : CustomInventory replaces Clip
{
	Default {}
	States
	{
	Spawn:
		TNT1 A 0 NoDelay
		{
			If(invoker.bTOSSED) // Credits
				Return ResolveState("Drop.Weapon"); // to
				Return ResolveState(Null); // SanyaWaffles
		}
		TNT1 A 0 A_SpawnItem("Clip");
		Stop;
	Drop.Weapon:
		TNT1 A 0
		{
			If( ... ) // What should I wrote ?
			{ A_DropItem("Clip"); } // For Zombieman only
			Else
			{ A_DropItem("Shell",4,256); } // Drop 4 Shells if the monster is not a Zombieman.
		}
		Stop;
	}
}
Jarewill
 
 
Posts: 1759
Joined: Sun Jul 21, 2019 8:54 am

Re: [ZScript] "Monsters Droppers"

Post by Jarewill »

From what I understand, you are trying to make an item drop only when dropped by a certain enemy, right?
If so, then the SpecialDropAction virtual function is what you need for that.
For example:

Code: Select all

Class DropChooser : Inventory
{
    Override bool SpecialDropAction(Actor dropper)
    {
        If(dropper is "Zombieman"){A_DropItem("ClipBox");} //If actor that dropped the item is a zombieman (or derived), drop a clip box
        Else If(dropper is "ShotgunGuy"){A_DropItem("ShellBox");} //If actor is a shotgunguy (or derived), drop a shell box
        Return 1; //Destroy the item if it was dropped at all
    }
}
You can put this override instead of the "Drop.Weapon" state and the bTOSSED check, as it will remove the item if it was dropped.
User avatar
Ac!d
Posts: 345
Joined: Tue Apr 02, 2019 5:13 am
Location: France

Re: [ZScript] "Monsters Droppers"

Post by Ac!d »

Thank you Jarewill, I've improved your code to make it compatible with monsters pack such as KriegslandEnemies.

Code: Select all

Class ClipDropChooser : Inventory replaces Clip
{
    Override bool SpecialDropAction(Actor dropper)
    {
        If(dropper is "Zombieman"){ A_DropItem("Clip"); } //If actor that dropped the item is a zombieman (or derived)
        Else { A_DropItem("ClipBox",25,256); }
        Return 1; //Destroy the item if it was dropped at all
    }
    States
    {
    Spawn:
        TNT1 A 0 NoDelay
        {
            If(invoker.bTOSSED)
                { A_SpawnItem("ClipDropChooser"); }
            Else
                { A_SpawnItem("Clip"); }
        }
        Stop;
   }
}
Post Reply

Return to “Scripting”