Add Item Gun Custom Slot & Condition

Jakkee

Retired Staff
Retired Staff
Plugin Developer
Jul 28, 2014
1,465
932
113
Australia
C#:
Inventory Pinventory = player.Inventory.InternalInventory
#Get Player inventory
ItemDataBlock itemlookup = DatablockDictionary.GetByName("M4");
#Look up weapon

IInventoryItem itemdata = Pinventory.AddItem(itemlookup, int slot, int amount);
#Add weapon to player inventory

itemdata.SetUses(int count);
#Set how much ammo is loaded in the weapon
itemdata.SetTotalModSlotCount(int count);
#Set how many mods slots you'd like
itemdata.SetCondition(float amount);
#Set the condition of the weapon

ItemDataBlock weaponmod = DatablockDictionary.GetByName("Holo sight");
#Lookup attachments to add
itemdata.AddMod(weaponmod);
#Add it
weaponmod = DatablockDictionary.GetByName("Silencer");
#Repeat for more mods
itemdata.AddMod(weaponmod);
weaponmod = DatablockDictionary.GetByName("Laser Sight");
itemdata.AddMod(weaponmod);
Something like this
 
  • Winner
Reactions: salva

remove.tk

Member
Trusted Member
Member
Jan 27, 2015
43
10
8
26
Parts Unknown
C#:
Inventory Pinventory = player.Inventory.InternalInventory
#Get Player inventory
ItemDataBlock itemlookup = DatablockDictionary.GetByName("M4");
#Look up weapon

IInventoryItem itemdata = Pinventory.AddItem(itemlookup, int slot, int amount);
#Add weapon to player inventory

itemdata.SetUses(int count);
#Set how much ammo is loaded in the weapon
itemdata.SetTotalModSlotCount(int count);
#Set how many mods slots you'd like
itemdata.SetCondition(float amount);
#Set the condition of the weapon

ItemDataBlock weaponmod = DatablockDictionary.GetByName("Holo sight");
#Lookup attachments to add
itemdata.AddMod(weaponmod);
#Add it
weaponmod = DatablockDictionary.GetByName("Silencer");
#Repeat for more mods
itemdata.AddMod(weaponmod);
weaponmod = DatablockDictionary.GetByName("Laser Sight");
itemdata.AddMod(weaponmod);
Something like this
Not Found method : itemdata.SetTotalModSlot & itemdata.AddMod

Thank
 

Jakkee

Retired Staff
Retired Staff
Plugin Developer
Jul 28, 2014
1,465
932
113
Australia
Not Found method : itemdata.SetTotalModSlot & itemdata.AddMod

Thank
Do you need to add weapon mods? If not use this:
C#:
Inventory Pinventory = player.Inventory.InternalInventory
#Get Player inventory
ItemDataBlock itemlookup = DatablockDictionary.GetByName("M4");
#Look up weapon

IInventoryItem itemdata = Pinventory.AddItem(itemlookup, int slot, int amount);
#Add weapon to player inventory

itemdata.SetUses(int count);
#Set how much ammo is loaded in the weapon
itemdata.SetCondition(float amount);
#Set the condition of the weapon
 

remove.tk

Member
Trusted Member
Member
Jan 27, 2015
43
10
8
26
Parts Unknown
Do you need to add weapon mods? If not use this:
C#:
Inventory Pinventory = player.Inventory.InternalInventory
#Get Player inventory
ItemDataBlock itemlookup = DatablockDictionary.GetByName("M4");
#Look up weapon

IInventoryItem itemdata = Pinventory.AddItem(itemlookup, int slot, int amount);
#Add weapon to player inventory

itemdata.SetUses(int count);
#Set how much ammo is loaded in the weapon
itemdata.SetCondition(float amount);
#Set the condition of the weapon
i need add weapon mods & slot
 

Jakkee

Retired Staff
Retired Staff
Plugin Developer
Jul 28, 2014
1,465
932
113
Australia
Maybe this?
C#:
ItemDataBlock weapon = DatablockDictionary.GetByName("M4");
#Look up weapon

weapon.ITEM_TYPE.SetUses(int count);
#Set how much ammo is loaded in the weapon
weapon.ITEM_TYPE.SetTotalModSlotCount(int count);
#Set how many mods slots you'd like
weapon.ITEM_TYPE.SetCondition(float amount);
#Set the condition of the weapon

ItemDataBlock weaponmod = DatablockDictionary.GetByName("Holo sight");
#Lookup attachments to add
weapon.ITEM_TYPE.AddMod(weaponmod);
#Add it
weaponmod = DatablockDictionary.GetByName("Silencer");
#Repeat for more mods
weapon.ITEM_TYPE.AddMod(weaponmod);
weaponmod = DatablockDictionary.GetByName("Laser Sight");
weapon.ITEM_TYPE.AddMod(weaponmod);

