• 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

Role Play Commands

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 IronLX » Sat Aug 20, 2011 1:04 pm

I added these commands, they're plug'n'play so just make the file, copy the code, rehash and there you go!
Attack and Hug use a role play system where it deals or heals random damage, everyone has 1000hp and 0 exp at level 0, every time you kill someone you gain 1 exp, every 100 exp you level up! :D

Simple /dice command (Rolls a 6 sided dice) dice.class.php
Code: Select all
<?php

require_once(dirname(__FILE__)."/../pfccommand.class.php");

class pfcCommand_dice extends pfcCommand
{
  var $usage = "/dice";

  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();

    $msg = phpFreeChat::PreFilterMsg(rand(1,6));
    $cmdp = $p;
    $cmdp["recipient"] = $recipient;
    $cmdp["recipientid"] = $recipientid;
    $cmdp["param"] = _pfc("%s rolls a dice: It lands %s!",$u->getNickname(), $msg);
    $cmd =& pfcCommand::Factory("notice");
    $cmd->run($xml_reponse, $cmdp);
  }
}

?>

/attack command (Attacks target with optional weapon) attack.class.php
Code: Select all
<?php

require_once(dirname(__FILE__)."/../pfccommand.class.php");

class pfcCommand_attack extends pfcCommand
{
  var $usage = "/attack {nick} [{tool}]";

  function run(&$xml_reponse, $p)
  {
    $clientid    = $p["clientid"];
    $param       = $p["param"];
    $params      = $p["params"]; // modif 1
    $sender      = $p["sender"];
    $recipient   = $p["recipient"];
    $recipientid = $p["recipientid"];

    $c  =& pfcGlobalConfig::Instance();
    $u  =& pfcUserConfig::Instance();
    $ct =& pfcContainer::Instance();

    $nick   = isset($params[0]) ? $params[0] : '';
    $tool = isset($params[1]) ? $params[1] : '';
    $tool = $tool==''?"weapon":$tool;
   $dmg = phpFreeChat::PreFilterMsg(rand(0,100));

   $hitpoint = $ct->getUserMeta($nick, 'hp');
   $exp = $ct->getUserMeta($u->nickid, 'xp');

   if ($hitpoint == "") $hitpoint = 1000;

    if (trim($param) == "" || $nick== "")
    {
      // error
      $cmdp = $p;
      $cmdp["param"] = _pfc("Missing parameter");
      $cmdp["param"] .= " (".$this->usage.")";
      $cmd =& pfcCommand::Factory("error");
      $cmd->run($xml_reponse, $cmdp);
      return;
    }

   $hitpoint -= $dmg;
   $ct->setUserMeta($nick, 'hp', $hitpoint);

   $cmdp = $p;
   $cmdp["recipient"] = $recipient;
   $cmdp["recipientid"] = $recipientid;
   $cmdp["param"] = _pfc("%s attacks %s with a %s, dealing %s damage! [%s]",$u->getNickname(), $nick, $tool, $dmg, $hitpoint);
   $cmd =& pfcCommand::Factory("notice");
   $cmd->run($xml_reponse, $cmdp);
   if ($hitpoint <= 0)
   {
      $exp += 1;
      $ct->setUserMeta($u->nickid, 'xp', $exp);
      $ct->setUserMeta($nick, 'hp', 1000);
      $cmdp = $p;
      $cmdp["recipient"] = $recipient;
      $cmdp["recipientid"] = $recipientid;
      $cmdp["param"] = _pfc("%s has been defeated! %s gained 1 exp! [%s]", $nick,$u->getNickname(), $exp);
      $cmd =& pfcCommand::Factory("notice");
      $cmd->run($xml_reponse, $cmdp);
   }
   if ($exp > 100)
   {
      $exp = 0;
      $ct->setUserMeta($u->nickid, 'xp', $exp);
      $lvl = $ct->getUserMeta($u->nickid, 'lvl');
      $lvl += 1;
      $ct->setUserMeta($u->nickid, 'lvl', $lvl);

      $cmdp = $p;
      $cmdp["recipient"] = $recipient;
      $cmdp["recipientid"] = $recipientid;
      $cmdp["param"] = _pfc("%s levelled up! [%s]", $u->getNickname(), $lvl);
      $cmd =& pfcCommand::Factory("notice");
      $cmd->run($xml_reponse, $cmdp);
   }
  }
}

?>

/hug command (Hugs target or asks for hug) hug.class.php
Code: Select all
<?php

require_once(dirname(__FILE__)."/../pfccommand.class.php");

class pfcCommand_hug extends pfcCommand
{
  var $usage = "/hug {nick}";

  function run(&$xml_reponse, $p)
  {
    $clientid    = $p["clientid"];
    $param       = $p["param"];
    $params      = $p["params"]; // modif 1
    $sender      = $p["sender"];
    $recipient   = $p["recipient"];
    $recipientid = $p["recipientid"];

    $c  =& pfcGlobalConfig::Instance();
    $u  =& pfcUserConfig::Instance();
    $ct =& pfcContainer::Instance();

    $nick   = isset($params[0]) ? $params[0] : '';
   $dmg = phpFreeChat::PreFilterMsg(rand(0,100));

   $hitpoint = $ct->getUserMeta($nick, 'hp');
   $exp = $ct->getUserMeta($u->nickid, 'xp');

   if ($hitpoint == "") $hitpoint = 1000;

    if (trim($param) == "" || $nick== "" || $nick == $u->getNickname())
    {
     // Need hug
     $cmdp = $p;
     $cmdp["recipient"] = $recipient;
     $cmdp["recipientid"] = $recipientid;
     $cmdp["param"] = _pfc("%s wants a hug!",$u->getNickname());
     $cmd =& pfcCommand::Factory("notice");
     $cmd->run($xml_reponse, $cmdp);
     return;
    }

   $hitpoint += $dmg;
   $ct->setUserMeta($nick, 'hp', $hitpoint);

   $cmdp = $p;
   $cmdp["recipient"] = $recipient;
   $cmdp["recipientid"] = $recipientid;
   $cmdp["param"] = _pfc("%s hugs %s, healing them %s points! [%s]",$u->getNickname(), $nick, $dmg, $hitpoint);
   $cmd =& pfcCommand::Factory("notice");
   $cmd->run($xml_reponse, $cmdp);
  }
}

?>
IronLX
New member
 
Posts: 4
Joined: Sat Aug 20, 2011 12:59 pm
Top

Postby IronLX » Sun Aug 21, 2011 12:36 pm

If you don't like the underscores just use this after setting the $cmdp["param"] = _pfc($string); output:
Code: Select all
$cmdp["param"] = substr($cmdp["param"],0,-1); // Creates sub-string up to last character
$cmdp["param"] = substr($cmdp["param"],1); // Creates sub-string after first character
IronLX
New member
 
Posts: 4
Joined: Sat Aug 20, 2011 12:59 pm
Top


Post a reply
2 posts • Page 1 of 1

Return to Contributions (v1.x)

Who is online

Users browsing this forum: No registered users and 19 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