n00b question ...

Started by Adin, October 10, 2003, 12:23:49 AM

Previous topic - Next topic

Adin

IT WORKS :D

YES ! ^^ Finally.

Thank you so much !!!

Thanks also for giving me a little peek into the scripts.

Tyris

heheheh, exuse my last edit above...
it turned out I'd been writing roll dice, instead of dice roll ^_^ heheheh

glad it works ^_^

enjoy!! :)*edit*
further more... it looks like the function DID have to be in the global scape... which is wierd... I swear people were saying you could have function inside other functions... o well ^_^

Adin

Who cares as long as it works ;)

eFishie

I could make a script to do dice rolling in a very small amount of lines. I believe it was 2. But you can only roll 6-sided.
--Jon

Abstraction Point Electronic Music Community - We don't bite! Really! I promise!

Check out my newest song: Alive

Tyris

heheh, well my script kinda included your script..
well the word 'rand' anyway ;) ;D
and I think it was a tad more useful having a dynamic input for the number of dice and sides ;D

and like I said..
QuoteI could probably have done the same thing a month ago.... but in ten times as many lines, in a few months, maybe I can do that same thing in less ^_^.

Tyris

latest update for Adin:

function rolldice($start,$dice,$sides,$end)
{
   $total = 0;
   $temp = '';
if(is_numeric($dice) && is_numeric($sides)) {
   for($i=0; $i < $dice; $i++)
   {
      $dv=rand(1,$sides);
      $temp .= 'roll ' . ($i + 1) . ': ' . $dv . ', ';
      $total = $total + $dv;
   }
   $temp .= 'total: ' . $total;
}
$temp = $start . $end . "<hr width=\"100%\" size=\"1\" class=\"windowbg3\" style=\"color: #6394BD\" />" . $temp;
return $temp;
}

put that bit in the global scape. You can again, change the formatting, and also change the style of the hr if you want (make sure its not grey tho, otherwise they can emulate it with an [ hr ] tag).

add after
   $message = str_replace(array("\r", "\n", "\t"), array('', '<br />', '&nbsp;&nbsp;&nbsp;'), $message);
this
   $message = preg_replace('~(.*):dice roll (.*)d(.*):(.*)~eis', "rolldice('\$1','\$2','\$3','\$4')", $message);
I'll make a better version when SMF goes public that will add a column to the db for storing that rolls (that way it can appear under the sig or something)

until then, that should do it for you ^_^

Adin

You're the best ^^!

Thanks again :)

I guess the hr will do to simply validate it.

If i wanted to give the actual output a bgcolour ... would i just have to wrap the $temp with the style ?

Tyris

pretty much yeah, except put $end afterwards..
basically here's the run down.
in the final line, $start is EVERYTHING before the roll... and $end is EVERYTHING after the roll... so if you wanna put the roll at the end of the message, add $start and $end together first, then put $temp (with the format around it) after that.
if you were to put the style around temp and have it where the roll was indicated
you do:
$temp = $start . "<div style=\"stuff\">" . $temp . "</div>" . $end;
(realistically the $start and $end become superfluous, but they are required unless you change the preg_replace back to its original... so it'll be easier to just use what I just wrote there)

Adin

Alright, thanks.

That Info helps alot :)

Adin

$temp = $start . "Rolling $dice $sides -sided dice:<br><hr width=\"100%\" size=\"1\" class=\"windowbg3\" style=\"color: #6394BD\" /><div style=\"background-color: #3F3F3F\">" . $temp . "</div>" . $end;

This is what i ended up with :)

Looks fine now :)

Phoenixoverlord

Would someone be willing to update this for RC1 please? The coding no longer works as a few things seem to have changed in the post.php

Any help would be appreciated. :)

Phoenixoverlord

Sorry for bumping this, but I'd like to try my luck once more.  :-[

I've checked the code and I tried modifying a few things but nothing worked for me....  :(

Would there be anyone who could modify this for RC1 please? Thank you. :)

[Unknown]

Can you post the finished code that worked for a beta, but not for RC1?

-[Unknown]

Phoenixoverlord

#33
This was made by Tyris :)

Apparently it goes into sources/post.php and then one needs to go to function post2 ()

Quote from: Tyris on October 11, 2003, 11:23:11 PM

function rolldice($start,$dice,$sides,$end)
{
   $total = 0;
   $temp = '';
if(is_numeric($dice) && is_numeric($sides)) {
   for($i=0; $i < $dice; $i++)
   {
      $dv=rand(1,$sides);
      $temp .= 'roll ' . ($i + 1) . ': ' . $dv . ', ';
      $total = $total + $dv;
   }
   $temp .= 'total: ' . $total;
}
$temp = $start . $end . "<hr width=\"100%\" size=\"1\" class=\"windowbg3\" style=\"color: #6394BD\" />" . $temp;
return $temp;
}

put that bit in the global scape. You can again, change the formatting, and also change the style of the hr if you want (make sure its not grey tho, otherwise they can emulate it with an [ hr ] tag).

add after
   $message = str_replace(array("\r", "\n", "\t"), array('', '<br />', '&nbsp;&nbsp;&nbsp;'), $message);
this
   $message = preg_replace('~(.*):dice roll (.*)d(.*):(.*)~eis', "rolldice('\$1','\$2','\$3','\$4')", $message);

[Unknown]

What about it no longer works?

-[Unknown]

Phoenixoverlord

#35
In the sources/post.php I can no longer find the following line:

$message = str_replace(array("\r", "\n", "\t"), array('', '<br />', '&nbsp;&nbsp;&nbsp;'), $message);

There is a line which resembles it and I tried putting

$message = preg_replace('~(.*):dice roll (.*)d(.*):(.*)~eis', "rolldice('\$1','\$2','\$3','\$4')", $message);

after it and then the other part of the code, but it simply doesn't work when I try to call the code in a post. It would appear that the structure of post.php has slightly altered in comparison to the previous released beta version. I just can't figure out what I should change in this code here to make it work...  :-[

The closest I can find to the above code is this:

$context['message'] = str_replace(array('"', '<', '>', '  '), array('&quot;', '&lt;', '&gt;', ' &nbsp;'), $form_message);

[Unknown]

I think it should go near a preparsecode...

-[Unknown]

Phoenixoverlord

* Phoenixoverlord scratches head   :-\

I'm afraid you already lost me here. I know how to install and set up the SMF software, but when it comes to actual coding...  :-[

Would the code as it is still work right now with RC1? Or would it need changes? Since apparently the post.php has changed since beta.  ???

[Unknown]

It should work, except the one line you have to find.... that was moved to another file..... I'm not sure why it's being done exactly there anyway...

-[Unknown]

Phoenixoverlord

Where would be a safe place to paste the code then in post.php? Sorry for bothering you so much, but I rather not mess up anything. :)

In the // Posting... section?

It's after all a rather longish file :)

Advertisement: