JoinWorld Restrictions

For all mod-related questions and custom code.
Post Reply
BinaryX
Offline
Posts: 8
Joined: October 13th, 2011, 3:52 pm
Location: The Netherlands
Contact:

JoinWorld Restrictions

Post by BinaryX »

Used in my faction system but can be used for anything.
Place this method in the OnJoinWorld Event and you'll be able to either deny or allow the player to Join any world based on certain criteria.

Put this in a new class (static) so that it's accessible.
Note: might want to adjust the criteria and get rid of the faction code.

Code: Select all

        public static Boolean CanJoin(World w, Player player, WorldChangeReason reason)
        {
            if (w == null) return false;
            if (reason == WorldChangeReason.Bring) return true;
            if (w.Faction == 0) return true;
            if (player.Info.FactionOverride) return true;
            Faction worldFaction = getFaction(w.Faction);
            if (!worldFaction.getId().Equals(player.Info.Faction)) return false;
            return true;
        }
Player.Networking.cs under the declaration of the variable useWorldSpawn are 3 methods.
By using an if-statement; check if the function returns either true or false and then do/return something.
Example:

Code: Select all

if (!MyStaticClass.CanJoin(newWorld, this, reason)) return false;
     if( RaisePlayerJoiningWorldEvent( this, newWorld, reason, textLine1, textLine2 ) ) {

Post Reply