GiveInventory (ScriptUtil)

From ZDoom Wiki
Jump to navigation Jump to search
Note: This function is a static ZScript function. For a non-static, Actor version, see GiveInventory (Actor). For the ACS function of the same name, see GiveInventory.


ScriptUtil

static void GiveInventory(Actor activator, Name type, int amount)

Usage

A static, ZScript-only version of GiveInventory (Actor)/A_GiveInventory. Requires a pointer to the actor that will receive the item. If the pointer is null, the item will instead be given to all players in the game.

Parameters

  • Actor activator
Pointer to the actor that will receive the item. If this is null, the item will be given to all players in the game.
  • Name type
The name of the intended Inventory item class to give. Since this is a Name, using non-existent class names will not cause an error, but it will print a message to the console, informing that this item doesn't exist.
If the provided class name is not an Inventory class, the function will also print a console message.
  • int amount
The amount of the specified item to give.

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.


	static void GiveInventory (Actor activator, Name type, int amount)
	{
		if (amount <= 0 || type == 'none')
		{
			return;
		}
		if (type == 'Armor')
		{
			type = "BasicArmorPickup";
		}
		Class<Actor> info = type;
		if (info == NULL)
		{
			Console.Printf ("GiveInventory: Unknown item type %s.\n", type);
		}
		else if (!(info is 'Inventory'))
		{
			Console.Printf ("GiveInventory: %s is not an inventory item.\n", type);
		}
		else if (activator == NULL)
		{
			for (int i = 0; i < MAXPLAYERS; ++i)
			{
				if (playeringame[i])
					players[i].mo.GiveInventory((class<Inventory>)(info), amount);
			}
		}
		else
		{
			activator.GiveInventory((class<Inventory>)(info), amount);
		}
	}

Examples

Nuvolachalk.png Note: This article lists no examples. If you make use of this feature in your own project(s) or know of any basic examples that could be shared, please add them. This will make it easier to understand for future authors seeking assistance. Your contributions are greatly appreciated.


See also