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

Command to bottle experience

Discussion in 'Development' started by Zade, Aug 19, 2019.

  1. Zade

    Zade Spider

    Messages:
    11
    How would I go about creating a command say /xp <amount> which would let a player bottle their xp into a bottle and right click the bottle to redeem the experience again?
     
  2. Zade

    Zade Spider

    Messages:
    11
    Here is the code I've got, but it tends to yield no results and there's no error messages either:
    PHP:
            public function calculateExpReduction($p$exp) {
            if(
    $p instanceof Human){
                
    $xp $p->getTotalXp();
                
    $p->setTotalXp($xp $exp);
            }
        }

        public function 
    redeemExp($player$exp) {
                if(
    $player instanceof Human){
                
    $currentExp $player->getTotalXp();
                if (
    $exp 32000) {
                    
    $player->sendMessage(TF::RED TF::BOLD "(!) " TF::RESET TF::RED "You cannot redeem more than 32000 XP at once.");
                    return 
    false;
                }
                    if (
    $currentExp >= $exp) {
                    
    $this->calculateExpReduction($player$exp);
                    
    $xpBottle Item::get(384$exp1);
                    
    $xpBottle->setCustomName(TF::GREEN TF::BOLD "Experience Bottle " TF::RESET TF::GRAY "(Throw)\n" TF::LIGHT_PURPLE "Value: " TF::WHITE $exp "\n" TF::LIGHT_PURPLE "Redeemed by: " TF::WHITE $player->getName());
                    
    $player->getInventory()->addItem($xpBottle);
                    
    $player->sendMessage(TF::GREEN TF::BOLD "XPBottle " TF::RESET TF::GREEN "You have successfully redeemed " TF::YELLOW $exp TF::GREEN ".");
                    
    $player->getLevel()->addSound(new ExpPickupSound($player), [$player]);
                } else {
                    
    $player->sendMessage(TF::RED TF::BOLD "XPBottle " TF::RESET TF::RED "You don't have enough experience. Your current experience is " TF::YELLOW $currentExp);
                    }
            }

    -----------------------------------------

                if (
    $args[0] == "xpbottle") {
                    if(
    $sender instanceof Human){
                        if (!isset(
    $args[1])) {
                            
    $sender->sendMessage(TF::YELLOW "/xpbottle <amount>\n" TF::GRAY "Converts <amount> xp into bottle form.\n" TF::GRAY "Use " TF::YELLOW "/xp" TF::GRAY " to view your current exp points.\n".TF::ITALIC.TF::GRAY."Your current XP: ".TF::GOLD.$sender->getTotalXp());
                        }
                        if (isset(
    $args[1])) {
                            if (
    is_numeric($args[1]) && $args[1] > 0$this->redeemExp($sender$args[0]);
                            else 
    $sender->sendMessage(TF::RED TF::BOLD "XPBottle " TF::RESET TF::RED "You have provided an invalid amount.");
                        }
                    }
                }



    When I run the command /o xpbottle, I get no results
     
    Last edited: Aug 19, 2019
  3. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    Did you forget the use statement for Human?
     
  4. Fadhel

    Fadhel Witch

    Messages:
    68
    GitHub:
    dimbis
    if you trying to check if the sender was player change the Human to Player.
     
    HimbeersaftLP 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.