SANDBOX — this is a test environment. No servers are actually deployed and no real payments are charged.
Back to NxLabs

NxLabs / Vintage Story

Login Protection

XBy Xel

Prevent players from taking damage until they move after logging in

Description

<h3>Tired of dying when logging into a server?</h3> <p>Login Protection prevents the player from taking damage when they join a server because the server thinks the player is ready even though their client is still loading.</p> <p>Once the player moves or does anything, they are considered "active" and no longer protected. Players standing in lava or on fire will also not be protected.</p> <p>There is also a single config option <code>ProtectionTimeSeconds</code>. If this is set to a number then the player's protection will expire that many seconds after logging in (this may be before the player can actually see anything. Make sure you set the number high enough).</p> <p>&nbsp;</p> <p>Exposes a single serverside method to check if a player is protected or not, as well as 3 events:</p> <pre class="language-csharp"><code>var loginProtection = Api.ModLoader.GetModSystem&lt;LoginProtectionModSystem&gt;(); loginProtection.OnLoginProtectionStart += player =&gt; doSomething(player); loginProtection.OnLoginProtectionStop += player =&gt; doSomething(player); loginProtection.OnShouldProtect += player =&gt; shouldProtect(player); if (wouldDoSomething &amp;&amp; loginProtection.IsPlayerProtected(player)) Dont();</code></pre> <div class="spoiler"> <div class="spoiler-toggle">Full code example using reflection:</div> <div class="spoiler-text"> <pre class="language-csharp"><code>internal class YourModSystem : ModSystem { private System.Func&lt;IPlayer, bool&gt; isPlayerProtected;

public void InjurePlayer (IPlayer player) { if (_api.IsServerSide()) { if (isPlayerProtected == null) { var loginProtection = _api.ModLoader.GetModSystem("LoginProtection.LoginProtectionModSystem"); if (loginProtection != null) { var isPlayerProtectedMethod = loginProtection.GetType().GetMethod("IsPlayerProtected"); isPlayerProtected = isPlayerProtectedMethod.CreateDelegate(typeof(System.Func&lt;IPlayer, bool&gt;), loginProtection) as System.Func&lt;IPlayer, bool&gt;; } else { isPlayerProtected = (IPlayer p) =&gt; false; } } if (!isPlayerProtected(player))) { ExplodePlayer(player); } } } }</code></pre></div></div>

Ratings & reviews

No ratings yet

Sign in to leave a rating or comment.