Скрипт позволит "кидать" кубики прямо на форуме.
Полезно для ролевых форумов.
Вариант 1.
Код:<input type="button" onclick="dice()" value="Кинуть кубики" /> <script type="text/javascript"> function dice() { var FoundErrors = ''; var diceRes="" var CountCube = prompt("Количество кубиков", "3"); var SideCube = prompt("Сколько граней у кубика?", "6"); if(CountCube>9){ alert("Нельзя бросать столько кубиков"); return false;} if(SideCube>9){ alert("Не бывает таких кубиков"); return false;} if (!CountCube) {return false;} if (!SideCube) {return false;} for(i=0; i<CountCube;i++){ var dice = (Math.round(Math.random()*SideCube)) if(dice==0) dice=1; diceRes += dice*1936+"-" } smile('[dice='+diceRes+CountCube+SideCube+']') } </script> <script> function addDice(str,from,internal){ var pos=0,pos2=0,newpos=0 if((pos=str.indexOf("[dice=",from))==-1) return str; if((pos2=str.indexOf("]"),pos+6)==-1) return str; newpos=str.indexOf("]",pos+6) if(newpos<pos2 && newpos!=-1) str=addDice(str,pos+6,true) if((pos2=str.indexOf("]",pos+6))==-1) return str; str=str.substring(0,pos)+makeDice(str.substring(pos+6,pos2))+str.substring(pos2+1,str.length) if( str.indexOf("[dice=")!=-1 && internal==false) str=addDice(str,0,false) return str} function makeDice(dice){ diceMass = dice.split("-") diceC = dice.substring(dice.length-2, dice.length-1) diceS = dice.substring(dice.length-1, dice.length) var diceR=0, diceRu=""; for(i=0;i<diceMass.length-1;i++){diceR+=diceMass[i]/1936;} for(i=0;i<diceMass.length-1;i++){if(diceMass[i]==diceMass[diceMass.length-2]){diceRu+=diceMass[i]/1936;}else{diceRu+=parseInt(diceMass[i]/1936)+"+";}} txt="<div class=\"quote-box\"><blockquote><p><b>Количество кубиков</b>: "+diceC+"<br /><b>Граней в кубике</b>: "+diceS+"<br /><br /><b>Результаты броска</b>: ("+diceRu+")="+diceR+"</p></blockquote></div>" return txt} if(document.URL.indexOf("viewtopic.php")!=-1){ elm=document.getElementById("pun-main").getElementsByTagName("div") for(x in elm) if(elm[x].className=="post-content"){ var post=elm[x] post.innerHTML=addDice(post.innerHTML,0,false)}} </script>Вариант 2.
Код:<input type="button" onclick="dice()" value="Кинуть кубики" /> <script type="text/javascript"> function dice() { var FoundErrors = ''; var diceRes="" var CountCube = prompt("Количество кубиков", "3"); var SideCube = prompt("Сколько граней у кубика?", "6"); if(CountCube>9){ alert("Нельзя бросать столько кубиков"); return false;} if(SideCube>9){ alert("Не бывает таких кубиков"); return false;} if (!CountCube) {return false;} if (!SideCube) {return false;} for(i=0; i<CountCube;i++){ var dice = (Math.round(Math.random()*SideCube)) if(dice==0) dice=1; diceRes += dice*1936+"-" } smile('[dice='+diceRes+CountCube+SideCube+']') } </script> <script> function addDice(str,from,internal){ var pos=0,pos2=0,newpos=0 if((pos=str.indexOf("[dice=",from))==-1) return str; if((pos2=str.indexOf("]"),pos+6)==-1) return str; newpos=str.indexOf("]",pos+6) if(newpos<pos2 && newpos!=-1) str=addDice(str,pos+6,true) if((pos2=str.indexOf("]",pos+6))==-1) return str; str=str.substring(0,pos)+makeDice(str.substring(pos+6,pos2))+str.substring(pos2+1,str.length) if( str.indexOf("[dice=")!=-1 && internal==false) str=addDice(str,0,false) return str} function makeDice(dice){ diceMass = dice.split("-") diceC = dice.substring(dice.length-2, dice.length-1) diceS = dice.substring(dice.length-1, dice.length) var diceR=0, diceRu=""; for(i=0;i<diceMass.length-1;i++){diceR+=diceMass[i]/1936;} for(i=0;i<diceMass.length-1;i++){if(diceMass[i]==diceMass[diceMass.length-2]){diceRu+=diceMass[i]/1936;}else{diceRu+=parseInt(diceMass[i]/1936)+"+";}} txt="<div class=\"quote-box\"><blockquote><p><b>Исходный бросок</b>: "+diceC+"d"+diceS+"<br /><br /><b>Результаты броска</b>: ("+diceRu+")="+diceR+"</p></blockquote></div>" return txt} if(document.URL.indexOf("viewtopic.php")!=-1){ elm=document.getElementById("pun-main").getElementsByTagName("div") for(x in elm) if(elm[x].className=="post-content"){ var post=elm[x] post.innerHTML=addDice(post.innerHTML,0,false)}} </script>Пользователь вводит сколько надо бросить кубиков и сколько в нем граней.
Далее получает уникальный код, который может произвольно перемещать в сообщении
После отправки в сообщении будет такая картина
Вставлять в ФОРМУ ОТВЕТА
Вариант 3, актуальный. - апдейтнутый и исправленный другими кодерами на момент 2021-го года.
<script type="text/javascript">
function unhtml(s)
{ return s.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">"); }
function numword(s,one,two,many)
{ return(((s%100>=10 && s%100<=20) || s%10>=5) ? many :
(s%10==1 ? one : two)); }
function dice()
{
var FoundErrors = '';
var diceRes=""
var CountCube = prompt("Сколько кубиков кидаешь?", "1");
if(CountCube>10 || CountCube<=0) {
alert("Можно кинуть не более десяти кубиков."); return false;}
var SideCube = prompt("Сколько граней у твоего кубика?", "6");
if(SideCube>100 || SideCube<=0){
alert("Таких кубиков не может быть."); return false;}
var ReasonCube = unhtml(prompt("Что спрашиваешь у кубика?", "").
replace(/\s+/g," ").replace("]"," "));
for(i=0; i<CountCube;i++)
{
var dice = (Math.round(Math.random()*SideCube));
if(dice==0) dice=1;
diceRes += dice*1936+"-";
}
smile('[dice='+diceRes+CountCube+':'+SideCube+
':'+ReasonCube+']');
}
function addDice(post, from, internal) {
var str = post.innerHTML;
var a = $(post).closest('.post').innerHTML;
var u = "";
var num = +post.id.match(/\d+/g)[0];
var date = new Date(+$(post).attr('data-posted')*1000).getSeconds();
var fCanRandomise = 1;
var ran = num + date;
return str
.replace(
/\[dice=((?:\d+[-—])*)(?:(\d)(\d+)|(\d+)(:)(\d+)(?::)()(?:([^\]]*))?)]/g,
function(a, dice, diceC, diceS, adieC, fNewScheme, adieS, adieB, adieR) {
dice = dice.replace(/[-—]/g, '-');
adieB = adieB.replace(/[-—]/g, '-');
diceC = parseInt(fNewScheme ? adieC : diceC);
diceS = parseInt(fNewScheme ? adieS : diceS);
adieB = parseInt(adieB ? adieB : 0);
if(adieB > 0) adieB='+'+adieB;
if(!fCanRandomise && fNewScheme)
return '<div class="quote-box"><blockquote><p><b>Что-то не получилось, сообщите администрации</b></p></blockquote></div>';
var i,
diceR = 0,
s = '<div class="quote-box"><blockquote '
+ 'style="text-align:left"><p>'
+ '<b>Игрок кинул '
+ diceC + numword(diceC,' из кубиков с ',' кубика с ',' кубиков с ')
+ diceS + numword(diceS,' гранью зла',' гранями зла',' гранями зла')
+ (adieB ? (adieB>0 ? ' и бонусом ' : ' и пенальти ')+adieB : '')
+ (adieR ? ', чтобы узнать:</b><br><i>'+adieR+'</i><b>' : '')
+ '<br /><br />Злобные Кубики Бесконечности ответили'
+ (fNewScheme ? '' : '(старая схема)')+'</b>: (';
dice = dice.split("-");
for (var i=0; i < dice.length-1; ++i) {
var d = parseInt(dice[i]/1936);
date=((date>>1)+((date&1)<<21))&0x3fffff;
num=((num>>1)+((num&1)<<22))&0x7fffff;
if(fNewScheme)
d = (ran=(((ran>>1)+(((ran&1) ? 0 : 1)<<23)+d+date)^num)&0xffffff)%diceS + 1;
diceR += d;
s+= (i?' + ':'') + d;
}
if (adieB)
diceR += parseInt(adieB);
return (s + (adieB ? ')'+adieB : ')')
+ '=' + diceR + '</p></blockquote></div>');
}
);
}
$(document).ready(function() { initDices() });
$(document).on('pun_post', function() { initDices() });
$(document).on('pun_edit', function() { initDices() });
function initDices() {
if (! FORUM.topic) return;
$('.post-content').each(function(i, post) {
var str = post.innerHTML;
var isDiceInPost = /\[dice=((?:\d+[-—])*)(?:(\d)(\d+)|(\d+)(:)(\d+)(?::)()(?:([^\]]*))?)]/.test(str);
if (!isDiceInPost) return;
post.innerHTML = addDice(post);
});
}
$(document).ready(function() {
$('#addition-area').append(function () {
return $('<div>Кинуть кубик</div>').click(dice);
});
});
</script>Теги: Скрипты и дополнения, Форма ответа


Объясни пожалуйста подробно, что значит выбрасывать кубики...


в скриптах не силен, не силен.