api = $api; } public function init(){ $this->api->console->register("calc", "calculates an expression", array($this, "Calculator")); } public function __destruct(){} public function Calculator($cmd, $arg, $issuer) { switch($cmd) { case "calc": $firstValue = $arg[0]; $operator = $arg[1]; $secondValue = $arg[2]; if (empty($arg[0]) || empty($arg[1]) || empty($arg[2])) { if (($issuer instanceof Player)) { $issuer.sendChat("[Calculator] Usage: /calc "); } else{ console("[Calculator] Usage: /calc "); break; } } elseif(!is_numeric($firstValue) || !is_numeric($secondValue)) { if (($issuer instanceof Player)) { $this->api->chat->sendTo(false, "[Calculator] Usage: /calc ", $issuer->username); break; } else{ console("[Calculator] Usage: /calc "); break; } } else { switch($operator) { case "+": $result = $firstValue + $secondValue; if (($issuer instanceof Player)) { $issuer->sendChat("The result is: $result"); break; } else { console("The result is: $result"); break; } //done with + break; case "-": $result = $firstValue - $secondValue; if (($issuer instanceof Player)) { $issuer->sendChat("The result is: $result"); break; } else { console("The result is: $result"); break; } //done with - case "*": $result = $firstValue * $secondValue; if (($issuer instanceof Player)) { $issuer->sendChat("The result is: $result"); break; } else { console("The result is: $result"); break; } //done with * case "/": $result = $firstValue / $secondValue; if (($issuer instanceof Player)) { $issuer->sendChat("The result is: $result"); break; } else { console("The result is: $result"); break; } //done with / default: if (($issuer instanceof Player)) { $this->api->chat->sendTo(false, "[Calculator] Usage: /calc ", $issuer->username); break; } else{ console("[Calculator] Usage: /calc "); break; } } } } } } ?>