1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Need some help

Discussion in 'Development' started by str0nix, Aug 14, 2020.

  1. str0nix

    str0nix Spider Jockey

    Messages:
    33
    GitHub:
    str0nixofficial
    Greetings,

    I'm new at coding and I need some help, because I don't know why this isn't working.
    Thanks any help in advance, have a great day!
    PHP:
    public function tierSystem(PlayerDeathEvent $event){

    $kdr $this->getServer()->getPluginManager()->getPlugin("KDR");
    $player $event->getPlayer();
    $killdata $kdr->getProvider()->getPlayerKillPoints($player);
    $firsttier 5# Award should be given after the 5th kill
    $killer $player->getLastDamageCause()->getDamager();

    if(
    $player->getLastDamageCause() instanceof EntityDamageByEntityEvent){
        if(
    $player->getLastDamageCause()->getDamager() instanceof Player){
            if(
    $killdata === $firsttier){
                
    $killer->sendMessage("§8[§b!§8]§7 You are on the first Tier! Your reward:§b 500$");
                
    $killer->sendTitle("§aTier 1 unlocked!");
                
    $killer->sendSubTitle("§7Your reward: §6500$");
                
    $this->getServer()->getPluginManager()->getPlugin("EconomyAPI");
                
    EconomyAPI::getInstance()->addMoney($killer500);
            }
        }
    }
     
  2. Primus

    Primus Zombie Pigman

    Messages:
    749
    You gave no useful information.

    Are there any errors? Did you register Listener? What's the expected behavior and whats the one you observe?
     
  3. str0nix

    str0nix Spider Jockey

    Messages:
    33
    GitHub:
    str0nixofficial
    I would like to make a plugin which rewards the player for every 5th kill. I get the kills data from the KDR plugin.
    In the current code, if the player has 5 kill, he or she should get 500 dollar after the 5th kill. When I get the 5th kill, nothing happens.
     
  4. Primus

    Primus Zombie Pigman

    Messages:
    749
    I'll teach you a valuable lesson. Simple output of the data can help you find the cause

    PHP:
    public function tierSystem(PlayerDeathEvent $event){

    # Add log message to see if this code gets executed at all
    $this->getServer()->getLogger()->notice(__CLASS__."::".__METHOD__." executed (Line: ".__LINE__.")");

    $kdr $this->getServer()->getPluginManager()->getPlugin("KDR");
    $player $event->getPlayer();
    $killdata $kdr->getProvider()->getPlayerKillPoints($player);
    $firsttier 5# Award should be given after the 5th kill
    $killer $player->getLastDamageCause()->getDamager();

    if(
    $player->getLastDamageCause() instanceof EntityDamageByEntityEvent){
        
    # DEBUG
        
    $this->getServer()->getLogger()->notice("Last damage cause was caused by entity");
        if(
    $player->getLastDamageCause()->getDamager() instanceof Player){
        
    # DEBUG
        
    $this->getServer()->getLogger()->notice("Last damager was instanceof Player");
        
    $this->getServer()->getLogger()->notice("Checking: {$killdata} === {$firsttier}");
            if(
    $killdata === $firsttier){
                
    $killer->sendMessage("§8[§b!§8]§7 You are on the first Tier! Your reward:§b 500$");
                
    $killer->sendTitle("§aTier 1 unlocked!");
                
    $killer->sendSubTitle("§7Your reward: §6500$");
                
    $this->getServer()->getPluginManager()->getPlugin("EconomyAPI");
                
    EconomyAPI::getInstance()->addMoney($killer500);
            }
        }
    }
    Do you have registered listener? Something like this:
    PHP:
    public function onEnable() {
        
    $this->getServer()->getPluginManager()->registerEvents($this$this);
    }
     
    GamakCZ likes this.
  5. str0nix

    str0nix Spider Jockey

    Messages:
    33
    GitHub:
    str0nixofficial
    Yes I did, I registered the Listener
     
    Primus likes this.
  6. str0nix

    str0nix Spider Jockey

    Messages:
    33
    GitHub:
    str0nixofficial
    Thanks for teaching me, successfully I found the error, and now everything works. Thanks for your time and help. Have a wonderful day!
     
    Primus likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.