private void AddBoxes(ScrapTransportHelicopter entity) { if (entity == null || !config.Enabled || num == 0) { return; } // check if there is already a box foreach (var child in entity.GetComponentsInChildren <StorageContainer>(true)) { if (child.name == prefab) { return; } } // Putting the Transport in Transport Helicopter if (num == 1) { var box = GameManager.server?.CreateEntity(prefab, entity.transform.position) as StorageContainer; if (box == null) { return; } box.Spawn(); box.SetParent(entity); box.transform.localPosition = new Vector3(0f, 0.85f, 1.75f); box.transform.Rotate(new Vector3(0.0f, 0.0f, 0.0f)); box.SendNetworkUpdateImmediate(true); } else if (num == 2) { var box = GameManager.server?.CreateEntity(prefab, entity.transform.position) as StorageContainer; if (box == null) { return; } box.Spawn(); box.SetParent(entity); box.transform.localPosition = new Vector3(-0.5f, 0.85f, 1.75f); box.transform.Rotate(new Vector3(0.0f, 0.0f, 0.0f)); box.SendNetworkUpdateImmediate(true); var box2 = GameManager.server?.CreateEntity(prefab, entity.transform.position) as StorageContainer; if (box2 == null) { return; } box2.Spawn(); box2.SetParent(entity); box2.transform.localPosition = new Vector3(0.5f, 0.85f, 1.75f); box2.transform.Rotate(new Vector3(0.0f, 0.0f, 0.0f)); box2.SendNetworkUpdateImmediate(true); } }
private void OnEntitySpawned(ScrapTransportHelicopter entity) { if (entity == null || !config.Enabled) { return; } // defer checking to ensure storage box is loaded (loads after parent, race condition there) timer.Once(0.1f, () => { AddBoxes(entity); }); }
// drop items when entity is killed (don't want salty tears) private void OnEntityKill(ScrapTransportHelicopter entity) { if (entity == null) { return; } foreach (var child in entity.GetComponentsInChildren <StorageContainer>(true)) { if (child.name == prefab) { child.DropItems(); } } }