Menu

#34 Expand the /Roll function

open
None
5
2008-12-29
2008-11-28
RiTz21
No

I installed this on my Forum, and I must say I am impressed! Very well done!

Is there a way to have the /Roll function expended a bit?
For instance, adding a modifier to a dice would go a long way to make this more RPG friendly...
I.e. /roll 1d20+4 would return (12+4)=16

The second ability which would cover much of the rest, would be the ability to 'list' multiple rolls in the same line:
i.e. /roll 1d20+4;1d8+2 would return (12+4)=16;(8+2)=10

That would really be awesome!

THANKS!!

RiTz21

Discussion

  • RiTz21

    RiTz21 - 2008-12-12

    I added this feature myself.

    Instructions:
    Just replace the insertParsedMessageRoll function in chat\lib\class\AJAXChat.php with the one below.

    // 12/06/2008: Added the ability to add a 'modifier' for the value \(i.e. xdy+z\) - RiTz21 http://TheOnlySheet.com
    function insertParsedMessageRoll\($textParts\) \{
        if\(count\($textParts\) == 1\) \{
            // default is one d6:
            $text = '/roll '.$this->getUserName\(\).' 1d6 '.$this->rollDice\(6\);
        \} else \{
            $diceParts = explode\('d', $textParts\[1\]\);
            if\(count\($diceParts\) == 2\) \{
                $bonus = 0;
                $number = \(int\)$diceParts\[0\];
                $diceandbonusParts = explode\('+', $diceParts\[1\]\);
    
                if\(count\($diceandbonusParts\) == 1\) \{
                    $sides = \(int\)$diceParts\[1\];
                \} else \{
                    $sides = \(int\)$diceandbonusParts\[0\];
                    $bonus = \(int\)$diceandbonusParts\[1\];
                    if \($bonus > 1000\)
                        $bonus = 1000;
                \}
    
                // Dice number must be an integer between 1 and 100, else roll only one:
                $number = \($number > 0 && $number <= 100\) ?  $number : 1;
    
                // Sides must be an integer between 1 and 100, else take 6:
                $sides = \($sides > 0 && $sides <= 100\) ?  $sides : 6;
    
                if \($bonus == 0\) \{
                    $text = '/roll '.$this->getUserName\(\).' '.$number.'d'.$sides.' '.'\[';
                \} else \{
                    $text = '/roll '.$this->getUserName\(\).' '.$number.'d'.$sides.'+'.$bonus.' '.'\[';
                \}
                $totalresult = 0;
                $tmpvalue = 0;
                for\($i=0; $i<$number; $i++\) \{
                    if\($i \!= 0\)
                        $text .= ',';
                    $tmpvalue = $this->rollDice\($sides\);
                    $text .= $tmpvalue;
                    $totalresult += $tmpvalue;
    

    // $text .= $this->rollDice($sides);
    }
    $totalresult += $bonus;
    $text .= ']';
    if ($bonus != 0)
    $text .= '+'.$bonus;
    $text .= '='.$totalresult;
    } else {
    // if dice syntax is invalid, roll one d6:
    $text = '/roll '.$this->getUserName().' 1d6 '.$this->rollDice(6);
    }
    }
    $this->insertChatBotMessage(
    $this->getChannel(),
    $text
    );
    }

     
  • Philip Nicolcev

    Philip Nicolcev - 2008-12-29
    • assigned_to: nobody --> frug
     
  • Philip Nicolcev

    Philip Nicolcev - 2008-12-29

    Well, i've never liked RPing with dice, but...

    I will take up adding this feature into a future release. I have also had a request for a grand total result for all the rolls to be displayed.