Items - SynapseSL/Synapse GitHub Wiki

SynapseItem

Namespace: Synapse.Api.Items

This is an object which represents an Item (on the Map or in the Inventory, it can be both)

The fields it contains:

  • ID => The ItemId of the Item
  • ItemType => The Actually ItemType which is used
  • ItemCategory => The ItemCategory of the ItemType
  • IsCustomItem => If the Item is an custom Item
  • Name => The Name of the Item
  • State => The Current state of the Item
  • ItemHolder => The Player which holds the Item currently in his Inventory (is null if nobody has it)
  • Durabillity => The durabillity of the Item
  • Sight => The sight of the Item
  • Barrel => The barrel of the Item
  • Other => The third possible Attachement (like a flashlight on the weapon)
  • Scale => The Scale of the item
  • Position => The Position of the Item (when a Player holds it it is obviously the Player Position as well)

The method it contains:

  • PickUp(Player) => Gives the Player this Item
  • Drop(Vector3) => Drops it at the Position
  • Drop() => Drops the Item by the ItemHolder(if it has no ItemHolder at the Position stored in Position)
  • Despawn() => Despawns the Item (you can Spawn it again with Drop())
  • Destroy() => Destroys the Item and remove it from the Map entire.

How to Spawn a new SynapseItem?

Its really easy to create a new SynapseItem` by using it's constructor

Example:

new SynapseItem(ItemType.GunLogicer, 10, 0, 0, 0) // ItemType, Durability, Sight, Barrel, Other

//or you can use the Id of the Logicer which would be 24

new SynapseItem(24, 10, 0, 0, 0)

After this if you want to drop on the map, you may use the Drop() method.

Vector 3 pos = ...;
var item = new SynapseItem(ItemType.GunLogicer,10,0,0,0);
item.Drop(pos);

//or you can do it like this

var item = new SynapseItem(ItemType.GunLogicer,10,0,0,0);
item.Position = ...;
item.Drop();

If you want to give the item a player you may use PickUp() method.

Player player = ...;
var item = new SynapseItem(ItemType.GunLogicer,10,0,0,0);
item.PickUp(player);

//or adding it through the Player Inventory object

Player player = ...;
var item = new SynapseItem(ItemType.GunLogicer,10,0,0,0);
player.Inventory.AddItem(item);

How to create a Custom Item?

In order to create a Custom Item you have to register it first.

You can do this through the ItemManager which you can get with SynapseController.Server.ItemManager or Server.Get.ItemManager.

Create a CustomItemInformations object (Namespace: Synapse.Api.Items) and use the method RegisterCustomItem() in the ItemManager with this.

Example:

using Synapse.Api;
using Synapse.Api.Plugin;

namespace FirstPlugin
{
    [PluginInformation(
        Name = "FirstPlugin", //The Name of Your Plugin
        Author = "Dimenzio", // Your Name
        Description = "My First Awesome Plugin", // A Description for your Plugin
        LoadPriority = int.MinValue, //When your Plugin should get loaded (use int.MinValue if you don't know how to use it)
        SynapseMajor = 2, //The Synapse Version for which this Plugin was created for (SynapseMajor.SynapseMinor.SynapsePatch => 2.0.0)
        SynapseMinor = 0,
        SynapsePatch = 0,
        Version = "v.1.0.0" //The Current Version of your Plugin
        )]
    public class PluginClass : AbstractPlugin
    {
        public override void Load()
        {
            var info = new Synapse.Api.Items.CustomItemInformations()
            {
                BasedItemType = ItemType.GunUSP, //The ItemType which is it based on (implementing new models is not possible)
                ID = 100,                        //You can take all Values for the ID except for the ones which is already used by the vanilla Items (0-35)
                Name = "CustomWeapon"            //The Name for your Item
            };

            Server.Get.ItemManager.RegisterCustomItem(info);
        }
    }
}

After this you can simply create the item with new SynapseItem(yourid(in this case 100),0,0,0,0). If you want to find out if a SynapseItem is your new Item you can check it with item.ID.

Note: It's recommended to register the Item in your Load() Method of your PluginClass so that its early registered