Ich habe eine Rollenspiel-Würfelfunktion geschrieben, die auch mit 20-seitigen Würfeln u.a. zurechtkommt.
/dice AnzahlWürfel AnzahlAugen, also z.B. /dice 3 20 für 3W20 nach DSA-Standard oder halt /dice 5 6 für 5W6. Man kann auch /dice ohne Parameter angeben ,dann würfelt er mit 1W20
PHP: DiceCommand.class.php
<?php
namespace chat\system\command\commands;
/**
* Rollenspiel-Würfelfunktion
*/
class DiceCommand extends \chat\system\command\AbstractCommand {
public $diceText;
public function __construct(\chat\system\command\CommandHandler $commandHandler) {
parent::__construct($commandHandler);
try { list($az1, $az2) = explode(' ', $commandHandler->getParameters(), 2); }
catch (\wcf\system\exception\SystemException $e) {
$az1=1; $az2=20;
}
$random="";
for ($i=1;$i<$az1+1;$i++)
{
if ($i<$az1) { $random.=mt_rand(1,$az2).","; }
if ($i==$az1) { $random.=mt_rand(1,$az2); }
}
$this->diceText = "würfelt ".$az1."W".$az2.": [B]" .$random."[/B]";
$this->didInit();
}
/**
* @see \chat\system\command\ICommand::getType()
*/
public function getType() {
return \chat\data\message\Message::TYPE_ME;
}
/**
* @see \chat\system\command\ICommand::getMessage()
*/
public function getMessage() {
return $this->diceText;
}
}
Display More