Command: /flip {heads/tails}
First add these lines at the bottom of /i18n/your_language/main.php
- Code: Select all
// flip game
$GLOBALS["i18n"]["Flipped coin landed on heads! "] = "Flipped coin landed on heads! ";
$GLOBALS["i18n"]["Flipped coin landed on tails! "] = "Flipped coin landed on tails! ";
$GLOBALS["i18n"]["You lose!"] = "You lose!";
$GLOBALS["i18n"]["You win!"] = "You win!";
Create a new file in /src/commands called flip.class.php
Paste the following into it:
- Code: Select all
<?php
/**
* flip.class.php
*
* Copyright © 2008 MaDc0w <MaDc0w@undergroundz.org>
* phpFreeChat Copyright © 2008 Stephane Gully <stephane.gully@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
require_once(dirname(__FILE__)."/../pfccommand.class.php");
class pfcCommand_flip extends pfcCommand
{
var $usage = "/flip {heads/tails}";
function run(&$xml_reponse, $p)
{
$clientid = $p["clientid"];
$param = $p["param"];
$sender = $p["sender"];
$recipient = $p["recipient"];
$recipientid = $p["recipientid"];
$c =& pfcGlobalConfig::Instance();
$u =& pfcUserConfig::Instance();
$ct =& pfcContainer::Instance();
if (trim($param) == "")
{
// error
$cmdp = $p;
$cmdp["param"] = _pfc("Missing parameter");
$cmdp["param"] .= " (".$this->usage.")";
$cmd =& pfcCommand::Factory("error");
$cmd->run($xml_reponse, $cmdp);
return;
}
$flipping = rand(1,1000);
if(($flipping - (2 * floor($flipping/2))) == 0)
{
$heads = true;
$msg .= _pfc("Flipped coin landed on heads! ");
}
else
{
$heads = false;
$msg .= _pfc("Flipped coin landed on tails! ");
}
if ((trim($param) == "heads") && ($heads))
{
$msg .= _pfc("You win!");
$ct->write($recipient, "*me*", $this->name, $u->getNickname()." Choose heads: ".$msg."");
}
if ((trim($param) == "heads") && (!$heads))
{
$msg .= _pfc("You lose!");
$ct->write($recipient, "*me*", $this->name, $u->getNickname()." Choose heads: ".$msg."");
}
if ((trim($param) == "tails") && (!$heads))
{
$msg .= _pfc("You win!");
$ct->write($recipient, "*me*", $this->name, $u->getNickname()." Choose tails: ".$msg. "");
}
if ((trim($param) == "tails") && ($heads))
{
$msg .= _pfc("You lose!");
$ct->write($recipient, "*me*", $this->name, $u->getNickname()." Choose tails: ".$msg."");
}
}
}
?>
Have fun.
MaDc0w