Dice roll mod ... again.

Started by Adin, February 02, 2005, 08:49:07 AM

Previous topic - Next topic

Owdy

Former Lead Support Specialist

Tarvitsetko apua SMF foorumisi kanssa? Otan työtehtäviä vastaan, lue:http://www.simplemachines.org/community/index.php?topic=375918.0

v4s

Where can I download this mod? I checked the Mods directory and didn't see it there.

Any assistance would  be appreciated.


shanks

Sorry, it's not available as a mod package. You have to insert the code yourself.

First make a backup of post.php in case something goes wrong and you need to revert to the original. :)

In post.php

Find
function Post()

Add before

function rolldice($dice, $sides, $sign, $modifier)
{
global $settings;

$total = 0;
$temp = '(';   

if ($dice>40) {return 'Sorry, too many rolls!';}
if ($sides>100) {return 'Sorry, too many sides!';}

if ($dice > 1)
{
for ($i=0; $i < ($dice-1); $i++)
{
$dv = rand(1, $sides);
        $temp .= $dv . '+';
$total=$total+$dv;
}
}
        $dv = rand(1, $sides);
        $temp .= $dv;
$total=$total+$dv;

if ($sign == '+')
{       
$total=$total+$modifier;
} elseif ($sign == '-') {
$total=$total-$modifier;
} else {
$temp .= '): Total = ' . $total;
{return '<img src="' . $settings['images_url'] . '/dice.gif" alt="" />Rolling ' . $dice . 'd' . $sides .': <div style="background-color: #919191;">' . $temp . '</div>';}
}
        $temp .= ')' . $sign . $modifier . ': Total = ' . $total;
{return '<img src="' . $settings['images_url'] . '/dice.gif" alt="" />Rolling ' . $dice . 'd' . $sides . $sign . $modifier .': <div style="background-color: #919191;">' . $temp . '</div>';}
}


Find
preparsecode($_POST['message']);

Add after
$_POST['message'] = preg_replace('~:dice (\d+)d(\d+)(\D*?)(\d*?):~ei', "rolldice('\$1', '\$2', '\$3', '\$4')", $_POST['message']);


If you stick this little attached gif into your images folder then it further helps highlight where a roll is being made.

mothlos

I am using a webboard to play hxxp:www.faterpg.com/ [nonactive] which uses hxxp:www.fudgerpg.com/fudge/ [nonactive] dice to determine outcomes. Results can be both positive and negative and it would be nice if the final result had a forced + sign for positive numbers. I know I can probably do an if check and just sub it in if it is positive, but is there a way to do it more simply?

// FUDGE dice roller
function fudge()
{
$rolls = 4;
$total = 0;
$temp = 'Results = ';

if (rolls>40) {return 'Sorry, too many rolls!';}


for ($i=0; $i<=($rolls-1); $i++)
{
$result=rand(1,3)-2;
if ($result==-1) $temp.='-, ';
elseif ($result==0) $temp.='0, ';
elseif ($result==1) $temp.='+, ';
$total=$total+$result;
}

return 'Rolling '.$rolls.'dF<br><div style="background-color: #919191;">'.$temp.' '.'<b>Total = '.$total.'</b></div>';
}


// Roll 4dF
$_POST['message'] = preg_replace('~:fudge:~ei', "fudge()", $_POST['message']);

[Unknown]

return 'Rolling ' . $rolls . 'dF<br><div style="background-color: #919191;">' . $temp . ' <b>Total = ' . ($total <= 0 ? $total : '+' . $total) . '</b></div>';

-[Unknown]

Anki

Thank ye all for this wonderful mod. Did you ever fix the mutliple roll errors?

mantaar

dang...that works slick...THANK YOU

oldschoolstroker

This is an awesome mod...thanks!

Cysvariamne

Very nice mod.

This is a godsend, its my first mod I've added to SMF since I installed just minutes ago and the mod had a few hiccups after I added code.

For one, the css coding of style and background colour appeared as text in the post instead of modifying the colour and the image I do not have, any help on that would be good :)

Also, I got the dice roller to work withut it showing the style code by changing it to its html equivilent div bgcolor="#919191" which has removed the inline code but lacks colour, but it got me one step closer..

The roll right now looks like this:

(Img) Rolling 1d100:
(15): Total = 15

Is there any way to get it all on one line? Is it already meant to be on one line? I've tried to see where the fault is to no avail..

I can post the coding I've done if needed, its pretty much exactly what Adin had posted on page 2 (for the standard roller, not the whitewolf-style) except for the above.

Thanks!

Cysvariamne

#49
Okay, this is off topic but might as well do two birds with one stone.. I was about to test the dice roll again by replying to my fiance's post and it gave this:

