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

full inventory swap

Comments in 'Plugin Development' started by dxm_hippie, Sep 16, 2015.

  1. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    PHP:
    public function onDeath(PlayerDeathEvent $event){
    $victim $event->getEntity();
    if(!
    $victim->getLastDamageCause() instanceof EntityDamageByEntityEvent) return;
    $attacker $victim->getLastDamageCause()->getDamager();
    if(
    $attacker instanceof Player){
    $loot $victim->getInventory()->getContents();
    foreach(
    $loot as $item){
      
    $attacker->getInventory()->addItem($item);
    }
    }
    }
    Should work.
    Taha_The_Hacker and dxm_hippie like this.
  2. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    Wow im not copying anything.. I'm simply modifying other peoples plugins to my likeing.
  3. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    What plugin is this?
  4. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
  5. andre_the_gamer
    Offline

    andre_the_gamer Active Member

    Joined:
    Feb 5, 2015
    Posts:
    112
    Minecraft User:
    Andre_The_Gamer
    Ok :)
  6. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    why wont this work?

    PHP:
    public function onPlayerDeath(PlayerDeathEvent $event){
            
    $deadPlayer $event->getEntity();
                    
    $killer $deadPlayer->getLastDamageCause();
                       
                    if(
    $killer instanceof EntityDamageByEntityEvent){
                       
    $killer $killer->getDamager();
                    if(
    $killer instanceof Player) {
                    
    $killer->getInventory()->addItem($event->getDrops()); 
                   }
                 }
  7. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    getDrops

    Plural...
  8. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    Thanks I didn't see that will try it!
  9. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    Won't the inventory be empty if the player already died tho? /:
    Legoboy0215 likes this.
  10. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Thats why you need to TEST it. Don't understand it? Try and test it and see the result.
  11. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    so it should be getDrop(); ??
  12. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Use this.
    PHP:
    public function onDeath(PlayerDeathEvent $event){
      
    $last $event->getEntity()->getLastDamageCause();
      if(
    $last instanceof EntityDamageByEntityEvent){
        
    $killer $last->getDamager();
        if(
    $killer instanceof Player and $killer->isOnline()){ // check online to prevent crash if player shoots an arrow to kill someone but leaves the server before the arrow hits
          
    $killer->getInventory()->addItem(...$event->getDrops());
          
    $event->setDrops([]);
        }
      }
    }
    That's the question initially...
  13. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    I could use setDrops([]) so the dead person keeps their inventory maybe?
    Legoboy0215 likes this.
  14. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Nothing :p. @PEMapModder's code may work.
  15. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Because addItem accepts variadic Item objects, not an Item array.
    Next time please show the error message instead of saying that it "does not work". Not everyone is as clever as me ;) :p
    Primus and Legoboy0215 like this.
  16. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Wait. So getDrops is really plural?
    Plural = array. It does not accept arrays?
    And why ...?
  17. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Who was that :oops:
  18. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    Didnt work just dropped the items like normal witch is weird, no error. /: maybe i could use $event->setKeepDrops(true); then get the dead players inv and transfer it? then set the dead plaers inv to null? idk..
  19. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Registered listener?
    PEMapModder likes this.
  20. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    That's the problem.. there was no error with this. just simply did nothing along with the code you proposed. witch don't make sense ik..
    Last edited: Sep 16, 2015

Share This Page

Advertisement