Hello, I would like to do spawn a smart alarm on a storage box, and when I do spawn the smart alarm disappears.
void OnEntitySpawned(BaseEntity entity)
{
BasePlayer player = BasePlayer.FindByID(entity.OwnerID);
if (player == null)
return;
if (entity.ShortPrefabName != "woodbox_deployed")
return;
ItemContainer container = new ItemContainer();
container.ServerInitialize(null, 6);
container.GiveUID();
StorageContainer storage = entity as StorageContainer;
storage.inventory = container;
storage.inventory.entityOwner = entity;
storage.isLootable = true;
storage.SendNetworkUpdateImmediate();
Create(entity, player);
}
void Create(BaseEntity parent, BasePlayer player)
{
SmartAlarm alarm = CreateSmartAlarm(parent);
alarm.SetFlag(BaseEntity.Flags.On, true);
alarm.SetFlag(BaseEntity.Flags.Reserved8, true);
alarm.SetFlag(IOEntity.Flag_HasPower, true);
}
SmartAlarm CreateSmartAlarm(BaseEntity parent)
{
SmartAlarm smartAlarm = (SmartAlarm)GameManager.server.CreateEntity("assets/prefabs/deployable/playerioents/app/smartalarm/smartalarm.prefab");
smartAlarm.Spawn();
smartAlarm.SetParent(parent);
Vector3 pos = parent.transform.localPosition;
Quaternion rot = parent.transform.localRotation;
pos.y = pos.y + 0.55f;
smartAlarm.transform.position = pos;
smartAlarm.transform.rotation = rot;
UnityEngine.Object.DestroyImmediate(smartAlarm.GetComponent<DestroyOnGroundMissing>());
UnityEngine.Object.DestroyImmediate(smartAlarm.GetComponent<GroundWatch>());
UnityEngine.Object.DestroyImmediate(smartAlarm.GetComponent<BoxCollider>());
UnityEngine.Object.DestroyImmediate(smartAlarm.GetComponent<InstrumentKeyController>());
smartAlarm.EnableSaving(true);
smartAlarm.SendNetworkUpdateImmediate();
smartAlarm.SendNetworkUpdate();
return smartAlarm;
}