ntcnbyu
Ntcnjdfz ntvf
Сообщений 1 страница 4 из 4
Поделиться22011-05-13 23:31:31
<input type="button" onclick="dice()" value="Кинуть кубики" />
<script type="text/javascript">
function dice()
{
var FoundErrors = '';
var diceRes=""
var CountCube = 3
var SideCube = 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>
Поделиться32011-05-13 23:34:06
[dice=7744-5808-5808-36]
Поделиться42011-05-13 23:36:47
[dice=3872-16]