[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.

[ZScript] "Monsters Droppers"

Postby Ac!d » Sat Aug 01, 2020 3:23 am

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 allExpand view
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;
   }
}
User avatar
Ac!d
Perfection is a way, not an end. - Korean Proverb
 
Joined: 02 Apr 2019
Discord: Acid_Citric#2732

Re: [ZScript] "Monsters Droppers"

Postby Jarewill » Sat Aug 01, 2020 9:28 am

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 allExpand view
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.
Jarewill
 
 
 
Joined: 21 Jul 2019

Re: [ZScript] "Monsters Droppers"

Postby Ac!d » Sat Aug 01, 2020 11:58 pm

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

Code: Select allExpand view
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;
   }
}
User avatar
Ac!d
Perfection is a way, not an end. - Korean Proverb
 
Joined: 02 Apr 2019
Discord: Acid_Citric#2732


Return to Scripting

Who is online

Users browsing this forum: No registered users and 0 guests