Skip to content

Vanish hooks#541

Merged
MrBlue merged 1 commit intoOxideMod:developfrom
IIIaKa:Vanish
Dec 30, 2024
Merged

Vanish hooks#541
MrBlue merged 1 commit intoOxideMod:developfrom
IIIaKa:Vanish

Conversation

@IIIaKa
Copy link
Copy Markdown
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());
}

@MrBlue MrBlue merged commit 0d02c72 into OxideMod:develop Dec 30, 2024
@IIIaKa IIIaKa deleted the Vanish branch January 2, 2025 06:54
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.

2 participants