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

Help please D=

Comments in 'Plugin Development' started by iDirtPlayzMC, Jun 30, 2015.

  1. iDirtPlayzMC
    Offline

    iDirtPlayzMC Active Member

    Joined:
    Apr 10, 2015
    Posts:
    264
    Minecraft User:
    iZenith_xPr
    I try to make plugin that when player step on and they get effect...
    heres code
    PHP:
        public function onMove(PlayerMoveEvent $ev){
            if (
    $ev->isCancelled()) return;
            
    $cfg $this->getConfig();
            
    $effectid $cfg->get("effectid");
            
    $duration $cfg->get("duration");
            
    $blockid $cfg->get("blocks");
            
    $to $ev->getTo();
            
    $id $to->getLevel()->getBlockIdAt($to->getX(), $to->getY() - 1$to->getZ());
            if (isset(
    $this->$blockid[$id])) {
                
    $ev->getPlayer()->addEffect(Effect::getEffect($effectid)->setDuration($duration));
            }
    please check If i miss or did anything wrong ;-; Im suck at this
  2. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    isset() checks whether the Index $id is set in the Array. Example:
    Code:
    #config:
    blocks:
    #Index 1:
       - 123
    #Index 2:
       - 456
    # Index 3:
       - 789
    # etc...
    So if you use isset() in an array, it will search the Index, not whether the ID is set in the config.
    You can use in_array.
    Last edited: Jun 30, 2015
  3. GmWM
    Offline

    GmWM Active Member Plugin Developer

    Joined:
    Sep 8, 2013
    Posts:
    181
    Plugins:
    3
    I'm working on this. But I don't know when it will be done, because I don't have much time free.
  4. iDirtPlayzMC
    Offline

    iDirtPlayzMC Active Member

    Joined:
    Apr 10, 2015
    Posts:
    264
    Minecraft User:
    iZenith_xPr
    Uhm idk whut to do
  5. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Try this:
    PHP:
    public function onMove(PlayerMoveEvent $ev){
            if (
    $ev->isCancelled()) return;
            
    $cfg $this->getConfig();
            
    $effectid $cfg->get("effectid");
            
    $duration $cfg->get("duration");
            
    $blockid $cfg->get("blocks");
            
    $to $ev->getTo();
            
    $id $to->getLevel()->getBlockIdAt($to->getX(), $to->getY() - 1$to->getZ());
            if (
    in_array($id$blockid)) {
                
    $ev->getPlayer()->addEffect(Effect::getEffect($effectid)->setDuration($duration));
            }
  6. iDirtPlayzMC
    Offline

    iDirtPlayzMC Active Member

    Joined:
    Apr 10, 2015
    Posts:
    264
    Minecraft User:
    iZenith_xPr
    Code:
    [CRITICAL] "Could not pass event 'pocketmine\event\player\PlayerMoveEvent' to 'BlockEffect v1.0.0': in_array() expects parameter 2 to be array, integer given on iDirtniverse\BlockEffect\Main
    22:01:04 [WARNING] InvalidArgumentException: "in_array() expects parameter 2 to be array, integer given" (E_WARNING) in "/BlockEffect/src/iDirtniverse/BlockEffect/Main" at line 62
    
    all code :
    PHP:
    <?php

    namespace iDirtniverse\BlockEffect;

    use 
    pocketmine\event\player\PlayerMoveEvent;
    use 
    pocketmine\math\vector3;
    use 
    pocketmine\utils\TextFormat;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\event\level;
    use 
    pocketmine\event\player\PlayerChatEvent;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\Player;
    use 
    pocketmine\entity\Effect;
    use 
    pocketmine\utils\Config;

    class 
    Main extends PluginBase implements Listener
    {
        private 
    $players = array();

        public function 
    onEnable()
        {
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
            
    $this->getLogger()->info(TextFormat::DARK_GREEN "Im Enabled");
            
    $this->path $this->getDataFolder();
            @
    mkdir($this->path);
            
    $this->config = new Config($this->path "config.yml"Config::YAML, array(
                
    "blocks" => 133,
                
    "effectid" => 1,
                
    "duration" => 1500,
            ));
            
    $this->saveDefaultConfig();
            
    $this->reloadConfig();
        }

        
    //On Disable.
        
    public function onDisable()
        {
            
    $this->getLogger()->info(TextFormat::DARK_RED "Im Disabled");
            
    $this->saveDefaultConfig();
        }

        public function 
    onCommand(CommandSender $senderCommand $command$label, array $args)
        {
            
    $cmd strtolower($command->getName());
            switch (
    $cmd) {
                case 
    "be":
                    
    $sender->sendMessage(TextFormat::GREEN "Place block of emerald block and step on it!");
            }
        }

        public function 
    onMove(PlayerMoveEvent $ev)
        {
            if (
    $ev->isCancelled()) return;
            
    $cfg $this->getConfig();
            
    $effectid $cfg->get("effectid");
            
    $duration $cfg->get("duration");
            
    $blockid $cfg->get("blocks");
            
    $to $ev->getTo();
            
    $id $to->getLevel()->getBlockIdAt($to->getX(), $to->getY() - 1$to->getZ());
            if (
    in_array($id$blockid)) {
                
    $ev->getPlayer()->addEffect(Effect::getEffect($effectid)->setDuration($duration));
            }
        }
    }

    ?>
  7. DA_Swagnemite
    Offline

    DA_Swagnemite Notable Member Plugin Developer

    Joined:
    Nov 17, 2013
    Posts:
    386
    Plugins:
    7
    Minecraft User:
    DA_SWAGNEMITE
    #ReadTheDocs
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Wrong. Index starts from 0 not 1.
    Jon likes this.
  9. GmWM
    Offline

    GmWM Active Member Plugin Developer

    Joined:
    Sep 8, 2013
    Posts:
    181
    Plugins:
    3
    It's done, but currently awaiting approval.
    It will be awesome! Wait for it! :D

Share This Page

Advertisement