Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Playerdeath gives killer money

Comments in 'Plugin Development' started by PixelGuy75, Dec 13, 2014.

  1. PixelGuy75
    Offline

    PixelGuy75 Notable Member Plugin Developer

    Joined:
    Feb 9, 2014
    Posts:
    316
    Plugins:
    2
    Minecraft User:
    PixelGuy75
    I'm trying to make it so when someone kills a player, the killer gets money. You probably know that KillMoney does this, but the plugin does not work. I am also using PocketMoney instead of EconomyAPI. Here's my code, can someone tell me what to fix.
    PHP:
    public function onPlayerKilled(PlayerDeathEvent $event) {
            
    $entity $event->getEntity();
            
    $lastAttack $entity->getLastDamageCause();
            if (
    $lastAttack instanceof EntityDamageByEntityEvent) {
                
    $attacker $lastAttack->getDamager();
                
    $victim $lastAttack->getEntity();
                if (
    $attacker instanceof Player) {
                    
    $value 30;
                    
    $attacker->sendMessage("You killed "$victim ." and earned 30 coins!");
                    
    $this->owner->getServer()->getPluginManager()->getPlugin("PocketMoney")->grantMoney($attacker$value);
                    }
                }
        }
  2. CookieSteve
    Offline

    CookieSteve Active Member

    Joined:
    Apr 22, 2014
    Posts:
    132
    Minecraft User:
    iStrqfeChris
    Killmoney does work and even if it didn't why make a whole plugin just fix the one that's already made
  3. PixelGuy75
    Offline

    PixelGuy75 Notable Member Plugin Developer

    Joined:
    Feb 9, 2014
    Posts:
    316
    Plugins:
    2
    Minecraft User:
    PixelGuy75
    That's what I'm actually doing is trying to fix Killmoney, but the developer doesn't have a github so no one can make any pull requests.
  4. PixelGuy75
    Offline

    PixelGuy75 Notable Member Plugin Developer

    Joined:
    Feb 9, 2014
    Posts:
    316
    Plugins:
    2
    Minecraft User:
    PixelGuy75
    Also when a player dies from something other than another player, the server crashes.
  5. Xenturio
    Offline

    Xenturio Active Member

    Joined:
    Sep 19, 2014
    Posts:
    333
    Minecraft User:
    Xenturio
    u can use this
    $i = "givemoney {PLAYER} 30";
    $this->getServer()->dispatchCommand(new ConsoleCommandSender(),str_replace("{PLAYER}",$event->getPlayer()->getName(),$i));
    instead of
    $this->owner->getServer()->getPluginManager()->getPlugin("PocketMoney")->grantMoney($attacker, $value);

    dont know if $this->owner->getServer() is the problem
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Do not use dispatchCommand(). It is a bad practice to dispatch commands directly as it is slower.

    How to get the Server object depends on the context you're in.

Share This Page

Advertisement