Exemple #1
0
        private void TeleportHomeStart(BasePlayer player, Vector3 position, int countdown = 0)
        {
            PlayerData.PData pdata = PlayerData.Get(player);

            if (player == null || position == null || pdata == null)
            {
                return;
            }

            // Check if the teleport from location is valid
            string teleportFrom = CanTeleportFrom(player);

            if (teleportFrom != null)
            {
                player.ChatMessage($"<color=#d00>Error</color> you cannot teleport from your current location ({teleportFrom}).");
                return;
            }

            // Check if the teleport destination is valid
            string teleportTo = CanTeleportToPosition(player, position);

            if (teleportTo != null)
            {
                player.ChatMessage($"<color=#d00>Error</color> you cannot teleport to your home ({teleportTo}).");
                return;
            }

            // When there is a countdown timer, intialize a timer and notification timer
            if (countdown > 0)
            {
                Notifications.AddTimedNotification(player, "teleport_home", "Teleport Home", countdown, "0.3 0.3 0.3 1");
                timer.Once(countdown, () => TeleportHomeStart(player, position));
                return;
            }

            // Remove the notification timer
            Notifications.RemoveTimedNotification(player, "teleport_home");

            // Set the cooldown for the teleport
            int cooldownDuration = 60 * 20;

            if (Helper.HasMinimumVipRank(pdata, "vip"))
            {
                cooldownDuration = 60 * 5;
            }

            // Set the cooldown timer
            pdata.AddCooldown("teleport_home", cooldownDuration);

            // Execute the teleportation
            ExecuteTeleport(player, position);
        }
Exemple #2
0
        private void TeleportRequestStart(BasePlayer player, BasePlayer target, int countdown = 0)
        {
            PlayerData.PData pdata = PlayerData.Get(player);

            if (player == null || target == null || pdata == null)
            {
                return;
            }

            // Check if the player can teleport from the current location
            string canTeleportFrom = CanTeleportFrom(player);

            if (canTeleportFrom != null)
            {
                player.ChatMessage($"<color=#d00>Error</color> you cannot teleport from your current location ({canTeleportFrom}).");
                return;
            }

            // Check if the player can teleport to the target location
            string canTeleportToPosition = CanTeleportToPosition(player, target.transform.position);

            if (canTeleportToPosition != null)
            {
                player.ChatMessage($"<color=#d00>Error</color> you cannot teleport to {target.displayName} ({canTeleportFrom}).");
                return;
            }

            // Check if the player can teleport to the target itself
            string canTeleportToPlayer = CanTeleportToPlayer(player, target, false);

            if (canTeleportToPlayer != null)
            {
                player.ChatMessage($"<color=#d00>Error</color> you cannot teleport to {target.displayName} ({canTeleportToPlayer}).");
                return;
            }

            // When there is a countdown timer, intialize a timer and notification timer
            if (countdown > 0)
            {
                Notifications.AddTimedNotification(player, "teleport_tpr", "Teleporting", countdown, "0.3 0.3 0.3 1");
                Notifications.AddTimedNotification(target, "teleport_tpr", "Teleporting", countdown, "0.3 0.3 0.3 1");
                timer.Once(countdown, () => TeleportRequestStart(player, target));
                return;
            }

            // Remove the notification timer
            Notifications.RemoveTimedNotification(player, "teleport_tpr");
            Notifications.RemoveTimedNotification(target, "teleport_tpr");

            // Set the cooldown for the teleport
            int cooldownDuration = 60 * 20;

            if (Helper.HasMinimumVipRank(pdata, "vip"))
            {
                cooldownDuration = 60 * 5;
            }

            // Set the cooldown timer
            pdata.AddCooldown("teleport_tpr", cooldownDuration);

            // Execute the teleportation
            ExecuteTeleport(player, target.transform.position);
        }