#Applying changes to FirearmItem

8 messages · Page 1 of 1 (latest)

agile hinge
#

im making a simple custom item plugin for my server but i have a problem this setup was working on items added to someone Inventory but now im using it on spawned items but there is a problem my code cant get firearm module from pickup for some reason
the code:

Pickup itemP = Pickup.Create(AllItemsType.AllItems.Find(x => x.Id == CurrentItem.Id).BasicItem, CurrentItem.Position, Quaternion.EulerAngles(CurrentItem.Rotation), CurrentItem.Scale);
if (AllItemsType.AllItems.Find(x => x.Id == CurrentItem.Id).TypeOfTheItem == WhatTypeOfItem.Firearm)
{ 
    FirearmItem firearmItem = Item.Get(itemP.Base.Info.Serial) as FirearmItem;
if (firearmItem == null)
{
    Log.Info("No Firearm Module");
}
                  
Firearm gun = firearmItem.Base;
                   
if (gun == null)
{
    Log.Info("No gun Module");
}
                  
gun.ApplyAttachmentsCode(AllItemsType.AllItems.Find(x => x.Id == CurrentItem.Id).AttachmentsItem, true);
MothCustomItemsMain.Instance.CreateCustomWeapon(itemP.Serial, AllItemsType.AllItems.Find(x => x.Id == CurrentItem.Id).CustomItem);
if (AllItemsType.AllItems.Find(x => x.Id == CurrentItem.Id).BasicItem == ItemType.GunRevolver)
{
    gun.TryGetModule(out CylinderAmmoModule MagazineCylinder);
    MagazineCylinder.ServerModifyAmmo(-5 + CurrentItem.AmmoOrAmount);
    MagazineCylinder.RotateCylinder(5 - CurrentItem.AmmoOrAmount);
}
else
{
    gun.TryGetModule(out MagazineModule magazineModule);
    magazineModule.ServerSetInstanceAmmo(itemP.Base.Info.Serial, CurrentItem.AmmoOrAmount);
}}

hard goblet
#
  1. Create the item in Host player inventory and modify it there
#

and then drop it

#
  1. Use static serial-base methods from the used modules
agile hinge
hard goblet
#

Server.Host

agile hinge