Find dead baseplayer

Hey @all,

I recently found a problem with my plugin "disbanded team restore", which restores teams after a server crash.
Just this morning our windows server deviced to restart for a windows update, it literally killed the rust gameserver which lead to the loss of all teams (why? we don't know yet. I just happens sometimes).

To counter that, I made "disbanded team restore". After the plugin loads, it checks if an error occured while saving the teams. If so, it deletes all teams, creates new teams and adds all players to the newly created teams.

this works perfectly but ONLY for players that are awake/alive or sleeping.

Dead players (someone was sleeping on the streets and got killed by a bear) can't be retrieved by following methods:

- BasePlayer.FindAwakeOrSleepingByID(<steamId>)
- BasePlayer.FindByID(<steamId>)
- BasePlayer.FindSleeping(<steamId>)
- RelationshipManager.FindByID

 

This is because the dead player does not exists in these collections/lists:
- BasePlayer.allPlayerList
- BasePlaye.sleepingPlayerList
- BasePlaye.activePlayerList
- RelationshipManager.cachedPlayers

I CAN indeed find the IPlayer for a given steam id with
IPlayer iplayer = covalence.Players.FindPlayer("<steamID>");

BUT its "object" property is null, so:
BasePlayer basePlayer = (BasePlayer)iplayer.Object;

will give "true" for "basePlayer == null"

 

My plugin restores teams by creating a new PlayerTeam and then adding the BasePlayer objects like so:

RelationshipManager.PlayerTeam nums = new RelationshipManager.PlayerTeam();				
nums.teamLeader = playerTeam.teamLeader;
nums.teamID = playerTeam.teamID;
nums.teamName = playerTeam.teamName;
nums.members = new List<ulong>();

foreach (ulong member in playerTeam.members)
{
       BasePlayer basePlayer = RelationshipManager.FindByID(member);
	if(basePlayer != null) 
	{
		nums.AddPlayer(basePlayer);
		basePlayer.currentTeam = nums.teamID;
	} else {
		Puts($"Player {member} not found");
	}
}				
				
RelationshipManager.ServerInstance.teams.Add(nums.teamID, nums);

Since the class "RelationshipManager.PlayerTeam" only got one Method "AddPlayer(BasePlayer player)", I need to have a BasePlayer object.
There is no other method, like "AddPlayer(ulong steamID)".

Does anybody know how I can get the BasePlayer object of a dead player (that has of course already been playing on the server before) OR how I can create the BasePlayer object myself?

I can't just do:

BasePlayer baseplayer = new BasePlayer();
baseplayer.userID = <steamID>;
baseplayer.UserIDString = "<steamID>";
baseplayer.name= "blabla";
baseplayer.displayName = baseplayer.name;

Since I need to call (see my source code above):
basePlayer.currentTeam = nums.teamID;

and also (in order to notify the plugin "automatic authorization"):
Interface.CallHook("OnTeamAcceptInvite", nums, basePlayer);

When the player later logs in, he still sees no team in the left bottom corner of his screen and he is NOT authorized to the TC and turrets of his team mates.

So I guess the approach to create a new object of class "BasePlayer" is not a solution for my problem :(

 

 

Have ya tried

var player = covalence.Players.FindPlayer(steamID.ToString());​
​