• 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

Character prompt generator

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

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

Post a reply
1 post • Page 1 of 1

Character prompt generator

Postby Qem » Mon Apr 29, 2013 4:58 am

For a Fan Writers group, I made a /prompt command to randomly generate a character or group, along with an action.

You will need 2 text files for the code to randomly pull information from (which can go anywhere, I've put them in the data folder from where my chat is located.)

A text file with a list of characters - characters.txt
Example:
Code: Select all
The Warrior
The Healer
The Mage
The Thief
The Carddealer


A text file with a list of actions/general prompts - action.txt
Code: Select all
smile
stars
heading off to the bar
going skiing
jumping the shark
playing Go
arguing
sleeping
coding
chatting



In src/commands create a file prompt.class.php
Code: Select all
<?php

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

    // Prompt command by Qem

    class pfcCommand_prompt extends pfcCommand
    {
      var $usage = "/prompt {hero | duo | trio}";

      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;
        }
        $msg = phpFreeChat::PreFilterMsg($param);
       // values
      $i=0; //if some other option was selected.
       if($msg=="hero")   $i=1;
       if($msg=="duo") $i=2;
       if($msg=="trio") $i=3;


//this pulls from the folder structure of where your chat is located

          $f_character = file("data/characters.txt");
   
if($i==0){
 $result="Anyone ";
 }
 
      for($j = 0; $j < $i; $j++){'
      $char = $f_character[rand(0, count($f_character) - 1)];
      $result=$result . $char . " and ";
      }
   
      
    $f_action = file("data/action.txt");
    $action = $f_action[rand(0, count($f_action) - 1)];

$result=$result ."the prompt: " . $action;




        $ct->write($recipient, "*me*", $this->name, $u->getNickname()." asked for a prompt and got: " .$result);

       
      }
    }

    ?>
Qem
New member
 
Posts: 7
Joined: Mon Apr 22, 2013 9:27 am
Top

Post a reply
1 post • Page 1 of 1

Return to Contributions (v1.x)

Who is online

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