Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Random Number
RateU Offline
Administrator
*******
Posts: 2,350
Joined: Mar 2010
Post: #1
Random Number
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.



Attached File(s) Thumbnail(s)
   

(This post was last modified: 12-11-2015 02:05 AM by RateU.)
11-19-2015 03:20 AM
Find all posts by this user Quote this message in a reply
Greig Offline
Junior Member
**
Posts: 16
Joined: Nov 2015
Post: #2
RE: Random Number
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)

Forum Lair: http://www.forumlair.com
The exciting hybrid community!
11-19-2015 03:48 AM
Find all posts by this user Quote this message in a reply
RateU Offline
Administrator
*******
Posts: 2,350
Joined: Mar 2010
Post: #3
RE: Random Number
(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?

11-19-2015 03:54 AM
Find all posts by this user Quote this message in a reply
Greig Offline
Junior Member
**
Posts: 16
Joined: Nov 2015
Post: #4
RE: Random Number
They will be the post message as I have set a default message for that particular forum.

Forum Lair: http://www.forumlair.com
The exciting hybrid community!
11-19-2015 03:54 AM
Find all posts by this user Quote this message in a reply
RateU Offline
Administrator
*******
Posts: 2,350
Joined: Mar 2010
Post: #5
RE: Random Number
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

11-19-2015 04:00 AM
Find all posts by this user Quote this message in a reply
Greig Offline
Junior Member
**
Posts: 16
Joined: Nov 2015
Post: #6
RE: Random Number
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!

Forum Lair: http://www.forumlair.com
The exciting hybrid community!
11-19-2015 04:05 AM
Find all posts by this user Quote this message in a reply
RateU Offline
Administrator
*******
Posts: 2,350
Joined: Mar 2010
Post: #7
RE: Random Number
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

11-19-2015 04:16 AM
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #8
RE: Random Number
Does the number change every time the thread is edited?  You may need a conditional to block that...

My Blog
12-03-2015 05:15 PM
Find all posts by this user Quote this message in a reply
RateU Offline
Administrator
*******
Posts: 2,350
Joined: Mar 2010
Post: #9
RE: Random Number
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 (?)

12-04-2015 06:59 AM
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #10
RE: Random Number
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.


My Blog
12-06-2015 04:36 PM
Find all posts by this user Quote this message in a reply

« Next Oldest | Next Newest »

 Standard Tools
Forum Jump: