Craft help

Discussion in 'Plugin Help' started by Ali26, Nov 14, 2019.

  1. Ali26

    Ali26 Spider

    Messages:
    7
    Hey i need a help for my function, i want to use a config.yml
    main.php
    public function onCraft(PlayerCraftEvent $event) {
    $config = new Config($this->getDataFolder()."players/".strtolower($event->getPlayer()->getName()).".yml", Config::YAML);
    $player = $event->getPlayer();
    foreach($this->cfg->getAll() as $id => $array) {
    foreach($event->getOutputs() as $item){
    if(var_dump($item->getId() == $id and $array["need-lvl"] == $this->cfg->get("need-lvl"))){
    if($array["job"] == $this->config->get('farmer-lvl' or 'bucheron-lvl' or 'alchimiste-lvl' or 'miner-lvl')){
    if($array["need-lvl"] < $array["job"]){
    $event->setCancelled(true);
    if($array["message"] !== " ") {
    $player->sendMessage($array["message"]);
    }
    }
    }
    }
    }
    config. yml
    313: #id item
    job: "bucheron-lvl" #Choose with "bucheron-lvl" or "farmer-lvl" or "alchimiste-lvl" or "miner-lvl"
    need-lvl: 5 #level for unlock craft
    message: "§aYou can't craft this because you are not level 5" #set error message when your level is <
     
  2. Mr174

    Mr174 Baby Zombie

    Messages:
    117
    GitHub:
    Mr174
    Please use the insert code tab to make it easier to read
     
  3. MC ATECH

    MC ATECH Baby Zombie

    Messages:
    111
    GitHub:
    mcpeatech
    Are you getting any errors?
     
  4. Ali26

    Ali26 Spider

    Messages:
    7
    there are no error
     
  5. Ali26

    Ali26 Spider

    Messages:
    7
    ok sorry
     
  6. Ali26

    Ali26 Spider

    Messages:
    7
    In my plugin, they are 2 config one for store xp for job and the other for config.yml
    config.yml
    PHP:
    ---

    305#id item
      
    job"bucheron-lvl" #Choose with "bucheron-lvl" or "farmer-lvl" or "alchimiste-lvl" or "miner-lvl"
      
    need-lvl#level for unlock craft
      
    message"§aYou can't craft this because you are not level 5" #set error message when your level is <

    ...
    Main.php
    PHP:
    public function onCraft(Minecraft $event) {
            
    $config = new Config($this->getDataFolder()."players/".strtolower($event->getPlayer()->getName()).".yml"Config::YAML);
            
    $player $event->getPlayer();

            
    $myJob $this->config->get('farmer-lvl' or 'bucheron-lvl' or 'alchimiste-lvl' or 'miner-lvl');
            
    $array["job"] = $myJob;

            foreach(
    $this->config->get('farmer-lvl' or 'bucheron-lvl' or 'alchimiste-lvl' or 'miner-lvl') as $id => $array) {
                foreach(
    $event->getOutputs() as $item){
                if(
    $item->getId() == $id and $array["need-lvl"] == $this->cfg->get("need-lvl")){
                    if(
    $array["job"] == $this->config->get('farmer-lvl' or 'bucheron-lvl' or 'alchimiste-lvl' or 'miner-lvl')){
                        if(
    $array["need-lvl"] < $array["job"]){
                            
    $event->setCancelled(true);
                            if(
    $event->setCancelled() == true and $array["message"] !== " "){
                                
    $player->sendMessage($array["message"]);
                            }
                        }
                    }
                }   
            }
     
  7. HimbeersaftLP

    HimbeersaftLP Chicken

    Messages:
    1,823
    GitHub:
    HimbeersaftLP
    Uhmm, what is this supposed to do?
     
  8. Ali26

    Ali26 Spider

    Messages:
    7
    i want to cancelled a craft if with a job you don't have enough level to craft a item
     
  9. HimbeersaftLP

    HimbeersaftLP Chicken

    Messages:
    1,823
    GitHub:
    HimbeersaftLP
    No, I mean what's up with the messed up function arguments
     
    Last edited: Nov 16, 2019
  10. Ali26

    Ali26 Spider

    Messages:
    7
    there are no function properties :/
     
  11. HimbeersaftLP

    HimbeersaftLP Chicken

    Messages:
    1,823
    GitHub:
    HimbeersaftLP
    Argument I mean, sorry, that's what happens when I post in autopilot.
    Your first post has "PlayerCraftEvent $event" the second one has "Minecraft $event" while you probably want CraftItemEvent.
     
    Primus likes this.
  12. Ali26

    Ali26 Spider

    Messages:
    7
    oups i had forgotten, the Minecraft event is CraftItemEvent its just a as
     

Share This Page

  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.