Hi, I want to add float var in "public function onCommand" . Is it possible ? Code: <?php namespace CustomDamageItem; use pocketmine\plugin\PluginBase; use pocketmine\event\Listener; use pocketmine\command\CommandSender; use pocketmine\command\Command; use pocketmine\event\entity\EntityDamageEvent; use pocketmine\event\entity\EntityDamageByEntityEvent; use pocketmine\event\player\PlayerItemHeldEvent; use pocketmine\Player; use pocketmine\Server; use pocketmine\item\Item; use pocketmine\entity\Entity; use pocketmine\utils\TextFormat; class Main extends PluginBase implements Listener { public function onEnable() { $this->getServer()->getPluginManager()->registerEvents($this, $this); } /** * @param float $customDamage * @return int **/ public function onCommand($customDamage, CommandSender $sender, string $labels, Command $cmd, array $args): bool { if (!$sender instanceof Player()) { $sender->sendMessage(TextFormat::RED . "Cette commande doit être utiliser en jeu."); return true; } if (!isset($args[0])) { if ($sender->hasPermission("cid.command")) { $sender->sendMessage(TextFormat::RED . "Usage: /cid set|reset"); return false; } } if ($args[0] === "set") { if ($sender->hasPermission("cid.command") && $sender->hasPermission("cid.command.set")) { $sender->sendMessage("Usage: /cid set <id>"); return true; } } if ($args[0] === "reset") { if ($sender->hasPermission("cid.command") && $sender->hasPermission("cid.command.reset")) { $sender->sendMessage("Usage: /cid reset <id>"); } } if ($args[1] === "352" || $args[1] === "bone") { if ($sender->hasPermission("cid.command")) { if ($sender->hasPermission("cid.command.set") && $sender->hasPermission("cid.command.set.id")) { $sender->sendMessage("Usage: /cid set $args[1] <damage>"); } else { if ($sender->hasPermission("cid.command.reset") && $sender->hasPermission("cid.command.reset.id")) { $event->setDamage(0.25); } } } } if ($args[2] === $customDamage) { if (is_numeric($customDamage)) { if ($sender->hasPermission("cid.command") && $sender->hasPermission("cid.command.set") && $sender->hasPermission("cid.command.id") && $sender->hasPermission("cid.command.id.damage")) { $event->setDamage($customDamage); } } if (!is_numeric($customDamage)) { $sender->sendMessage("Les points d'attaques doivent être en valeur numérique !"); } } } public function onItemHeld(PlayerItemHeldEvent $event) { if ($event->getItem()->getId() == 352) { $event->getPlayer()->sendPopup("Épée en Améthyste"); } } public function onEntityDamageByEntity(EntityDamageEvent $event) { if ($event instanceof EntityDamageByEntityEvent) { $entity = $event->getEntity(); $player = $event->getDamager(); if ($entity instanceof Player && $player instanceof Player) { $item = $player->getInventory()->getItemInHand()->getID(); if ($item == 352) { $event->setDamage(6.0); } } } } }
well, in php we cannot declare real datatypes on variables. Assuming you want to have a "float" command argument all you need is to typecast the string argument to a float $floatArg = (float) $args[x]
PHP: if(args[2] === $customDamage){ if(is_numeric($customDamage)){ if($sender->hasPermission("cid.command") && $sender->hasPermission("cid.command.set") && $sender->hasPermission("cid.command.id") && $sender->hasPermission("cid.command.id.damage")){ $event->setDamage($customDamage); } } if(!is_numeric($customDamage)){ $sender->sendMessage("Les points d'attaque doivent être en valeur numérique !") } } I want to do "if args 2 is a float , check if player as some permission and set damage when user input float value"
is_float() won't check whether your string represents a number. It will always return false with a string.
PHP: // inside ur code bracesif (is_numeric($args[2) === false) { // invalid input return false;}$floatInput = (float) $args[2]; // now you can cast it as float.