Third Party Support

Various functions are included with RPGx that are intended to be used by third party content, such as for using stacks of items in your inventory as ammo for weapons. These functions will be simplified in a future update, and may only use one function.

**Note:** Make sure to require the RPGx add-on as a dependency if the third-party functions are used in your own projects.

**Note:** The "bow" and "spear" items are automatically set up to use the ammo system when hosted with RPGx - to demonstrate how the third party functions can be used. The bow will only fire if you have "arrow" items in your inventory or in a container you're carrying. Spears can also be used while stacked; one spear item will be removed from the stack each time you throw one. You can disable bows and spears from using ammo under Server Settings of the Drafting Table GUI.

## Checking For Item Stacks

**RPGx\_ifPlyrHasStack(%client, %itemDatablock, %amount);** can be used to check if a player has a certain amount of items in their player inventory, or in a backpack / container they are carrying; the item's don't have to be present in only one stack. Just enter the client for the player, replace %itemDatablock with the datablock name of the item you are searching for (make sure to enter the datablock's name, not ID), and replace %amount with the least amount of items you're looking for.

## Removing Stacks

**RPGx\_PlyrRmvStack(%client, %itemDatablock, %amount);** is used for removing a certain amount of items from a player's inventory, or from a backpack / container they're carrying. Similar to "RPGx\_ifPlyrHasStack", item's don't have to be present in a single stack to be deducted. Replace %itemDatablock with the name of the datablock for the item you want to remove, and replace %amount with the amount you want to remove.

**Note:** You can use "RPGx\_ifPlyrHasStack" beforehand to check if a player has the amount of items to deduct.

## Adding Stacks

**RPGx\_PlyrAddStack(%client, %itemID, %amount, %stackLimit, %weight, %durability, %efficiency, %uniqueID, %mods);** is used for adding a certain amount of items to a player's inventory, or to a backpack / container they are carrying. This function works similar to auto-sorting - it attempts to stack items in similar stacks, and adds the rest to any empty slots it can find. Items are not taken from another source, they are created for the purpose of the function.

Replace %itemID with the numerical ID of the datablock for the item you want to add, and replace %amount with the amount of items you want to add. The other variables you don't really have to worry about - they can be replaced with the following: **RPGx\_PlyrAddStack(%client, %itemID, %amount, %itemID.RPGx\_StackLm, %itemID.RPGx\_Wght, %itemID.RPGx\_maxDurab, %itemID.RPGx\_Effc, "", "");** Make sure to change each %itemID variable to the item's datablock ID.

If any items are remaining and can't be added to an inventory, the function will return the remaining amount.

## Dropping Stacks

**RPGx\_toolDrop(%player, %itemDatablock, %amount, %weight, %durability, %uniqueID, %efficiency, %mods, %pos, %rot);** can be used to drop a stack of items from a player. The item's don't actually have to be present in a player's inventory (or in any backpack / container they are carrying); this function just spawns and throws a physical item from the player. However, you can use "RPGx\_ifPlyrHasStack" in advance to check if the player has a certain amount of items, and "RPGx\_PlyrRmvStack" to remove those items.

Replace %player with the player's object ID (i.e. %client.player), change %itemDatablock to the item's datablock name (not it's ID), and %amount to the amount of items that will be added to the stack. The other variables can be replaced with the following: **RPGx\_toolDrop(%player, %itemDatablock, %amount, %itemID.RPGx\_Wght, %itemID.RPGx\_maxDurab, "", %itemID.RPGx\_Effc, "", %pos, %rot);**

%pos is a 3-dimensional string vector (i.e. "0.0 1.0 2.0") of the position of where to spawn the dropped item. If %pos is left blank (""), the player's position will be used automatically and the item will be given velocity - to simulate the item being thrown by the player. If %pos is not left blank, the item will just be spawned without being thrown (used for other RPGx scripts). %rot is a quaternion for the spawned item's rotation; if %pos is left blank, %rot will default to the player's rotation and can also be left blank.