• Forum
  • Doc
  • Screenshots
  • Download
  • Donate
  • Contributors
  • Contact
  • Follow @phpfreechat
  • DEMO
  • Board index ‹ Version 1.x branch ‹ Contributions (v1.x)
  • Change font size
  • FAQ
  • Register
  • Login

Coin flip

Post a bug fix, a new feature, a theme ...

Moderators: OldWolf, re*s.t.a.r.s.*2

Post a reply
2 posts • Page 1 of 1

Postby MaDc0w » Tue Aug 19, 2008 9:13 pm

Well since i'm still waiting here on any sign of life or support I decided to make a small game while waiting:

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
MaDc0w
MaDc0w
Member
 
Posts: 20
Joined: Tue Aug 12, 2008 10:32 am
  • Website
Top

Postby mike54721 » Mon Sep 21, 2009 9:14 am

nice!
mike54721
New member
 
Posts: 2
Joined: Mon Sep 21, 2009 9:09 am
Top


Post a reply
2 posts • Page 1 of 1

Return to Contributions (v1.x)

Who is online

Users browsing this forum: Google [Bot] and 11 guests

  • Board index
  • The team • Delete all board cookies • All times are UTC + 1 hour
Powered by phpBB® Forum Software © phpBB Group
Sign in
Wrong credentials
Sign up I forgot my password
.
jeu-gratuit.net | more partners
Fork me on GitHub