đź“–
Wiki Nova Life
  • Bienvenue !
  • Discord MOD
  • Serveur
    • Introduction
    • L'hĂ©bergeur
    • La configuration
    • Ajouter des plugins
  • Plugins
    • Introduction
    • Informations pour dĂ©buter
    • Aides
      • ModKit
      • Base d'un plugin
      • CenterText
      • Config JSON
      • Commande
      • Cooldown individuel
      • Cooldown global
      • ÉvĂ©nements
      • Points
      • Panels
      • Webhook (Embed)
      • Webhook (Message)
  • Flocages
    • Introduction
    • Informations pour dĂ©buter
    • Flocage de vĂŞtement
    • Flocage de vĂ©hicule
    • Flocage de panneau
Propulsé par GitBook
Sur cette page
  1. Plugins
  2. Aides

Cooldown individuel

Voici le code pour créer un cooldown individuel :

// Dictionnaire pour stocker le dernier moment d'action du joueur
private Dictionary<string, DateTime> cooldowns = new Dictionary<string, DateTime>();

// Durée du cooldown en heures
private TimeSpan cooldownDuration = TimeSpan.FromHours(12);

// Vérifie si le joueur peut réaliser l'action en fonction du cooldown
private bool TryGetCooldown(Player player, out TimeSpan remainingTime)
{
    if (cooldowns.TryGetValue(player.GetFullName(), out DateTime lastActionTime))
    {
        TimeSpan elapsedTime = DateTime.Now - lastActionTime;
        if (elapsedTime < cooldownDuration)
        {
            remainingTime = cooldownDuration - elapsedTime;
            return true;
        }
    }

    remainingTime = TimeSpan.Zero;
    return false;
}

// Met Ă  jour le cooldown du joueur
private void UpdateCooldown(Player player)
{
    cooldowns[player.GetFullName()] = DateTime.Now;
}

// Exemple d'utilisation pour vérifier si un joueur peut effectuer une action
public void PerformAction(Player player)
{
    if (TryGetCooldown(player, out TimeSpan remainingTime))
    {
        player.Notify("Erreur", $"Vous devez encore attendre {remainingTime} avant de pouvoir réaliser cette action.", NotificationManager.Type.Error);
        return;
    }

    UpdateCooldown(player);
    // Code pour réaliser l'action...
    player.Notify("Succès", "Vous avez effectué l'action avec succès.", NotificationManager.Type.Success);
}
PrécédentCommandeSuivantCooldown global

Dernière mise à jour il y a 3 mois