vForums Support Banner



 

Welcome Guest! Please Login or Register
vForums Support :: Programming & Coding :: Code Requests & Support :: Dice rolls in post - View Topic (Page 1 of 2)Page: 1 2
Topic Rating: *****
Printable View
Jedi Slayer
Junior Member
**

[Avatar]
Sith Lord

Posts: 92
Status: Offline
Joined:  
Reputation: 0%  


pmwwwyahoo
Dice rolls in post (13th Mar 09 at 9:52pm UTC)
I would like to be able to add dice rolls in posts, Is that possible?
Jedi Slayer
Junior Member
**

[Avatar]
Sith Lord

Posts: 92
Status: Offline
Joined:  
Reputation: 0%  


pmwwwyahoo
Re: Dice rolls in post (14th Mar 09 at 6:27am UTC)
I was trying to use this code. the header said it can be posted anywhere so I was trying to get it to work here.

Code:
 
  1. <style type="text/css">
  2. .dicebg {background-color: FFFFFF;border:solid 2px #000000;}
  3. .dicefont {background-color: FFFFFF;color: 000000; font-weight:bold;}
  4. </style>
  5. <script>
  6. //Dice Rolls In Posts v1.1
  7.  
  8. //Copyright 4-23-2007 ~Wonder
  9. //May be reposted anywhere as long as this header remains in tact
  10.  
  11. //Do you want the dice to line of horizontally(true) or vertically(false)
  12. diceAlignment=true;
  13.  
  14. //Enter URL of the image you want to appear as the dice ubbc button
  15. UBBCdiceImage="http://img100.imageshack.us/img100/6118/diceicon9rx.gif";
  16.  
  17. //Enter the default # of sides
  18. defaultSides=20;
  19.  
  20. //Enable dice in preview? true or false
  21. enablePreview=false;
  22.  
  23.  
  24.  
  25. rs="";mainForm="";
  26. if(document.postForm)
  27. {
  28. mainForm=document.postForm;
  29. if(location.href.match(/action\=modifypost/)){enablePreview=true;}
  30. mainForm.color.parentNode.innerHTML+="<a href=javascript:add(\"[dice="+defaultSides+"]\",\"\")><img src=\""+UBBCdiceImage+"\" alt=\"Insert Dice Roll\" border=\"0\"></a>";
  31. mainForm.onsubmit=addRand;
  32. mainForm.message.value=mainForm.message.value.replace(/(\[rand\=\d+\])/ig,"");
  33. rs=RegExp.$1; rs=(/\[rand\=/.test(rs))?rs:"";
  34. if(location.href.match(/quote\=\d+/))
  35. {
  36. mainForm.message.value=mainForm.message.value.replace(/(\[dice\=\d+\])/ig,"");
  37. rs="";
  38. }
  39. }
  40. else if(location.href.match(/action\=display/))
  41. {
  42. ta=document.getElementsByTagName("textarea");
  43. if(ta.length>0 && ta[0].name=="message")
  44. {
  45. mainForm=ta[0].parentNode;
  46. mainForm.onsubmit=addRand;
  47. }
  48. }
  49.  
  50.  
  51.  
  52. ///////////////////////
  53. if(location.href.match(/action\=(display|pmview|recent|userrecentposts|gotopost|search|calendarview)/) || (!location.href.match(/action\=/) && document.postForm && enablePreview))
  54. {
  55. hr=document.getElementsByTagName("hr");
  56. for(i=0;i<hr.length;i++)
  57. {
  58. if(typeof(hr[i].parentNode)!="undefined" && hr[i].parentNode.tagName=="TD" && typeof(hr[i].parentNode.lastChild)!="undefined" && typeof(hr[i].parentNode.lastChild.lastChild)!="undefined" && hr[i].parentNode.lastChild.lastChild.nodeType!=1)
  59. {
  60. n=hr[i].parentNode.lastChild;
  61. rand=n.innerHTML.match(/\[rand\=\d+\]/);
  62. if(rand!=null)
  63. {
  64. n.innerHTML=n.innerHTML.replace(rand[0],"");
  65. rand=rand[0].replace(/[^\d]/g,"");
  66. dice=n.innerHTML.match(/\[dice\=\d+(\+\d+)?\]/ig);
  67. if(dice!=null)
  68. {
  69. for(k=0;k<dice.length;k++)
  70. {
  71. numb=dice[k].match(/\d+(\+\d+)?/);
  72. numb=numb[0].split("+");
  73. addon=numb.length>1?parseInt(numb[1],10):0;
  74. numb=parseInt(numb[0],10);
  75. roll=Math.round((parseFloat(rand.substring(k,k+2)+"."+rand.substring(k+2,rand.length))/100)*(numb-1))+1+addon;
  76. n.innerHTML=n.innerHTML.replace(dice[k],"<table "+(diceAlignment?"style=\"display:inline\"":"")+" border=0 cellpadding=0 cellspacing=0><tr><td><table class=dicebg cellpadding=1 cellspacing=0><tr><td><center><font class=dicefont size=\"+1\"><b>"+roll+"</b><br><font size=\"1\">"+numb+" sides"+(addon>0?"+"+addon:"")+"</font></font></center></td></tr></table></td></tr></table>  ");
  77. }
  78. }
  79. }
  80. }
  81. }
  82. }
  83. function addRand()
  84. {
  85. mainForm.message.value=mainForm.message.value.replace(/(\[rand\=\d+\])/ig,"");
  86. if((rs.length==0 && mainForm.message.value.match(/(\[dice\=\d+(\+\d+)?\])/)) && (enablePreview==true || (enablePreview==false && mainForm.nextaction.value=="post")))
  87. {
  88. mainForm.message.value+="[rand="+(Math.random()+"").replace(/0\./,"")+(Math.random()+"").replace(/0\./,"")+(Math.random()+"").replace(/0\./,"")+( Math.random()+"").replace(/0\./,"")+"]";
  89. }
  90. else
  91. {
  92. mainForm.message.value+=rs;
  93. }
  94. disable(mainForm);
  95. }
  96. </script>
  97.  
  98.  
 
Graham
Support Administrator
*****

[Avatar]

Posts: 1,642
Status: Offline
Gender: Male
Location: Sussex, UK
Age: 39
Joined:  

Additional Groups:
Support Team
***


Reputation: 57%  


pmwww
Re: Dice rolls in post (14th Mar 09 at 9:38am UTC)
The code you're using is for the Proboards software, they won't work on vForums. I think someone can edit the classes so that it does work, however {Smile}
Jedi Slayer
Junior Member
**

[Avatar]
Sith Lord

Posts: 92
Status: Offline
Joined:  
Reputation: 0%  


pmwwwyahoo
Re: Dice rolls in post (15th Mar 09 at 8:44pm UTC)
well that makes sense, I am hoping i can get a dice working here it's the only thing keeping me from moving both my proboards sites over, cause as a whole this forum is alot better imo
Jedi Slayer
Junior Member
**

[Avatar]
Sith Lord

Posts: 92
Status: Offline
Joined:  
Reputation: 0%  


pmwwwyahoo
Re: Dice rolls in post (17th Mar 09 at 1:21pm UTC)
Just checking bases here does this seem doable or is this not going to work at this time? Thank you in advance for your assistance.
Ross
Administrator
*****

[Avatar]

Posts: 3,709
Status: Offline
Gender: Male
Age: 8 11
Joined:  

Additional Groups:
Support Team
***


Reputation: 45%  


pmwwwtwittergtalkvForum
Re: Dice rolls in post (17th Mar 09 at 2:03pm UTC)
I'll look at this for you a little later tonight (unless anyone else wants to do it first {Wink} ) {Smile}

Image
Jedi Slayer
Junior Member
**

[Avatar]
Sith Lord

Posts: 92
Status: Offline
Joined:  
Reputation: 0%  


pmwwwyahoo
Re: Dice rolls in post (19th Mar 09 at 1:30pm UTC)
Any Luck Ross?
Ross
Administrator
*****

[Avatar]

Posts: 3,709
Status: Offline
Gender: Male
Age: 8 11
Joined:  

Additional Groups:
Support Team
***


Reputation: 45%  


pmwwwtwittergtalkvForum
Re: Dice rolls in post (20th Mar 09 at 12:35am UTC)
Hi. Sorry it's taken a little longer than expected {Smile}

This should work if you want to give it a go. Global or Board Footer

Code:
 
  1. <style type="text/css">
  2. .dicebg {background-color: FFFFFF;border:solid 2px #000000;}
  3. .dicefont {background-color: FFFFFF;color: 000000; font-weight:bold;}
  4. </style>
  5. <script type="text/javascript">
  6. //Dice Rolls In Posts v1.1
  7.  
  8. //Copyright 4-23-2007 ~Wonder
  9. //May be reposted anywhere as long as this header remains in tact
  10. //Modified by Ross of vForums Support for vForums compatibility
  11.  
  12. //Do you want the dice to line of horizontally(true) or vertically(false)
  13. diceAlignment=true;
  14.  
  15. //Enter URL of the image you want to appear as the dice ubbc button
  16. UBBCdiceImage="http://img100.imageshack.us/img100/6118/diceicon9rx.gif";
  17.  
  18. //Enter the default # of sides
  19. defaultSides=20;
  20.  
  21. //Enable dice in preview? true or false
  22. enablePreview=false;
  23.  
  24.  
  25. rs="";
  26. mainForm="";
  27. if(document.post_form || document.quick_reply_form) {
  28. if(document.post_form) {
  29.     mainForm=document.post_form;
  30.     if(location.href.match(/action\/modify/)){enablePreview=true;}
  31.     ubbc_holder = document.createElement('span');
  32.     get('ubbc_buttons', ID).firstChild.insertBefore(ubbc_holder, get('ubbc_buttons', ID).firstChild.lastChild);
  33. } else {
  34.     ubbc_holder = get('quick_reply_ubbc', ID).firstChild.nextSibling;
  35.     mainForm=document.quick_reply_form;
  36. }
  37. ubbc_holder.innerHTML+="<a href=javascript:add_ubbc(\"[dice="+defaultSides+"] \",\"\")><img src=\""+UBBCdiceImage+"\" alt=\"Insert Dice Roll\" border=\"0\"></a>";
  38. mainForm.onsubmit=addRand;
  39. mainForm.message.value=mainForm.message.value.replace(/(\[rand\=\d+\])/ig,"");
  40. rs=RegExp.$1; rs=(/\[rand\=/.test(rs))?rs:"";
  41. if(location.href.match(/quote\/\d+/))
  42. {
  43. mainForm.message.value=mainForm.message.value.replace(/(\[dice\=\d+\])/ig,"");
  44. rs="";
  45. }
  46. }
  47.  
  48.  
  49.  
  50. ///////////////////////
  51. if(location.href.match(/action\/(view_topic|search|recent|pm_view|post|modify|create_poll)/)) {
  52. td=document.getElementsByTagName("td");
  53. topic_summary = false;
  54. for(i=0;i<td.length;i++) {
  55. if(td.item(i).className == 'post' || topic_summary) {
  56. // Remove from message preview
  57. if(td.item(i).className == 'post' && location.href.match(/action\/(post|modify|create_poll)/) && !enablePreview) {
  58.     td.item(i).innerHTML=td.item(i).innerHTML.replace(/\[rand\=(\d|\w|<|>|\/|\s)+\]/gi,"");
  59. }
  60. rand=td.item(i).innerHTML.match(/\[rand\=(\d|\w|<|>|\/|\s)+\]/);
  61. if(rand!=null)
  62. {
  63. td.item(i).innerHTML=td.item(i).innerHTML.replace(rand[0],"");
  64. rand=rand[0].replace(/[^\d]/g,"");
  65. dice=td.item(i).innerHTML.match(/\[dice\=\d+(\+\d+)?\]/ig);
  66. if(dice!=null)
  67. {
  68. for(k=0;k<dice.length;k++)
  69. {
  70. numb=dice[k].match(/\d+(\+\d+)?/);
  71. numb=numb[0].split("+");
  72. addon=numb.length>1?parseInt(numb[1],10):0;
  73. numb=parseInt(numb[0],10);
  74. roll=Math.round((parseFloat(rand.substring(k,k+2)+"."+rand.substring(k+2,rand.length))/100)*(numb-1))+1+addon;
  75. td.item(i).innerHTML=td.item(i).innerHTML.replace(dice[k],"<table "+(diceAlignment?"style=\"display:inline\"":"")+" border=0 cellpadding=0 cellspacing=0><tr><td><table class=dicebg cellpadding=1 cellspacing=0><tr><td><center><font class=dicefont size=\"+1\"><b>"+roll+"</b><br><font size=\"1\">"+numb+" sides"+(addon>0?"+"+addon:"")+"</font></font></center></td></tr></table></td></tr></table>  ");
  76. }
  77. }
  78. }
  79. } else if(td.item(i).className == 'title1' && td.item(i).innerHTML.match(/>Topic Summary</i)) {
  80.     topic_summary = true;
  81. }
  82. }
  83. }
  84. function addRand() {
  85. mainForm.message.value=mainForm.message.value.replace(/(\[rand\=\d+\])/ig,"");
  86. if((rs.length==0 && mainForm.message.value.match(/(\[dice\=\d+(\+\d+)?\])/))) {
  87. mainForm.message.value+="[rand="+(Math.random()+"").replace(/0\./,"")+(Math.random()+"").replace(/0\./,"")+(Math.random()+"").replace(/0\./,"")+( Math.random()+"").replace(/0\./,"")+"]";
  88. } else {
  89. mainForm.message.value+=rs;
  90. }
  91. disable(mainForm);
  92. }
  93. </script>
 

Image
Jedi Slayer
Junior Member
**

[Avatar]
Sith Lord

Posts: 92
Status: Offline
Joined:  
Reputation: 0%  


pmwwwyahoo
Re: Dice rolls in post (20th Mar 09 at 3:46am UTC)
No worries I appreciate the help.

I am not getting it to work, I put it in global first, didnt work. Moved it around in a diffrent order, still did not work. So I moved it to a board footer still didnt work, no UBBC button, and tried to just inout the UBBC code [dice=20] and that did not work either. Any thoughts?



http://swlounge.vforums.co.uk/
Jedi Slayer
Junior Member
**

[Avatar]
Sith Lord

Posts: 92
Status: Offline
Joined:  
Reputation: 0%  


pmwwwyahoo
Re: Dice rolls in post (20th Mar 09 at 2:25pm UTC)
I played around with it again this morning removed all other codes and it's still not working.
Jedi Slayer
Junior Member
**

[Avatar]
Sith Lord

Posts: 92
Status: Offline
Joined:  
Reputation: 0%  


pmwwwyahoo
Re: Dice rolls in post (20th Mar 09 at 2:52pm UTC)
It's sorta working now, part of it was my fault I have a bad habit of copy and pasting the code direct from the box instead of using the select all key...

I still have one small problem, that is it puts the dice UBBC button up but when you press it it does not do anything, if you use the dice ubbc code [dice=20] it works fine
Ross
Administrator
*****

[Avatar]

Posts: 3,709
Status: Offline
Gender: Male
Age: 8 11
Joined:  

Additional Groups:
Support Team
***


Reputation: 45%  


pmwwwtwittergtalkvForum
Re: Dice rolls in post (20th Mar 09 at 10:48pm UTC)
I've copied the code directly from my test board onto your forum. That seems to have gotten it working. I can only presume that something changed in the code either when I pasted it here or you copied it from here. Eitehr way, its' working now {Smile}

Image
Jedi Slayer
Junior Member
**

[Avatar]
Sith Lord

Posts: 92
Status: Offline
Joined:  
Reputation: 0%  


pmwwwyahoo
Re: Dice rolls in post (20th Mar 09 at 11:02pm UTC)
Yup its working perfect thank you!!
Jedi Slayer
Junior Member
**

[Avatar]
Sith Lord

Posts: 92
Status: Offline
Joined:  
Reputation: 0%  


pmwwwyahoo
Re: Dice rolls in post (9th Jun 09 at 2:48pm UTC)
It no longer works with the new WYSIWYG Beta
Ross
Administrator
*****

[Avatar]

Posts: 3,709
Status: Offline
Gender: Male
Age: 8 11
Joined:  

Additional Groups:
Support Team
***


Reputation: 45%  


pmwwwtwittergtalkvForum
Re: Dice rolls in post (9th Jun 09 at 2:51pm UTC)
Hi, I just posted this in your bugs thread not realising. The actual functionality now works, it's just the layout which will need some tweaking to reposition the button where you want it.

The (updated) code:

Code:
 
  1.  <style type="text/css">
  2. .dicebg {background-color: FFFFFF;border:solid 2px #000000;}
  3. .dicefont {background-color: FFFFFF;color: 000000; font-weight:bold;}
  4. </style>
  5. <script type="text/javascript">
  6. //Dice Rolls In Posts v1.1
  7. //Copyright 4-23-2007 ~Wonder
  8. //May be reposted anywhere as long as this header remains in tact
  9. //Modified by Ross of vForums Support for vForums compatibility
  10. //Do you want the dice to line of horizontally(true) or vertically(false)
  11. diceAlignment=true;
  12. //Enter URL of the image you want to appear as the dice ubbc button
  13. UBBCdiceImage="http://img100.imageshack.us/img100/6118/diceicon9rx.gif";
  14. //Enter the default # of sides
  15. defaultSides=20;
  16. //Enable dice in preview? true or false
  17. enablePreview=false;
  18. rs="";
  19. mainForm="";
  20. if(document.post_form || document.quick_reply_form) {
  21. if(document.post_form) {
  22. mainForm=document.post_form;
  23. if(location.href.match(/action\/modify/)){enablePreview=true;}
  24. ubbc_holder = document.createElement('span');
  25. get('ubbc_buttons', ID).appendChild(ubbc_holder);
  26. } else {
  27. ubbc_holder = get('quick_reply_ubbc', ID);
  28. mainForm=document.quick_reply_form;
  29. }
  30. ubbc_holder.innerHTML+="<a href=javascript:add_ubbc(\"[dice="+defaultSides+"]\",\"\")><img src=\""+UBBCdiceImage+"\" alt=\"Insert Dice Roll\" border=\"0\"></a>";
  31. mainForm.onsubmit=addRand;
  32. mainForm.message.value=mainForm.message.value.replace(/(\[rand\=\d+\])/ig,"");
  33. rs=RegExp. ; rs=(/\[rand\=/.test(rs))?rs:"";
  34. if(location.href.match(/quote\/\d+/))
  35. {
  36. mainForm.message.value=mainForm.message.value.replace(/(\[dice\=\d+\])/ig,"");
  37. rs="";
  38. }
  39. }
  40. ///////////////////////
  41. if(location.href.match(/action\/(view_topic|search|recent|pm_view|post|modify|create_poll)/)) {
  42. td=document.getElementsByTagName("td");
  43. topic_summary = false;
  44. for(i=0;i<td.length;i++) {
  45. if(td.item(i).className == 'post' || topic_summary) {
  46. // Remove from message preview
  47. if(td.item(i).className == 'post' && location.href.match(/action\/(post|modify|create_poll)/) && !enablePreview) {
  48. td.item(i).innerHTML=td.item(i).innerHTML.replace(/\[rand\=(\d|\w|<|>|\/|\s)+\]/gi,"");
  49. }
  50. rand=td.item(i).innerHTML.match(/\[rand\=(\d|\w|<|>|\/|\s)+\]/);
  51. if(rand!=null) {
  52. td.item(i).innerHTML=td.item(i).innerHTML.replace(rand[0],"");
  53. rand=rand[0].replace(/[^\d]/g,"");
  54. dice=td.item(i).innerHTML.match(/\[dice\=\d+(\+\d+)?\]/ig);
  55. if(dice!=null) {
  56. for(k=0;k<dice.length;k++) {
  57. numb=dice[k].match(/\d+(\+\d+)?/);
  58. numb=numb[0].split("+");
  59. addon=numb.length>1?parseInt(numb[1],10):0;
  60. numb=parseInt(numb[0],10);
  61. roll=Math.round((parseFloat(rand.substring(k,k+2)+"."+rand.substring(k+2,rand.length))/100)*(numb-1))+1+addon;
  62. td.item(i).innerHTML=td.item(i).innerHTML.replace(dice[k],"<table "+(diceAlignment?"style=\"display:inline\"":"")+" border=0 cellpadding=0 cellspacing=0><tr><td><table class=dicebg cellpadding=1 cellspacing=0><tr><td><center><font class=dicefont size=\"+1\"><b>"+roll+"</b><br><font size=\"1\">"+numb+" sides"+(addon>0?"+"+addon:"")+"</font></font></center></td></tr></table></td></tr></table>  ");
  63. }
  64. }
  65. }
  66. } else if(td.item(i).className == 'title1' && td.item(i).innerHTML.match(/>Topic Summary</i)) {
  67. topic_summary = true;
  68. }
  69. }
  70. }
  71. function addRand() {
  72. tinyMCE.triggerSave(true, true);
  73. mainForm.message.value=mainForm.message.value.replace(/(\[rand\=\d+\])/ig,"");
  74. if((rs.length==0 && mainForm.message.value.match(/(\[dice\=\d+(\+\d+)?\])/))) {
  75. mainForm.message.value+="[rand="+(Math.random()+"").replace(/0\./,"")+(Math.random()+"").replace(/0\./,"")+(Math.random()+"").replace(/0\./,"")+( Math.random()+"").replace(/0\./,"")+"]";
  76. } else {
  77. mainForm.message.value+=rs;
  78. }
  79. disable(mainForm);
  80. }
  81. </script>
 

Image
 Printable View
Page: 1 2

All times are GMT+0 :: The current time is 6:16am
Page generated in 1.5827 seconds
This Forum is Powered By vForums (v2.4)
Create a Forum for Free | Find Forums