Ejemplo n.º 1
0
        private void TeleportHome(BasePlayer player, string name)
        {
            PlayerData.PData pdata = PlayerData.Get(player);

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

            // Check if home exists
            if (!playerHomes[player.userID].ContainsKey(name))
            {
                player.ChatMessage($"<color=#d00>Error</color> the home with the name \"{name}\" does not exists.");
                return;
            }

            // Check for the cooldown
            int cooldown = pdata.HasCooldown("teleport_home");

            if (cooldown > 0)
            {
                player.ChatMessage($"<color=#d00>Error</color> teleport cooldown {Helper.TimeFormat.Long(cooldown)}.");
                return;
            }

            TeleportHomeStart(player, playerHomes[player.userID][name], 10);
        }
Ejemplo n.º 2
0
        private void TeleportRequest(BasePlayer player, BasePlayer target)
        {
            PlayerData.PData pdata = PlayerData.Get(player);

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

            // Check for the cooldown
            int cooldown = pdata.HasCooldown("teleport_tpr");

            if (cooldown > 0)
            {
                player.ChatMessage($"<color=#d00>Error</color> teleport to player cooldown {Helper.TimeFormat.Long(cooldown)}.");
                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);

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

            player.ChatMessage($"Teleport request sent to {target.displayName}. Type /tpc to cancel the teleport request.");
            target.ChatMessage($"Teleport request from {player.displayName}. Type /tpa to accept the teleport request. Or type /tpc to cancel the teleport request.");

            pendingTeleportRequests.Add(new TPR()
            {
                player = player,
                target = target,
            });

            timer.Once(30f, () =>
            {
                TPR tpr = FindTPR(player, target);
                if (tpr != null)
                {
                    if (tpr.player != null)
                    {
                        player.ChatMessage($"Teleport request timed out.");
                    }

                    if (tpr.target != null)
                    {
                        target.ChatMessage($"Teleport request timed out.");
                    }

                    pendingTeleportRequests.Remove(tpr);
                }
            });
        }