Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vanish hooks #541

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open

Vanish hooks #541

wants to merge 1 commit into from

Conversation

IIIaKa
Copy link
Contributor

@IIIaKa IIIaKa commented Dec 10, 2024

As we already know, in the December update, the developers added a new command "invis"(Vanish).
I suggest adding OnVanishDisappear and OnVanishReappear hooks to track the entry and exit from invisibility, similar to what is already available in the Vanish and BetterVanish plugins.

1. The OnVanishDisappear hook is called after the player became invisible. No return behavior.

void OnVanishDisappear(BasePlayer player)
{
    Puts($"Player {player.displayName} has become invisible.");
}

2. The OnVanishReappear hook is called after the player became visible. No return behavior.

void OnVanishReappear(BasePlayer player)
{
    Puts($"Player {player.displayName} is visible again.");
}

Code before:

[ServerVar(Help = "Make admin invisibile")]
public static void invis(ConsoleSystem.Arg arg)
{
	global::BasePlayer basePlayer = arg.Player();
	if (basePlayer == null)
	{
		return;
	}
	bool @bool = arg.GetBool(0, !Debugging.invisiblePlayers.Contains(basePlayer));
	if (@bool && !Debugging.invisiblePlayers.Contains(basePlayer))
	{
		Debugging.invisiblePlayers.Add(basePlayer);
		basePlayer.limitNetworking = true;
		basePlayer.syncPosition = false;
		global::HeldEntity expr_5D = basePlayer.GetHeldEntity();
		if (expr_5D != null)
		{
			expr_5D.SetHeld(false);
		}
		basePlayer.DisablePlayerCollider();
		Rust.Ai.SimpleAIMemory.AddIgnorePlayer(basePlayer);
		global::BaseEntity.Query.Server.RemovePlayer(basePlayer);
		if (!Global.Runner.IsInvoking(new Action(Debugging.TickInvis)))
		{
			Global.Runner.InvokeRepeating(new Action(Debugging.TickInvis), 0f, 0f);
		}
	}
	else if (!@bool && Debugging.invisiblePlayers.Contains(basePlayer))
	{
		Debugging.invisiblePlayers.Remove(basePlayer);
		basePlayer.limitNetworking = false;
		basePlayer.syncPosition = true;
		basePlayer.EnablePlayerCollider();
		Rust.Ai.SimpleAIMemory.RemoveIgnorePlayer(basePlayer);
		global::BaseEntity.Query.Server.RemovePlayer(basePlayer);
		global::BaseEntity.Query.Server.AddPlayer(basePlayer);
		if (Debugging.invisiblePlayers.Count == 0)
		{
			Global.Runner.CancelInvoke(new Action(Debugging.TickInvis));
		}
	}
	arg.ReplyWith("Invis: " + basePlayer.limitNetworking.ToString());
}

Code after:

[ServerVar(Help = "Make admin invisibile")]
public static void invis(ConsoleSystem.Arg arg)
{
	global::BasePlayer basePlayer = arg.Player();
	if (basePlayer == null)
	{
		return;
	}
	bool @bool = arg.GetBool(0, !Debugging.invisiblePlayers.Contains(basePlayer));
	if (@bool && !Debugging.invisiblePlayers.Contains(basePlayer))
	{
		Debugging.invisiblePlayers.Add(basePlayer);
		basePlayer.limitNetworking = true;
		basePlayer.syncPosition = false;
		global::HeldEntity expr_5D = basePlayer.GetHeldEntity();
		if (expr_5D != null)
		{
			expr_5D.SetHeld(false);
		}
		basePlayer.DisablePlayerCollider();
		Rust.Ai.SimpleAIMemory.AddIgnorePlayer(basePlayer);
		global::BaseEntity.Query.Server.RemovePlayer(basePlayer);
		Interface.CallHook("OnVanishDisappear", basePlayer);//<=== OnVanishDisappear
		if (!Global.Runner.IsInvoking(new Action(Debugging.TickInvis)))
		{
			Global.Runner.InvokeRepeating(new Action(Debugging.TickInvis), 0f, 0f);
		}
	}
	else if (!@bool && Debugging.invisiblePlayers.Contains(basePlayer))
	{
		Debugging.invisiblePlayers.Remove(basePlayer);
		basePlayer.limitNetworking = false;
		basePlayer.syncPosition = true;
		basePlayer.EnablePlayerCollider();
		Rust.Ai.SimpleAIMemory.RemoveIgnorePlayer(basePlayer);
		global::BaseEntity.Query.Server.RemovePlayer(basePlayer);
		global::BaseEntity.Query.Server.AddPlayer(basePlayer);
		Interface.CallHook("OnVanishReappear", basePlayer);//<=== OnVanishReappear
		if (Debugging.invisiblePlayers.Count == 0)
		{
			Global.Runner.CancelInvoke(new Action(Debugging.TickInvis));
		}
	}
	arg.ReplyWith("Invis: " + basePlayer.limitNetworking.ToString());
}

Added OnVanishDisappear and OnVanishReappear hooks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant