DropInventory (ZScript)
Inventory DropInventory (Inventory item, int amt = 1)
Usage
Drops an item to the ground by the calling actor. In contrast to A_DropItem, this drops an actual instance of an item from the actor's inventory rather than spawn a new item to imitate dropping.
To be dropped, the item needs to have an owner. This owner does not necessarily need to be the calling actor itself. Items which have the INVENTORY.UNDROPPABLE or INVENTORY.UNTOSSABLE flags set cannot be dropped, as well as items which lack the Spawn state. The number of samples the dropped item could contain cannot be more than what the owner has in their inventory of the item.
Note: what is explained above is the default behavior, a behavior which can be altered through the virtual function CreateTossable. |
A dropped item will have its NOGRAVITY flag explicitly cleared, and will no longer count towards the map's statistics.
Parameters
- Inventory item
- The item to drop. This is a pointer to the item.
- int amt
- The number of samples the dropped item contains.
Return value
The function returns a pointer to the item if it was dropped successfully, otherwise it returns null.
Examples
The killer of this archvile drops an energy cell that is worth 20 ammo from their inventory.
class ExArchvile : Archvile { override void Die (Actor source, Actor inflictor, int dmgflags, Name MeansOfDeath) { Super.Die(source, inflictor, dmgflags, MeansOfDeath); if (source) { Inventory drop = source.FindInventory("Cell"); if (drop) { source.DropInventory(drop, 20); } } } }
ZScript definition
Note: The ZScript definition below is for reference and may be different in the current version of GZDoom.The most up-to-date version of this code can be found on GZDoom GitHub. |
Inventory DropInventory (Inventory item, int amt = 1)
{
Inventory drop = item.CreateTossable(amt);
if (drop == null) return NULL;
drop.ClearLocalPickUps();
drop.bNeverLocal = true;
drop.SetOrigin(Pos + (0, 0, 10.), false);
drop.Angle = Angle;
drop.VelFromAngle(5.);
drop.Vel.Z = 1.;
drop.Vel += Vel;
drop.bNoGravity = false; // Don't float
drop.ClearCounters(); // do not count for statistics again
drop.OnDrop(self);
return drop;
}