|
Boc
| Reputation: 157 | Group: | Admin | Posts: | 19,204 | Joined: | Jun 22, 2012 |
| Post #1: 13th Feb 2021 4:59 PM | |
HEY! So unlike most ndim feature requests, this is something that's actually doable without having access to the source code (albeit in a roundabout way). I threw this together and added it to FE, here's the code to add this to any NDim board (Code Editor > Below the Board):
|
|
<script>
var inlineClick;
if($(".innertable .innercontent input[value='B']").length) {
$(".innertable .innercontent input[value='B']").parent("td").append('<input class="buttonstyle" type="button" value="Roll" onmouseover="[roll]XdY[/roll]" onclick="var numDice=prompt(\'How many dice?\',\'\');var numSides=prompt(\'How many sides?\',\'\');insertBBCode(inputBox,\'[roll]\',numDice+\'d\'+numSides+\'[/roll]\',true,document.getElementById(\'fullreply\'))" />');
}
if ($("#sendform input:button").length) {
inlineClick = $("#sendform input:button")[0].onclick;
$("#sendform input:button")[0].onclick = null;
$("#sendform input:button").click(function(e) {
parseRoll("#sendform textarea#fastreply");
});
$("#sendform input:button")[0].onclick = inlineClick;
}
if ($("#frform input:button").length) {
inlineClick = $("#frform input:button")[0].onclick;
$("#frform input:button")[0].onclick = null;
$("#frform input:button").click(function(e) {
parseRoll("#frform textarea#frbox");
});
$("#frform input:button")[0].onclick = inlineClick;
}
if ($('form[name="addreply"] input:button[value="Add Reply"]').length) {
inlineClick = $('form[name="addreply"] input:button[value="Add Reply"]')[0].onclick;
$('form[name="addreply"] input:button[value="Add Reply"]')[0].onclick = null;
$('form[name="addreply"] input:button[value="Add Reply"]').click(function(e) {
parseRoll('form[name="addreply"] textarea#fullreply');
});
$('form[name="addreply"] input:button[value="Add Reply"]')[0].onclick = inlineClick;
}
// full PMs
if ($("form[name='sendpost'] input:button[value='Send']").length) {
inlineClick = $("form[name='sendpost'] input:button[value='Send']")[0].onclick;
$("form[name='sendpost'] input:button[value='Send']")[0].onclick = null;
$("form[name='sendpost'] input:button[value='Send']").click(function(e) {
parseRoll('form[name="sendpost"] textarea#fullreply');
});
$("form[name='sendpost'] input:button[value='Send']")[0].onclick = inlineClick;
}
// quick PMs
if ($('form[name="sendpost"] input:button[value="Add Reply"]').length) {
inlineClick = $('form[name="sendpost"] input:button[value="Add Reply"]')[0].onclick;
$('form[name="sendpost"] input:button[value="Add Reply"]')[0].onclick = null;
$('form[name="sendpost"] input:button[value="Add Reply"]').click(function(e) {
parseRoll('form[name="sendpost"] textarea#fullreply');
});
$('form[name="sendpost"] input:button[value="Add Reply"]')[0].onclick = inlineClick;
}
// fast PMs
if ($("#fpmform input:button").length) {
inlineClick = $("#fpmform input:button")[0].onclick;
$("#fpmform input:button")[0].onclick = null;
$("#fpmform input:button").click(function(e) {
parseRoll("#fpmform textarea#fpbox");
});
$("#fpmform input:button")[0].onclick = inlineClick;
}
function parseRoll(textElement) {
var fastReplyText = $(textElement).val();
var validationRegEx = new RegExp(/(?:\[quote.*\][\S\s]*Rolled:[\S\s]*\[\/quote\])|(.*Rolled:.*)/gi);
var validationResult = Array.from(fastReplyText.matchAll(validationRegEx));
if (!!validationResult.length && !!validationResult.some(match => !!match[1])) {
$(textElement).val(fastReplyText + " [color=red]!!!POSSIBLE CHEATING DETECTED!!![/color]");
return false;
}
var rollRegEx = /\[roll\]([0-9]{1,2})d([0-9]{1,3})\[\/roll\]/g;
var m;
while ((m = rollRegEx.exec(fastReplyText)) !== null) {
if (m.index === rollRegEx.lastIndex) {
rollRegEx.lastIndex++;
}
m.forEach((match, groupIndex) => {
var rollString = match.match(/([0-9]{1,2})d([0-9]{1,3})/gi);
if (rollString === null) return;
var results = rollDice(rollString[0]);
var str = "[i]Rolled: [b]" + results.reduce((a, b) => a + b, 0) + "[/b] (";
for (var i = 0; i < results.length; i++) {
str += results[i];
if (i !== results.length - 1) {
str += "+";
}
}
str += ") [" + rollString + "][/i]";
fastReplyText = fastReplyText.replace(match, str);
});
}
$(textElement).val(fastReplyText);
return true;
}
function rollDice(rollString) {
var diceValues = rollString.split('d');
var results = [];
for (var i = 0; i < diceValues[0]; i++) {
results.push(Math.ceil(Math.random() * diceValues[1]));
}
return results;
}
</script> |
|
I'll update this post if/when I update this script. Right now it only works via Fast Reply (like I said it's roundabout so I have to manually hook it up to any button that can submit a post).
HOW IT WORKS
Just post the following (for example):
[ roll ]2d6[ / roll ]
(obv remove the spaces first)
Also, as a very basic way of not allowing people to fake a dice roll, if you try to straight-up post "Rolled:", it'll tack on a message letting the world know you could be a dirty cheater
Also also, if you have any improvement suggestions or find any bugs with it LMK!
PATCH NOTES
+ Now works with Add Reply, Fast Reply, and Quick Reply Box
+ Now works with PMs
+ No longer detects as cheater when quoting someone's roll
+ Added Roll button on Add Reply screen
Post Edited by Boc @ 23rd Feb 2022 10:00 AM | |
| | |
Dyl
Butt Not Even Visible
| Reputation: 80 | Group: | Moderator | Posts: | 13,554 | Joined: | Jun 25, 2012 |
| Post #2: 13th Feb 2021 5:03 PM | |
MVP | "So, uh, what are we saying here? If we save LA from a nuclear bomb, then you and I can get together for dinner and a movie?"
|
| | |
Curtis
First Place Dick
| Reputation: 1,170 | Group: | Admin | Posts: | 79,234 | Joined: | Jun 22, 2012 |
| Post #3: 13th Feb 2021 5:05 PM | |
Helllllllll yawwwww
This is gonna be a game changer for games here, we can come up with all kinds of new things to use it for. RnF folks are you ready for FE Dicevivor to become a thing? | |
| | |
Curtis
First Place Dick
| Reputation: 1,170 | Group: | Admin | Posts: | 79,234 | Joined: | Jun 22, 2012 |
| Post #4: 13th Feb 2021 5:06 PM | |
Very curious to see what ORG hosts can come up with too, either for challenges or twists or swaps or who knows | |
| | |
Curtis
First Place Dick
| Reputation: 1,170 | Group: | Admin | Posts: | 79,234 | Joined: | Jun 22, 2012 |
| Post #5: 13th Feb 2021 5:09 PM | |
Who's gonna find a way to run a dice based Mafia | |
| | |
Lamps
Sansa
| Reputation: 104 | Group: | Overlord | Posts: | 14,181 | Joined: | Oct 1, 2013 |
| Post #6: 13th Feb 2021 5:10 PM | |
FE dicevivor bb omg | |
| | |
mal
Pronouns: they/them
| Reputation: 104 | Group: | Overlord | Posts: | 12,650 | Joined: | Jun 26, 2012 |
| Post #7: 13th Feb 2021 5:10 PM | |
Rolled: 69 !!!POSSIBLE CHEATING DETECTED!!! | |
| | |
Lamps
Sansa
| Reputation: 104 | Group: | Overlord | Posts: | 14,181 | Joined: | Oct 1, 2013 |
| Post #8: 13th Feb 2021 5:11 PM | |
Rolled: 10 (6+4) [2d6]
Rolled: 75 (46+29) [2d100] | |
| | |
mal
Pronouns: they/them
| Reputation: 104 | Group: | Overlord | Posts: | 12,650 | Joined: | Jun 26, 2012 |
| Post #9: 13th Feb 2021 5:11 PM | |
It works wow love it | |
| | |
Curtis
First Place Dick
| Reputation: 1,170 | Group: | Admin | Posts: | 79,234 | Joined: | Jun 22, 2012 |
| Post #10: 13th Feb 2021 5:13 PM | |
| |
| | |
Spin
Milk Bowl
| Reputation: 119 | Group: | Godfather | Posts: | 25,300 | Joined: | Feb 18, 2015 |
| Post #11: 13th Feb 2021 5:17 PM | |
Looks like I might have to resurrect another go at The Quick and The Dead mafia, and use dice rolls instead of Rock-Paper-Scissors. | |
| | |
John Snav
Confirmed misogynist
| Reputation: 120 | Group: | Overlord | Posts: | 16,277 | Joined: | Sep 18, 2014 |
| Post #12: 13th Feb 2021 5:38 PM | |
[roll]2d6[/roll]
| |
| | |
John Snav
Confirmed misogynist
| Reputation: 120 | Group: | Overlord | Posts: | 16,277 | Joined: | Sep 18, 2014 |
| Post #13: 13th Feb 2021 5:39 PM | |
Rolled: 6 (3+3) [2d6]
| |
| | |
John Snav
Confirmed misogynist
| Reputation: 120 | Group: | Overlord | Posts: | 16,277 | Joined: | Sep 18, 2014 |
| Post #14: 13th Feb 2021 5:39 PM | |
You meant ADD REPLY instead of Fast Reply smh | |
| | |
John Snav
Confirmed misogynist
| Reputation: 120 | Group: | Overlord | Posts: | 16,277 | Joined: | Sep 18, 2014 |
| Post #15: 13th Feb 2021 5:39 PM | |
Rolled: 6 !!!POSSIBLE CHEATING DETECTED!!! | |
| | |
2 Users Viewing (2 Guests) |
|
|