Meteor 2 Scripting Functions
Inventory
void givePlayerItem(int playerID, string itemName, int amount)
Give items to a player.
if(isServer())
{
for(int i=0; i<getPlayersCount(); i++)
{
int playerID = getPlayerAtIndex(i);
givePlayerItem(playerID, "Rifle Mag", 1);
}
}
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.
int getPlayerItemCount(int playerID, string itemName)
Get amount of an item a player has.
for(int i=0; i<getPlayersCount(); i++)
{
int playerID = getPlayerAtIndex(i);
print(getPlayerName(playerID) + " has " + getPlayerItemCount(playerID, "Rifle Mag") + " rifle mags");
}
void resetPlayerItems(int playerID, bool mapStartItemsOnly)
Reset a player's items (server only).
if(isServer())
{
for(int i=0; i<getPlayersCount(); i++)
{
int playerID = getPlayerAtIndex(i);
int playerObjectID = getPlayerObject(playerID);
resetPlayerItems(playerID, false);
clampPlayerWeapon(playerID);
}
}
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).
void addItem(int objectID, string itemName, int count)
Create new item (by item name) and add to an object's inventory (server and clients).
addItem(PLAYER_OBJECT, "Rifle Mag", 1);
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).
int rifleMagTypeNumber = getItemTypeNumber("Rifle Mag");
addItem(PLAYER_OBJECT, rifleMagTypeNumber, 1);
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).
removeItem(PLAYER_OBJECT, "Rifle Mag");
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).
int rifleMagTypeNumber = getItemTypeNumber("Rifle Mag");
removeItem(PLAYER_OBJECT, rifleMagTypeNumber);
void getItemCount(int objectID, string itemName)
Get the count of an item (by item name) in an object's inventory.
print(getItemCount(PLAYER_OBJECT, "Rifle Mag"));
void getItemCount(int objectID, int itemTypeNumber)
Get the count of an item (by item type number) in an object's inventory.
int rifleMagTypeNumber = getItemTypeNumber("Rifle Mag");
print(getItemCount(PLAYER_OBJECT, rifleMagTypeNumber));
array getContainerItems(int objectID, bool includeWeaponSlots=true)
Get a list of item IDs for all items in an object's inventory.
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.
float getContainerUsedCapacity(int objectID)
Get the available space for an object's inventory.
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)
The item is added without any capacity checks so can overfill.
void removeItemFromContainer(int objectID, uint itemID)
Remove an existing item from an object's inventory (server and clients)
The item is not deleted and can still be added back to the inventory or to another object's inventory.
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)
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).
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");
}
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).
bool hasSpaceForItem(int objectID, uint itemID)
Determine if an object/container has space for an existing item.
print(hasSpaceForItem(PLAYER_OBJECT, 10));
string getItemName(uint itemID)
Get the name (item type name) of an existing item.
print(getItemName(10));
string getItemCategoryName(uint itemID)
Get the item type category name of an existing item.
print(getItemCategoryName(10));
int getItemItemTypeNumber(uint itemID)
Get the item type number of an existing item.
print(getItemItemTypeNumber(10));
Not to be confused with getItemTypeNumber()
uint getItemSize(uint itemID)
Get the capacity size of an existing item.
print(getItemSize(10));
int getItemSlot(uint itemID)
Get the slot index for an item.
print(getItemSlot(1234));
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
uint getSlotItem(int objectID, int slot)
Get the item in the specified object's slot.
print(getSlotItem(PLAYER_OBJECT, SLOT_PRIMARY));
See getItemSlot() for a list of slot numbers.
Returns 0 if there is no item in the slot or the object does not exist.
bool isItemWeapon(uint itemID)
Determine if an existing item is a weapon.
print(isItemWeapon(1234));
bool isItemWeaponMag(uint magItemID, uint weaponItemID)
Determine if an existing item is a magazine that fits inside an existing weapon item.
int getWeaponItemMagsItemsCount(int objectID, uint weaponItemID)
Get the number of magazines an object has in their inventory for an existing weapon item.
Does not count mags in weapons within the inventory or slots.
float getItemTypeSize(int itemTypeNumber)
Get the capacity size of an item type.
print(getItemTypeSize("Chocolate Bar"));
Works just like getItemSize but does not require an existing item instance.
int getItemTypeNumber(string itemTypeName)
Get the index of an item type.
print(getItemTypeNumber("Chocolate Bar"));
Returns 0 (default item) if the item does not exist.
string getItemTypeName(int itemTypeNumber)
Get the name of an item type by index.
print(getItemTypeName(0));
string getItemTypeCategoryName(int itemTypeNumber)
Get the category name of an item type by item type index.
print(getItemTypeCategoryName(0));
int getItemTypesCount()
Get the amount of item types.
print("There are " + getItemTypesCount() + " item types.");
array getItemTypeNames()
Get the names of all item types.
array<string> itemTypeNames = getItemTypeNames();
for(uint i=0; i<itemTypeNames.length(); i++)
{
print(itemTypeNames[i] + ": " + getPlayerItemCount(getLocalPlayer(), itemTypeNames[i]));
}
Index