1. Hey there,

    is there a way to convert BasePlayer to ProtoBuf.PlayerNameID and back?
     
  2. There is no direct way, no. From what I remember, PlayerNameID only stores exactly what it says; the player's name and ID. You can create one using the info from baseplayer (their name and ID), but you can't convert these two.
     
  3. Okay i changed a liddle bit code but it doesn't work.
    This my way:
    Code:
                            int t = 0;
                            ProtoBuf.PlayerNameID pl = new ProtoBuf.PlayerNameID();
                            pl.userid = players[0].userID;
                            pl.username = players[0].displayName;
                            List<AutoTurret> turrets = Component.FindObjectsOfType<AutoTurret>().ToList();
                            foreach (AutoTurret turret in turrets)
                            {
                                if (turret.OwnerID == player.OwnerID)
                                {
                                    if (!turret.authorizedPlayers.Contains(pl))
                                    {
                                        turret.authorizedPlayers.Add(pl);
                                        turret.SendNetworkUpdateImmediate();
                                        t++;
                                    }
                                }
                            }
                            players[0].SendNetworkUpdateImmediate();
    WHats wrong with it?
     
  4. I believe the problem is that PlayerNameIDs are still 'unique', so you can't just create a new one and check if it exists.

    You can also check if a player is authed by simply doing turret.IsAuthed(Player), where Player is BasePlayer.

    If you need to do a check through authorizedPlayers, you can do this (using LINQ):
    Code:
    var isAuthed = turret.authorizedPlayers.FirstOrDefault(p => p.userid == player.userID) != null;
    
     
  5. Mhh thanks but it doesnt work. I get 0 players.

    Code:
                            ProtoBuf.PlayerNameID pl = new ProtoBuf.PlayerNameID();
                            pl.userid = players[0].userID;
                            pl.username = players[0].displayName;
                            List<AutoTurret> turrets = Component.FindObjectsOfType<AutoTurret>().ToList();
                            foreach (AutoTurret turret in turrets)
                            {
                                if (turret.OwnerID == player.OwnerID)
                                {
                                    var isAuthed = turret.authorizedPlayers.FirstOrDefault(p => p.userid == players[0].userID) != null;
                                    if (isAuthed)
                                    {
                                        turret.authorizedPlayers.Remove(pl);
                                        turret.SendNetworkUpdateImmediate();
                                        t++;
                                    }
                                }
                            }
    Is there a Field of WhiteList players same as a codelock?
     
  6. Ahh now i know wthats wrong.

    List<AutoTurret> turrets = Component.FindObjectsOfType<AutoTurret>().ToList();
    There i get all autoturrets. BUT if i check:
    if (turret.OwnerID == player.OwnerID)

    i get false back. So the OwnerID in the turret is null. But why?
     
  7. I'm not sure. Are these turrets being placed normally, or are they being placed through a plugin? If normally, I'm not sure why they would lack an owner ID.
     
  8. Code:
    if ((turret as BaseEntity).OwnerID == player.OwnerID)