MyBB Hacks

Full Version: Random Number
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
More details:
http://mybbhacks.zingaburga.com/showthread.php?tid=5295

Create a custom thread fields with these settings:
Title: Your Random Number is:
Key: random_number
Applicable Forums: Select any forum(s) where the random number will be displayed.
Hide input field on New/edit thread: Checked
Text Mask Filter: Digits
Input Formatter:

Code:
<?=mt_rand()?>

Modify it as our needs (ex: using min and max).
Custom Modify Error:

Code:
<if THIS_SCRIPT == 'editpost.php' then>Random number cannot be modified</if>

Underlying Data Type: Integer (unsigned, usually 32-bit)

By default, it'll be displayed above the first post. For displaying it manually somewhere else, check the Hide on Show thread setting, set the Display Format setting to:

Code:
<div>Your Random Number is: {VALUE}</div>

then put {$GLOBALS['threadfields']['random_number']} inside postbit_first and/or postbit_first_classic and/or forumdisplay_thread templates.

Brilliant. A couple of questions:

How to set the min and max number? I want the numbers to be between 1 and 10. Is this possible?
Will this show below the users text? I have a forum which users post this:

Forum Name
Forum Link

Your Random Number is: 10 (example)
(11-19-2015 03:48 AM)Greig Wrote: [ -> ]How to set the min and max number? I want the numbers to be between 1 and 10. Is this possible?
You can use <?=mt_rand(1,10)?>

(11-19-2015 03:48 AM)Greig Wrote: [ -> ]Will this show below the users text? I have a forum which users post this:

Forum Name
Forum Link

Your Random Number is: 10 (example)

Not quite sure where the "Forum Name" and the "Forum Link" come from. Are they post message or other custom thread fields?
They will be the post message as I have set a default message for that particular forum.
Oh, then you can do this:
(11-19-2015 03:20 AM)RateU Wrote: [ -> ]For displaying it manually somewhere else, check the Hide on Show thread setting, set the Display Format setting to:

Code:
<div>Your Random Number is: {VALUE}</div>

then put {$GLOBALS['threadfields']['random_number']} inside postbit_first and/or postbit_first_classic and/or forumdisplay_thread templates.


Offtopic:
Since you use XThreads, why not using custom thread fields for the Forum Name and the Forum Link?
I know there are some default post messages plugins out there. But none of them provide validations.
For example:
Forum Link: Oooooops!

Just a suggestions though Smile
Well I am still new, so I could get rid of the default post message plugin and use XThreads for this? If so, I will definitely switch over. Also, thank you for the extra code, this plugin looks awesome!
You can read this thread as your reference (a bit similar -  for the old XThreads version):
http://mybbhacks.zingaburga.com/showthread.php?tid=289
You can use the Text Mask Filter for validating the URL. Set it to URL (HTTP/S)

Feel free to ask if you still don't understand it Smile
Does the number change every time the thread is edited?  You may need a conditional to block that...
It doesn't change from my quick test, Yumi.
The input is not displayed on the newthread/editpost. And maybe caused by the behavior too (?):
Input Formatter Descriptions Wrote:Note that this is always applied on newthread, but only applied on edit if the user supplies a value

But I think it will change if the user "forks" the input (?)
Well, you know XThreads better than I do Smile

Anyway, can easily be blocked with the following Custom Modify Error:

Code:
<if THIS_SCRIPT=='editpost.php' then>Random number cannot be modified</if>


Also, this has exposed a bit of a bug in XThreads with replacing values on edit.

Pages: 1 2
Reference URL's