player.Inventory.InternalInventory.AddItem(weapon, int slot, int amount);
#Add weapon to player inventory
#Setting the amount to a weapon being spawned in the hotbar, will override SetUses()
 

Komrad

Member
Member
May 14, 2017
89
4
6
30
Maybe this?
C#:
ItemDataBlock weapon = DatablockDictionary.GetByName("M4");
#Look up weapon

weapon.ITEM_TYPE.SetUses(int count);
#Set how much ammo is loaded in the weapon
weapon.ITEM_TYPE.SetTotalModSlotCount(int count);
#Set how many mods slots you'd like
weapon.ITEM_TYPE.SetCondition(float amount);
#Set the condition of the weapon

ItemDataBlock weaponmod = DatablockDictionary.GetByName("Holo sight");
#Lookup attachments to add
weapon.ITEM_TYPE.AddMod(weaponmod);
#Add it
weaponmod = DatablockDictionary.GetByName("Silencer");
#Repeat for more mods
weapon.ITEM_TYPE.AddMod(weaponmod);
weaponmod = DatablockDictionary.GetByName("Laser Sight");
weapon.ITEM_TYPE.AddMod(weaponmod);

player.Inventory.InternalInventory.AddItem(weapon, int slot, int amount);
#Add weapon to player inventory
#Setting the amount to a weapon being spawned in the hotbar, will override SetUses()
what do you mean by ITEM_TYPE? - if you take the M4 has a type of bullet - although the weapon does not have this type
 

Komrad

Member
Member
May 14, 2017
89
4
6
30
Maybe this?
C#:
ItemDataBlock weapon = DatablockDictionary.GetByName("M4");
#Look up weapon

weapon.ITEM_TYPE.SetUses(int count);
#Set how much ammo is loaded in the weapon
weapon.ITEM_TYPE.SetTotalModSlotCount(int count);
#Set how many mods slots you'd like
weapon.ITEM_TYPE.SetCondition(float amount);
#Set the condition of the weapon

ItemDataBlock weaponmod = DatablockDictionary.GetByName("Holo sight");
#Lookup attachments to add
weapon.ITEM_TYPE.AddMod(weaponmod);
#Add it
weaponmod = DatablockDictionary.GetByName("Silencer");
#Repeat for more mods
weapon.ITEM_TYPE.AddMod(weaponmod);
weaponmod = DatablockDictionary.GetByName("Laser Sight");
weapon.ITEM_TYPE.AddMod(weaponmod);

player.Inventory.InternalInventory.AddItem(weapon, int slot, int amount);
#Add weapon to player inventory
#Setting the amount to a weapon being spawned in the hotbar, will override SetUses()
I made a function for adding mods on a weapon,but can't yet how to update view model - mod well added,but to see him to draw a weapon in barslot
 

Jakkee

Retired Staff
Retired Staff
Plugin Developer
Jul 28, 2014
1,465
932
113
Australia
I made a function for adding mods on a weapon,but can't yet how to update view model - mod well added,but to see him to draw a weapon in barslot
So it adds mods to the weapon?
But can't get it to spawn in hotbar?
Try spawning it in slot 36 I think is the first slot in the hotbar (Check code of battlefield server kit for slot numbers)
 

Komrad

Member
Member
May 14, 2017
89
4
6
30
So it adds mods to the weapon?
But can't get it to spawn in hotbar?
Try spawning it in slot 36 I think is the first slot in the hotbar (Check code of battlefield server kit for slot numbers)
No - the modifier I added - it was added to the weapon, but on the model itself it appears after rebooting the weapon
 

DreTaX

Probably knows the answer...
Administrator
Jun 29, 2014
4,093
4,784
113
At your house.
github.com
I think months ago I found something about the slot system, it was sorta complicated. I will see if I can dig it up on the week.
 

Komrad

Member
Member
May 14, 2017
89
4
6
30
I think months ago I found something about the slot system, it was sorta complicated. I will see if I can dig it up on the week.
I already found a method - you can even use weapons to eat food in inventory: D
 

DreTaX

Probably knows the answer...
Administrator
Jun 29, 2014
4,093
4,784
113
At your house.
github.com
Which was the slot editing?


C#:
ItemDataBlock weapon = DatablockDictionary.GetByName(shootEvent.Player.Inventory.ActiveItem.Name);
Debug.Log(weapon);
ItemModDataBlock weaponmod = DatablockDictionary.GetByName("Holo sight")as ItemModDataBlock;
shootEvent.IBulletWeaponItem.AddMod(weaponmod);
weaponmod = DatablockDictionary.GetByName("Silencer")as ItemModDataBlock;
shootEvent.IBulletWeaponItem.AddMod(weaponmod);
weaponmod = DatablockDictionary.GetByName("Laser Sight")as ItemModDataBlock;
shootEvent.IBulletWeaponItem.AddMod(weaponmod)
shootEvent.IBulletWeaponItem.OnDeactivate();
shootEvent.IBulletWeaponItem.OnActivate();
@remove.tk
 
Last edited: