Spawn Items In Specific Slots on HotbarSolved
So I am trying to spawn in items on a player's hotbar but for some reason the ak spawns on the last slot while the rest of the items spawn in the correct slots just one down since the ak isnt there. I am using item.position = 1; to set the positition of the items but its not working.

Item item = ItemManager.CreateByName("rifle.ak", 1);
// If weapon fill magazine to capacity
var weapon = item.GetHeldEntity() as BaseProjectile;
if (weapon != null)
{
(item.GetHeldEntity() as BaseProjectile).primaryMagazine.contents = weapon.primaryMagazine.capacity;
}

//Attachments
bool silencer = true;
bool holosight = false;
if (silencer)
{
item.contents.AddItem(ItemManager.CreateByName("weapon.mod.silencer", 1).info, 1);
}
if (holosight)
{
item.contents.AddItem(ItemManager.CreateByName("weapon.mod.holosight", 1).info, 1);
}
// End Attachments
item.position = 1;
player.inventory.GiveItem(item);
//MEDS
Item item2 = ItemManager.CreateByName("syringe.medical", 2);
item.position = 2;
player.inventory.GiveItem(item2);

Item item3 = ItemManager.CreateByName("syringe.medical", 2);
item.position = 3;
player.inventory.GiveItem(item3);

Item item4 = ItemManager.CreateByName("syringe.medical", 2);
item.position = 4;
player.inventory.GiveItem(item4);

Item item5 = ItemManager.CreateByName("bandage", 3);
item.position = 5;
player.inventory.GiveItem(item5);​

The PlayerInventory has a method called GetIdealPickupContainer which will change the container that an item goes to depending on whether or not the item is stackable, usable, has the "NotStraightToBelt" flag, and/or player already has the item.

Also, the GiveItem method will choose it's own position for the item (the same as using position -1).

In your case, you should not use the GiveItem method in PlayerInventory, but rather the MoveToContainer method in Item.

item.MoveToContainer(player.inventory.containerBelt, position);​

You may also need to iterate through every item that is currently in the player's belt and move it to their inventory (or drop it to the ground) to ensure the belt slots are able to receive new items.
Locked automatically