inherit
141264
0
Aug 12, 2011 10:12:36 GMT -8
Gloometh
24
June 2009
gloometh
|
Post by Gloometh on Dec 24, 2009 17:21:20 GMT -8
I'm using Cr0w's lottery code and was wondering if it was possible to get a few things changed. Its all at the top part... the display part. (Also, I was wondering if I could change the number of numbers they draw?) I want the display to look different - first off, can I make it so that each number is in its own cell? So they aren't all displayed like 23,23,32,54, (which is like what they are now) but like... (With each | because a wall for a different cell.) Then if I can get the numbers that are picked go from four to three, that would be wonderful. Thats all. Is it possible? Oh, my site; nonstopstory.proboards.com/index.cgi?Thanks! *gives cookie*
|
|
inherit
Official Code Helper
65613
0
1
May 8, 2024 9:12:48 GMT -8
Chris
"'Oops' is the sound we make when we improve"
8,874
December 2005
horace
|
Post by Chris on Dec 25, 2009 15:24:28 GMT -8
I rewrote Cr0w's Lottery code a couple years ago as an exercise in admin editable codes and remembered when I saw this request. It took some effort to find it but here it is...
<script type="text/javascript"> <!-- /* @name Lottery System v1 by Cr0w Copyright 2006 Do not repost and keep this header intact (modified by Eton Bones) Install in MAIN HEADER */ var Lottery={ lotto_preferences:{ //changes made to preferences only take effect on next draw lotto_highestNumber:"80", lotto_picksPerDraw:"6" }, lotto_enabled:false, lotto_numbers:[], lotto_drawDate:new Date(), lotto_show:function(){ var LottoTable = '<table width="250px" cellpadding="4" cellspacing="1" align="center" class="bordercolor" id="LottoTable" '+((!this.lotto_enabled)?'style="display:none;"':'')+' >'; LottoTable += '<tr>'; LottoTable += '<td class="titlebg" width="100%" align="center">'; LottoTable += '<font size=2><b>Winning Lotto Numbers</b></font>'; LottoTable += '</td>'; LottoTable += '</tr>'; LottoTable += '<tr>'; LottoTable += '<td width="100%" class="windowbg2" vAlign="top" align="center" id="LotteryTable">'; LottoTable += '</td>'; LottoTable += '</tr>'; LottoTable += '</table>'; document.write(LottoTable) }, lotto_draw:function (){ var xxx=[],y=0,xxx1='' var L=Lottery var c =L.header.value.match(/lotto_enabled\s*:\s*(true|false)/g) if(!c){ alert('The Lottery code needs to see itself in the MAIN HEADER\nIf the code is remotely hosted, improperly installed, encoded or delegated (Hack Manager for example) it will fail.'); }else{ if(c.length>1){alert('The Lottery has detected multiple installs of itself in the MAIN HEADER\nOnly one instance of the code is required else it may fail.');} if(!isNaN(document.getElementById('lottohigh').value) && parseInt(document.getElementById('lottohigh').value)>1){ L.header.value = L.header.value.replace(/lotto_highestNumber\s*:\s*['"]?\s*\d+\s*['"]?/,'lotto_highestNumber:"'+document.getElementById('lottohigh').value+'"'); L.lotto_preferences.lotto_highestNumber=document.getElementById('lottohigh').value }else{alert('The high number value is invalid');return true} if(!isNaN(document.getElementById('lottopick').value) && parseInt(document.getElementById('lottopick').value)>0){ L.header.value = L.header.value.replace(/lotto_picksPerDraw\s*:\s*['"]?\s*\d+\s*['"]?/,'lotto_picksPerDraw:"'+document.getElementById('lottopick').value+'"'); L.lotto_preferences.lotto_picksPerDraw=document.getElementById('lottopick').value }else{alert('The number of picks is invalid');return true} var x=[] for(var z=0;z<this.lotto_preferences.lotto_picksPerDraw;z++){ var y=Math.round(Math.random()*this.lotto_preferences.lotto_highestNumber),w=0 while(String(','+x.join(',')+',').indexOf(String(','+y+','))>-1 && w<10) {y=Math.round(Math.random()*this.lotto_preferences.lotto_highestNumber);w++} x.push(y) } L.header.value = L.header.value.replace(new RegExp('lotto_enabled\s*:\s*'+L.lotto_enabled),'lotto_'+'enabled:true'); L.header.value = L.header.value.replace(/lotto_numbers\s*\:\s*\[[^)]*\]/,'lotto_numbers:['+x.join(',')+']') L.header.value = L.header.value.replace(/lotto_drawDate\s*\:\s*new\s+Date\([^)]*\)/,'lotto_drawDate:new Date('+ (new Date(new Date().toGMTString()).getTime()) +')') } document.forms.item(0).submit(true); }, lotto_disable:function(){ Lottery.header.value = Lottery.header.value.replace(new RegExp('lotto_enabled:'+Lottery.lotto_enabled+'',"i"),'lotto_'+'enabled:false'); document.forms.item(0).submit(true); }, lotto_prepdraw:function(){ var LottoBody = document.getElementById('LottoTable'); LottoBody.width="92%"; document.getElementById('LotteryTable').removeAttribute('title') LottoBody.rows[0].cells[0].lastChild.innerHTML="<b>Lottery Settings</b>" LottoBody.rows[0].cells[0].removeAttribute('align') LottoBody.rows[1].cells[0].removeAttribute('align') var h ='<table cellpadding="0" cellspacing="0" ><tbody><tr><td width="25%">' h += 'Picks per Drawing:</td><td width="17%"> <input type="text" size="3" id="lottopick" value="'+parseInt(this.lotto_preferences.lotto_picksPerDraw)+'" />' h += '</td><td width="58%" >The amount of numbers that will be picked during a single lottery drawing</td>' h += '</td></tr><tr><td colspan="3"> <br></td></tr><tr>' h += '<td width="25%">Highest Pick:</td><td width="17%"><input type="text" size="6" id="lottohigh" value="'+parseInt(this.lotto_preferences.lotto_highestNumber)+'" /></td>' h += '<td width="58%" >The highest number any single pick can reach <br>(example: a value of 80 means a pick can be any number between and including 1 and 80)</td>' h += '</tr></tbody></table><br><br>' h += "Choose your preferences above then " +((!this.lotto_enabled)?'click the "Activate Lottery" button to enable and select numbers for the lottery system.':'click the "Pick new numbers" button to select new numbers for the lottery system.')+'<br><tt>Everyone on this forum will see the exact same numbers.</tt>'+'<br><br>'; h += '<center><input type="button" value="'+((this.lotto_enabled)?'Pick new numbers':'Activate Lottery')+'" onclick="Lottery.lotto_draw()"> <input type="button" value="Deactivate Lottery" onclick="Lottery.lotto_disable()" '+((!this.lotto_enabled)?'disabled="true"':'')+'></center>'; LottoBody.rows[1].cells[0].innerHTML = h LottoBody.style.display=""; h = document.createElement('span'); h.className="nav" h.innerHTML = '<a href="/">'+document.title.split(/\s-\s/)[0]+'</a> :: <a href="/?action=admin">Administration Area</a> :: Lottery Settings' LottoBody.parentNode.insertBefore(h,LottoBody) h.style.cssText="position: relative; left: 4%;" }, lotto_admin:function(){ document.title = document.title.replace('Modify Headers and Footers','Lottery Settings'); var Table = document.getElementsByTagName('Table'),t,u=null; for(t=4;t<Table.length;t++){ Table.item(t).style.display = 'none' } Lottery.header = document.getElementsByName('header').item(0); Lottery.lotto_prepdraw() }, lotto_panel:function(){ var lnk = document.getElementsByTagName('a'); for(q=0;q<lnk.length;q++){ if(lnk[q].href && lnk[q].href.match(/action=headersfooters\b/i)){ lnk[q].parentNode.innerHTML ='<a href="index.cgi?action=headersfooters2&id=-&system=Lottery">Lottery System</a><br />' + lnk[q].parentNode.innerHTML; break; } } }, init:function(){ this.lotto_show() document.getElementById("LotteryTable").innerHTML = '<table border="1" style="text-align:center" width="100%" height="100%"><tbody><tr><td>'+this.lotto_numbers.join('</td><td>')+'</td></tr></tbody></table>'; document.getElementById("LotteryTable").title='Drawing Date:'+this.lotto_drawDate.toGMTString() if(window.addEventListener){ if(location.href.match(/action=(admin|\w+3)/i))window.addEventListener('load',this.lotto_panel,false) if(location.href.match(/system=Lottery/))window.addEventListener('load',this.lotto_admin,false) }else if(window.attachEvent){ if(location.href.match(/action=(admin|\w+3)/i))window.attachEvent('onload',this.lotto_panel) if(location.href.match(/system=Lottery/))window.attachEvent('onload',this.lotto_admin) } } } Lottery.init() // --> </script>
I've modified to slightly to put the numbers in cells for this request. The code is admin editable like the original so no direct editing of the code itself should be required unless it pertains to appearance. The main feature added is the ability to choose how many numbers are chosen in a single drawing and no footer portion is needed.
edit: fixed a bug when set to choose only one number
|
|
inherit
141264
0
Aug 12, 2011 10:12:36 GMT -8
Gloometh
24
June 2009
gloometh
|
Post by Gloometh on Dec 26, 2009 15:28:25 GMT -8
Okay, thank you so much! x3 I'll go see if it works!
EDIT:
Its perfect! Thank you, thank you, thank!!!
|
|
inherit
Official Code Helper
65613
0
1
May 8, 2024 9:12:48 GMT -8
Chris
"'Oops' is the sound we make when we improve"
8,874
December 2005
horace
|
Post by Chris on Dec 26, 2009 20:36:49 GMT -8
You're welcome
|
|