1. Here is what I got, it makes a 1x1 with a door, I am trying to get the lock to stick on and work.

    Sorry for the wordy code..

    Code:
            void Spawn1x1(Vector3 position, Quaternion rotation, BasePlayer player)
            {            BuildingGrade.Enum type = BuildingGrade.Enum.Wood;
                int strength = 1;            SpawnStructure("assets/prefabs/building core/foundation/foundation.prefab",
                               position,
                               Quaternion.AngleAxis(0, new Vector3(0, 1, 0)),
                               type,strength);
                SpawnStructure("assets/prefabs/building core/wall/wall.prefab",
                               position + new Vector3(-1.5f,0,0),
                               Quaternion.AngleAxis(180, new Vector3(0, 1, 0)),
                               type, strength);
                SpawnStructure("assets/prefabs/building core/wall/wall.prefab",
                               position + new Vector3(1.5f, 0, 0),
                               Quaternion.AngleAxis(0, new Vector3(0, 1, 0)),
                               type, strength);
                SpawnStructure("assets/prefabs/building core/wall/wall.prefab",
                               position + new Vector3(0, 0, 1.5f),
                               Quaternion.AngleAxis(-90, new Vector3(0, 1, 0)),
                               type, strength);
                SpawnStructure("assets/prefabs/building core/floor/floor.prefab",
                               position + new Vector3(0, 3, 0),
                               Quaternion.AngleAxis(0, new Vector3(0, 1, 0)),
                               type, strength);
                           
                SpawnStructure("assets/prefabs/building core/wall.doorway/wall.doorway.prefab",      
                                position + new Vector3(0, 0, -1.5f),
                               Quaternion.AngleAxis(90, new Vector3(0, 1, 0)),
                               type, strength);            var door = SpawnDeployable("door.hinged.metal",
                                position + new Vector3(0, 0, -1.5f),
                               Quaternion.AngleAxis(90, new Vector3(0, 1, 0)),
                               player) as Door;            var doorLock = SpawnDeployable("lock.code",
                               position + new Vector3(0, 1.5f, -1.5f),
                               Quaternion.AngleAxis(90, new Vector3(0, 1, 0)),
                               player) as CodeLock;            door.SetSlot(BaseEntity.Slot.Lock, doorLock);
            }
    
    entity spawn code, taken from Build.cs, thanks Reneb & NoGrod

    Code:
            private BuildingBlock SpawnStructure(string prefabname, Vector3 pos, Quaternion angles, BuildingGrade.Enum grade, float health)
            {
                GameObject prefab = GameManager.server.CreatePrefab(prefabname, pos, angles, true);
                if (prefab == null)
                {
                    PrintToChat($"SpawnStructure: {prefab} no worky.");
                    return null;
                }
                BuildingBlock block = prefab.GetComponent<BuildingBlock>();
                if (block == null) return null;
                block.transform.position = pos;
                block.transform.rotation = angles;
                block.gameObject.SetActive(true);
                block.blockDefinition = PrefabAttribute.server.Find<Construction>(block.prefabID);
                block.Spawn();
                block.SetGrade(grade);
                if (health <= 0f)
                    block.health = block.MaxHealth();
                else
                    block.health = health;            block.SendNetworkUpdate(BasePlayer.NetworkQueue.Update);
                spawnedBuildingBlocks.Add(block);
                return block;
            }        private BaseEntity SpawnDeployable(string prefab, Vector3 pos, Quaternion angles, BasePlayer player)
            {
                //Item newItem = ItemManager.CreateByName(prefab, 1);
                Item newItem = makeItem(prefab, 1);            if (newItem?.info.GetComponent<ItemModDeployable>() == null)
                {
                    PrintToChat(player, $"SpawnDeployable: {prefab} no worky.");             
                    return null;
                }
                var deployable = newItem.info.GetComponent<ItemModDeployable>().entityPrefab.resourcePath;
                if (deployable == null)
                {
                    return null;
                }
                var newBaseEntity = GameManager.server.CreateEntity(deployable, pos, angles, true);
                if (newBaseEntity == null)
                {
                    return null;
                }
                newBaseEntity.SendMessage("SetDeployedBy", player, UnityEngine.SendMessageOptions.DontRequireReceiver);
                newBaseEntity.SendMessage("InitializeItem", newItem, UnityEngine.SendMessageOptions.DontRequireReceiver);
                newBaseEntity.Spawn();            spawnedEntities.Add(newBaseEntity);
                return newBaseEntity;
            }
    
    if you remove:

    door.SetSlot(BaseEntity.Slot.Lock, doorLock);

    The lock just sits there in mid air..

    otherwise it just sits the in the center of the door way.


    Plase halp..
     
  2. You may need to send a network update after you've set the lock on the door - doorLock.SendNetworkUpdate(); This will refresh the entity on your client.