2: call_user_func(Post): First argument is expected to be a valid callback
File: /home/roleplay/public_html/forum/index.php
Line: 119

I went down the coding to the smf_main section but I got lost with what could be at fault since is both a Sunday and my first time at php.

The only mod I've done to the board is within post.php with this dice roller.

Edit: I reverted back to the original Post.php and the reply function now works all over the board 100% so it was a fault with the dice roller, so help would be a blessing :)


Z

This helped me out quite a bit. I salute everyone who had something to do with this dice roller mod.

shanks

It's been awhile, but I shall reaquaint myself with php and the roller to fix issues I have found and those of other people :)

Timgoss

Hey, I have a problem. I am using SMF RC 1.something and I am running a RPG forum. I would like to add the Dicemod to my forums, but I am having soooo many problems. can someone post a correct post.php and source file for this? It would help me big time

shanks

Can you post me the post.php that you are using? It's tricky to post the correct one for you if you don't know which version of SMF you are using!

shanks

#54
I have now checked the roller with both 1.0.5 and 1.1 RC1, and it works fine for both... aside from the dice gif (but that's hardly important).

I have now also moved the roller functions into their own file. Over time I'll be improving how it works and adding other RPG related figures. This way the amount of editting of core SMF files will be reduced, and most updates can be handled by a simple RPG.php file replacement.

Attached below is the aforementioned RPG.php and an editted post.php file for 1.1. RC1. Simply place each file in the Sources folder. However if you have installed any other mods/alterations and you are unsure if post.php has other changes within it then you'll want to manually edit the file as below:

Find, in Post.php:

preparsecode($_POST['message']);


Add after:

include 'RPG.php';
$_POST['message'] = preg_replace('~:dice (\d+)d(\d+)(\D*?)(\d*?):~ei', "dice('\$1', '\$2', '\$3', '\$4')", $_POST['message']);
$_POST['message'] = preg_replace('~:stats (\d+)d(\d+)(\D*?)(\d*?),(\D+),(\d+):~ei', "stats('\$1', '\$2', '\$3', '\$4', '\$5', '\$6')", $_POST['message']);


One final caveat, being new to php I do not know whether or not the use of include opens up any security risks, but I can't logically think of any. So, until verified by one knowledgeable in php, please understand that you use this at your own risk.

If you prefer to omit the use of RPG.php you may copy and paste the functions into post.php above the line:

function post()

Mecha Dude

I had an unmodified post.php, your post.php did not work (and seems 20 kb larger).  Simply following your instructions to edit post.php worked perfectly.

Cheers!

ictus

has this been made into an approved mod yet?

a self instal would be great to have...

ictus

is it possible to encorporate mothlos fudge dice into the rpg.php code, if so how do I do it, I know nothing about php, so simple help for a simple person :)

and I've got the roller working, so i'm really pleased with that.

Rasyr

Quote from: Cysvariamne on September 03, 2005, 09:34:42 PM
(Img) Rolling 1d100:
(15): Total = 15

Is there any way to get it all on one line? Is it already meant to be on one line? I've tried to see where the fault is to no avail..

The div tag (on two different lines in the RPG.php file, around line 33 or so) is what is causing the second portion to drop to the next line. If you change it to a span (or get rid of the div altogether), then it will appear on a single line. There are two lines that this can be found, first is around line 33, and the second is a few lines below it. You will want to make the same changes to both lines just to be safe.

Now, I have a question or two of my own.....

1) How would I go about altering the code so that if the result falls within a certain range, it will roll again and add the two numbers - and if the second roll also falls within the specific range, to repeat continuously as long as the new roll is with the specific range. I have a javascript function which does this, but have no idea about php.  For this, it would be for use with percentile dice only, so a roll of 96+ would mean rolling again and adding to the first, if the second roll was 96+, it would roll a third time and add it to the first two, etc.. On the low side, I would want to do the same with a low end range. Now, only the first roll could go either way, all secondary rolls would be open-ended in one direction only.

2) How can I add this so that it works in PMs as well?


Rasyr

Quote from: ictus on December 27, 2005, 09:10:46 AM
is it possible to encorporate mothlos fudge dice into the rpg.php code, if so how do I do it, I know nothing about php, so simple help for a simple person :)

and I've got the roller working, so i'm really pleased with that.

Andrew, that is the easy part.   :D

Step 1: copy the fudge() function into the bottom of the rpg.php file.

Step 2: copy the other portion (the single line) directly beneath the other two lines you added for the base dice roller.

Don't forget to add the fix that [Unknown] posted directly after mothlos' post (i.e. replace the line in the fudge() function with the one [Unknown] gave.

And that should do it...  ;D

Advertisement: