Meteor 2 Scripting Functions
Inventory
void givePlayerItem(int playerID, string itemName, int amount)
Give items to a player.

Example
if(isServer())
{
    // give all players 1 rifle mag
    for(int i=0; i<getPlayersCount(); i++)
    {
        int playerID = getPlayerAtIndex(i);
        givePlayerItem(playerID, "Rifle Mag", 1);
    }
}

Comments
Pass a negative amount to take items.
Final item counts are clamped between 0 and max specified in base\game\items.ini (depending on game mode)
Can be called from server or client.

See also
getPlayerItemCount resetPlayerItems clampPlayerWeapon

int getPlayerItemCount(int playerID, string itemName)
Get amount of an item a player has.

Example
// show how many rifle mags player has
for(int i=0; i<getPlayersCount(); i++)
{
    int playerID = getPlayerAtIndex(i);
    print(getPlayerName(playerID) + " has " + getPlayerItemCount(playerID, "Rifle Mag") + " rifle mags");
}

See also
givePlayerItem resetPlayerItems

void resetPlayerItems(int playerID, bool mapStartItemsOnly)
Reset a player's items (server only).

Example
if(isServer())
{
    // reset all player loadouts to basics only
    for(int i=0; i<getPlayersCount(); i++)
    {
        int playerID = getPlayerAtIndex(i);
        int playerObjectID = getPlayerObject(playerID);
        resetPlayerItems(playerID, false);
        clampPlayerWeapon(playerID);
    }
}

Comments
set mapStartItemsOnly to true to keep weapons and ammo but loose keys etc.
set mapStartItemsOnly to false to keep only default starting items like starting a new game (e.g. pistol and some bullets).

See also
givePlayerItem getPlayerItemCount clampPlayerWeapon

void addItem(int objectID, string itemName, int count)
Create new item (by item name) and add to an object's inventory (server and clients).

Example
addItem(PLAYER_OBJECT, "Rifle Mag", 1);

See also
removeItem getItemCount

void addItem(int objectID, int itemTypeNumber, int count)
Create a new item (by item type number) and add to an object's inventory (server and clients).

Example
int rifleMagTypeNumber = getItemTypeNumber("Rifle Mag");
addItem(PLAYER_OBJECT, rifleMagTypeNumber, 1);

See also
removeItem getItemCount

void removeItem(int objectID, string itemName)
Remove an item (by item type name) from an object's inventory and delete the item (server and clients).

Example
removeItem(PLAYER_OBJECT, "Rifle Mag");

See also
addItem getItemCount

void removeItem(int objectID, int itemTypeNumber)
Remove an item (by item type number) from an object's inventory and delete the item (server and clients).

Example
int rifleMagTypeNumber = getItemTypeNumber("Rifle Mag");
removeItem(PLAYER_OBJECT, rifleMagTypeNumber);

See also
addItem getItemCount

void getItemCount(int objectID, string itemName)
Get the count of an item (by item name) in an object's inventory.

Example
print(getItemCount(PLAYER_OBJECT, "Rifle Mag"));

See also
addItem removeItem

void getItemCount(int objectID, int itemTypeNumber)
Get the count of an item (by item type number) in an object's inventory.

Example
int rifleMagTypeNumber = getItemTypeNumber("Rifle Mag");
print(getItemCount(PLAYER_OBJECT, rifleMagTypeNumber));

See also
addItem removeItem

array getContainerItems(int objectID, bool includeWeaponSlots=true)
Get a list of item IDs for all items in an object's inventory.

Example
int objectID = PLAYER_OBJECT;
array<uint> containerItems = getContainerItems(objectID);
int count = 0;
for (uint i = 0; i < containerItems.length(); i++)
{
    uint itemID = containerItems[i];
    print(getItemName(itemID) + " (" + itemID + ")");

    count++;
}
print(getDisplayName(objectID) + " contains " + count + " items");

float getContainerCapacity(int objectID)
Get the total capacity/size for an object's inventory.

See also
getContainerUsedCapacity

float getContainerUsedCapacity(int objectID)
Get the available space for an object's inventory.

See also
getContainerCapacity

bool isItemInContainer(int objectID, uint itemID, bool includeWeaponSlots=true)
Check if an existing item is in an object's inventory.

void addItemToContainer(int objectID, uint itemID)
Add an existing item to an object's inventory (server and clients)

Comments
The item is added without any capacity checks so can overfill.

See also
removeItemFromContainer hasSpaceForItem

void removeItemFromContainer(int objectID, uint itemID)
Remove an existing item from an object's inventory (server and clients)

Comments
The item is not deleted and can still be added back to the inventory or to another object's inventory.

See also
addItemToContainer

void mergeContainers(int sourceContainerID, int destContainerID, bool moveToCentre)
Moves the items in the source container to the destination container, and then deletes the source container (server only)

Comments
Set moveToCentre to true to move the destination container to the centre of the source and destination containers.

void takeItem(int objectID, int containerObjectID, uint itemID)
Take an item from a container and add to an object's inventory (server and clients).

Example
// local player takes item ID 1234 from container object ID 100
int containerObjectID = 100;
int itemID = 1234;
if(hasSpaceForItem(PLAYER_OBJECT, containerObjectID, itemID))
{
    takeItem(PLAYER_OBJECT, containerObjectID, itemID);
    print("Taken " + getItemName(containerObjectID, itemID));
}
else
{
    print("No space for " + getItemName(containerObjectID, itemID) + " or item does not exist");
}

Comments
Will fail if the item is not in the container.
Does not check for available space so can overfill (use hasSpaceForItem() to determine if space is available).

See also
hasSpaceForItem

bool hasSpaceForItem(int objectID, uint itemID)
Determine if an object/container has space for an existing item.

Example
print(hasSpaceForItem(PLAYER_OBJECT, 10));

string getItemName(uint itemID)
Get the name (item type name) of an existing item.

Example
print(getItemName(10));

See also
getItemItemTypeNumber getItemTypeSize

string getItemCategoryName(uint itemID)
Get the item type category name of an existing item.

Example
print(getItemCategoryName(10));

See also
getItemTypeCategoryName

int getItemItemTypeNumber(uint itemID)
Get the item type number of an existing item.

Example
print(getItemItemTypeNumber(10));

Comments
Not to be confused with getItemTypeNumber()

See also
getItemName getItemTypeSize

uint getItemSize(uint itemID)
Get the capacity size of an existing item.

Example
print(getItemSize(10));

See also
getItemTypeSize getItemItemTypeNumber

int getItemSlot(uint itemID)
Get the slot index for an item.

Example
print(getItemSlot(1234));

Comments
Returns -1 if the item does not go in a slot.
If the result is not -1 is can be any of the following:
SLOT_MOUNTED
SLOT_PRIMARY
SLOT_SIDEARM
SLOT_LAUNCHER
SLOT_BINOCULARS

See also
getSlotItem

uint getSlotItem(int objectID, int slot)
Get the item in the specified object's slot.

Example
print(getSlotItem(PLAYER_OBJECT, SLOT_PRIMARY));

Comments
See getItemSlot() for a list of slot numbers.
Returns 0 if there is no item in the slot or the object does not exist.

See also
getItemSlot

bool isItemWeapon(uint itemID)
Determine if an existing item is a weapon.

Example
print(isItemWeapon(1234));

See also
isItemWeaponMag getWeaponItemMagsItemsCount

bool isItemWeaponMag(uint magItemID, uint weaponItemID)
Determine if an existing item is a magazine that fits inside an existing weapon item.

See also
isItemWeapon getWeaponItemMagsItemsCount

int getWeaponItemMagsItemsCount(int objectID, uint weaponItemID)
Get the number of magazines an object has in their inventory for an existing weapon item.

Comments
Does not count mags in weapons within the inventory or slots.

See also
isItemWeapon isItemWeaponMag

float getItemTypeSize(int itemTypeNumber)
Get the capacity size of an item type.

Example
print(getItemTypeSize("Chocolate Bar"));

Comments
Works just like getItemSize but does not require an existing item instance.

See also
getItemSize

int getItemTypeNumber(string itemTypeName)
Get the index of an item type.

Example
print(getItemTypeNumber("Chocolate Bar"));

Comments
Returns 0 (default item) if the item does not exist.

See also
getItemTypeName

string getItemTypeName(int itemTypeNumber)
Get the name of an item type by index.

Example
print(getItemTypeName(0));

See also
getItemTypeNumber getItemTypesCount getItemTypeNames

string getItemTypeCategoryName(int itemTypeNumber)
Get the category name of an item type by item type index.

Example
print(getItemTypeCategoryName(0));

See also
getItemCategoryName

int getItemTypesCount()
Get the amount of item types.

Example
print("There are " + getItemTypesCount() + " item types.");

See also
getItemTypeName getItemTypeNames

array getItemTypeNames()
Get the names of all item types.

Example
// show how many of each item the local player has
array<string> itemTypeNames = getItemTypeNames();
for(uint i=0; i<itemTypeNames.length(); i++)
{
    print(itemTypeNames[i] + ": " + getPlayerItemCount(getLocalPlayer(), itemTypeNames[i]));
}

See also
getItemTypeName getItemTypesCount


Index