Example #1
0
        private bool unflipTurreT(BaseEntity turret, BasePlayer player)
        {
            try{
                if (turret.transform.rotation.w != -0.00f)
                {
                    return(false);
                }

                AutoTurret autoTurret = GameManager.server.CreateEntity(pf, new Vector3(turret.transform.position.x, turret.transform.position.y - 3f, turret.transform.position.z), new Quaternion(0.0f, 0.1f, 0.0f, 1.0f), true) as AutoTurret;
                autoTurret.Spawn();
                autoTurret.health = turret.Health();

                turretinv.Add(autoTurret, 0);
                foreach (var item in turret.GetComponent <AutoTurret>().inventory.itemList.ToList())
                {
                    if (item.info.displayName.english == ("5.56 Rifle Ammo"))
                    {
                        turretinv[autoTurret] = turretinv[autoTurret] + item.amount;
                    }
                }
                turretplayer.Add(autoTurret, new AutoPlayer {
                });
                foreach (var target in turret.GetComponent <AutoTurret>().authorizedPlayers)
                {
                    turretplayer[autoTurret].players.Add(target);
                }

                Item itemn = BuildItems("ammo.rifle", turretinv[autoTurret]);
                if (itemn != null)
                {
                    itemn.MoveToContainer(autoTurret.inventory);
                }
                turretinv.Remove(autoTurret);

                foreach (var entry in turretplayer[autoTurret].players)
                {
                    autoTurret.authorizedPlayers.Add(entry);
                }
                turretplayer.Remove(autoTurret);

                autoTurret.SendNetworkUpdateImmediate();
                turret.KillMessage();
                return(true);
            }
            catch (System.Exception)
            {
                return(false);
            }
        }
        void AddTurret(MiniCopter copter)
        {
            AutoTurret aturret = GameManager.server.CreateEntity(autoturretPrefab, copter.transform.position) as AutoTurret;

            DestroyMeshCollider(aturret);
            DestroyGroundComp(aturret);
            aturret.Spawn();
            aturret.pickup.enabled = false;
            aturret.sightRange     = config.turretRange;
            aturret.SetParent(copter);
            aturret.transform.localPosition = new Vector3(0, 0, 2.47f);
            aturret.transform.localRotation = Quaternion.Euler(0, 0, 0);
            ProtoBuf.PlayerNameID pnid   = new ProtoBuf.PlayerNameID();
            BasePlayer            player = BasePlayer.FindByID(copter.OwnerID);

            if (player != null)
            {
                pnid.userid   = player.userID;
                pnid.username = player?.displayName;
                aturret.authorizedPlayers.Add(pnid);
            }
            aturret.SendNetworkUpdate();
            AddSwitch(aturret);
        }