Saving BasePlayer in datafile and loading it?Solved
Is this possible, even if the player is not online/alive anymore?
(I'm beginner with C#)


            var entities = BaseNetworkable.serverEntities.Where(e => e?.name != null && e.name.Contains("skull_fire_pit")).Cast<BaseEntity>().ToList();
...           
            foreach (var entity in entities)
            {
                if (!entity.GetBuildingPrivilege())
                {
                    entity.Kill(BaseNetworkable.DestroyMode.Gib);
                    continue;
                }
...

                BasePlayer owner = BasePlayer.FindByID(entity.OwnerID);
                if (BasePlayer.FindByID(entity.OwnerID))
                    owner = BasePlayer.FindByID(entity.OwnerID);
                else if (BasePlayer.FindSleeping(entity.OwnerID))
                    owner = BasePlayer.FindSleeping(entity.OwnerID);

                if (owner == null)
                {
                    entity.Kill(BaseNetworkable.DestroyMode.Gib);
                    continue;
                }​

In indisght covalence.Players is more suitable, but it would require a lot of change to other parts of the plugin

Why do you need to save BasePlayer? Technically, you can do that. But I don't understand why
No, you cannot save an entire BasePlayer object in a .json data file. You can save the data (granted that it can convert to text) that each part of that object contains, but not the entire object.
In response to misticos ():
Why do you need to save BasePlayer? Technically, you can do that. But I don't understand why
Bad design choice.

A BasePlayer variable is used throughout the plugin, it initialize normally if the player is either online/offline and sleeping. But if he's dead and offline, findbyid/findsleeping is null. Figured save/load could be a way, also an oppurtunity to learn more.
In response to haggbart ():
Bad design choice.

A BasePlayer variable is used throughout the plugin, it initialize nor...
Base player is a class. Its not like your created class, its dynamic and different. You CANT. If you need help - accounce your current problem why you want to save BasePlayer - we will help.
Locked automatically