|
Post by Wormopolis on Aug 27, 2012 22:03:00 GMT -8
Browsers Tested: IE, FF and Chrome placement: board footer and global footer
This code allows you to setup a one-click button that generates a random encounter from a list of monsters you create. you can define all of the monster stats, min/max appearing, how rare the monster is, and even some custom attributes for that monster alone. you can also define if the monster would appear with other monsters and how many!
have a look at the example troll to see how a monster is edited. I would advise to keep that default one in there for later. it wont affect you results.
board footer part:
<script type="text/javascript"> <!-- // Random Encounters // v2.0 // by Wormopolis - www.wormocodes.com // do not repost - keep header intact // board footer section
var RE_buttonImage="http://i197.photobucket.com/albums/aa250/WORMOPOLIS/randenc.gif"; var RE_disableButtonAfterOneClick=true; var RE_usersWhoCanUseButton="admin|user2|user3";
var encounterList=new Array(); /* EXAMPLE (keep this in here - it wont affect your results)
encounterList['Troll']={ Frequency: '2', //this controls how often this monster appears, lower number means more rare Min: '5', //minimum appearing Max: '10', //maximum appearing Stats: [['Strength','3','20'],['Agility','1','16'],['Hit Points','10','30']], //the stats of the monster, you can edit or add more // notice the array structure: [stat name, minimum of stat, maximum of stat]
// above is required to have // below are custom attributes of the monster
Weapons: [['Fists','100%','(2-10)'],[['Club','70%','(5-15)'],['Iron Mace','30%','(10-20)'],'25%']], // structure: [name, chance, damage or note] // if you want a subset array, the structure is [[name1, chance, damage or note],[name2, chance, note],chance of subset] // so there is a 25% chance of getting club OR mace, and then a 70% chance of club and 30% for mace // subset percentages should add to 100%
Spells: [], // you can leave as an empty array or just omit completely
// below is if the monster appears with other monsters. it can be removed if you wish
Company: [['Troll King','1','1','80%'],['Troll Dog','3','8','60%']] // structure: [other monster name, min appearing, max appearing, chance of appearance] // the name must exactly match your defined monster };
*/
encounterList['Troll']={ Frequency: '2', Min: '5', Max: '10', Stats: [['Strength','3','20'],['Agility','1','16'],['Hit Points','10','30']], Weapons: [['Fists','100%','(2-10)'],[['Club','70%','(5-15)'],['Iron Mace','30%','(10-20)'],'25%']], Spells: [], Company: [['Troll King','1','1','80%'],['Troll Dog','3','8','60%']] }; encounterList['Troll King']={ Frequency: '1', Min: '1', Max: '1', Stats: [['Strength','5','20'],['Agility','3','16'],['Hit Points','15','40']], Weapons: [['Fists','100%','(4-12)'],['Club','20%','(5-15)'],['Iron Mace','40%','(10-20)'],['Giant Sword','40%','(16-30)']], Spells: [['Fear','20%','(reduces opp strength)']], Company: [['Troll','10','20','100%'],['Troll Dog','8','12','60%']] }; encounterList['Troll Dog']={ Frequency: '3', Min: '3', Max: '10', Stats: [['Strength','1','5'],['Agility','3','8'],['Hit Points','2','10']], Weapons: [['Bite','100%','(2-8)'],['Claw','100%','(1-6)']], Spells: [], Company: [['Troll','1','5','75%']] }; encounterList['Evil Wizard']={ Frequency: '1', Min: '1', Max: '1', Stats: [['Strength','2','12'],['Agility','2','12'],['Hit Points','10','25']], Weapons: [['Dagger','50%','(1-10)']], Spells: [['Fireball','20%','(10-20)'],['Lightning Bolt','50%','(10-20)'],['Raise Undead','20%','(calls forth zombie army)'],['Blindness','50%','(temporary blinds opponent)'],['Dark Bolt','60%','(12-25)']], Company: [] }; encounterList['Red Dragon']={ Frequency: '1', Min: '1', Max: '1', Stats: [['Strength','8','20'],['Agility','6','20'],['Hit Points','40','80']], Weapons: [['Bite','100%','(10-20)'],['Claw','100%','(10-20)'],['Fire Breath','100%','(20-30)']], Spells: [['Fear','60%','(reduces opp strength)'],['Fire Wall','30%','(8-16)'],['Dust Storm','40%','(temporary blinds opponents)']], Company: [] }; encounterList['Giant Wasp Queen']={ Frequency: '1', Min: '1', Max: '1', Stats: [['Strength','2','12'],['Agility','5','18'],['Hit Points','10','25']], Weapons: [['Sting','100%','(10-20)'],['Bite','100%','(3-10)']], Spells: [], Company: [['Giant Wasp','10','20','100%']] }; encounterList['Giant Wasp']={ Frequency: '2', Min: '5', Max: '15', Stats: [['Strength','2','10'],['Agility','5','18'],['Hit Points','6','15']], Weapons: [['Sting','100%','(5-15)'],['Bite','100%','(1-6)']], Company: [['Giant Wasp Queen','1','1','30%']] };
var percentageOfARandomEncounter='50%'; var whatToSayWhenNothingIsEncountered="You hear a noise, but there is nothing there!";
// no editing below is necessary unless you know what you are doing
function getEncounterList(type, min, max) { var encResults=[]; erescount=0; var totalAppearing=parseInt(min||encounterList[type].Min) + Math.floor(Math.random()*((max-min)||(parseInt(encounterList[type].Max) - parseInt(encounterList[type].Min)))); for (ta=0; ta<totalAppearing; ta++) { var encresStats=[]; encresStatcount=0; for (er=0; er<encounterList[type].Stats.length; er++) { encresAbscore=parseInt(encounterList[type].Stats[er][1]) + Math.floor(Math.random()*(encounterList[type].Stats[er][2] - encounterList[type].Stats[er][1])); encresStats[encresStatcount++]=encounterList[type].Stats[er][0] +': '+ encresAbscore; } encResults[erescount]=new Array(); dataArray=new Array(); dataArray[0]='Name= ' + type; dataArray[1]='Stats= ' + encresStats; datacount=2; for (part in encounterList[type]) { if (part!='Frequency' && part!='Min' && part!='Max' && part!='Company' && part!='Stats') { var encresParts=[]; encresPartscount=0; for (er=0; er<encounterList[type][part].length; er++) { if (encounterList[type][part][er] instanceof Array && encounterList[type][part][er][0] instanceof Array) { // inclusive group found. create randomresult array and choose one of the items var randomresult=[]; var rr=0; for (rrc=0; rrc<encounterList[type][part][er].length-1; rrc++) { //last element is chance current_rrN=encounterList[type][part][er][rrc][0]; current_rrC=encounterList[type][part][er][rrc][1]; current_rrD=encounterList[type][part][er][rrc][2]; for (rra=0; rra<parseInt(current_rrC); rra++) randomresult[rr++]=current_rrN + ' ' + current_rrD; } var rr_chance= encounterList[type][part][er][ encounterList[type][part][er].length-1 ]; rr_chance= parseInt(rr_chance) / 100.0; var rr_choice= randomresult[ Math.floor(Math.random() * 100) ]; if (Math.random() < rr_chance) encresParts[encresPartscount++] = rr_choice; } else { encresPartChance=parseInt(encounterList[type][part][er][1]) / 100.0; if (Math.random() <= encresPartChance) encresParts[encresPartscount++]=encounterList[type][part][er][0] +' '+ encounterList[type][part][er][2]; } } dataArray[datacount++]=part + '= ' + encresParts;
} } encResults[erescount][0]=encounterList[type].Frequency; encResults[erescount++][1]=dataArray; } if (encounterList[type].Company && !min) { for (ac=0; ac<encounterList[type].Company.length; ac++) { var accomptemp=getEncounterList(encounterList[type].Company[ac][0], encounterList[type].Company[ac][1], encounterList[type].Company[ac][2]); var accompchance=parseInt(encounterList[type].Company[ac][3]) / 100.0; if (Math.random() <= accompchance) encResults=encResults.concat(accomptemp); } } return encResults; }
function convertToTag(encArray) { var taggedEncResults='[randomEncounter]', tierwatch=''; for (encTier=0; encTier<encArray.length; encTier++) { if (encArray[encTier][0]!=tierwatch) { if (tierwatch!='') taggedEncResults+= '[/tier]'; tierwatch=encArray[encTier][0]; taggedEncResults+= '[tier=' + tierwatch + ']'; } for (i=0; i<encArray[encTier][1].length; i++ ) taggedEncResults+= '[' + encArray[encTier][1][i] + ']'; taggedEncResults+= '[/' + encArray[encTier][1][0] + ']'; } taggedEncResults+= '[/tier][/randomEncounter]'; return taggedEncResults; }
function clickEncounter(){ // get list of all encounters with weights and randomize var encList=[]; ecount=0; for (encname in encounterList) { for (ee=0; ee<parseInt(encounterList[encname].Frequency); ee++) encList[ecount++]=encname; } var chosenEnc=encList[Math.floor(Math.random()*ecount)]; var encounterResults=((Math.random())< (parseInt(percentageOfARandomEncounter)/100.0) ? getEncounterList(chosenEnc,0).sort() : whatToSayWhenNothingIsEncountered); var tmpstuff='[table][tr][td][center]Random Encounter![/center][/td][/tr][tr][td]'; if (typeof encounterResults == 'string') { tmpstuff+='[randomEncounter][none]' + encounterResults+ '[/none][/randomEncounter][/td][/tr][/table]'; } else { tmpstuff+=convertToTag(encounterResults) + '[/td][/tr][/table]'; } document.postForm.message.value+='\n' + tmpstuff;
}
if (document.postForm && pb_username.match(new RegExp('^('+RE_usersWhoCanUseButton+')$',''))) { var encmsg=document.postForm.message; var smrow=encmsg.parentNode.parentNode.parentNode.previousSibling; var rerow=smrow.cloneNode(true); rerow.firstChild.firstChild.innerHTML=''; rerow.firstChild.nextSibling.firstChild.innerHTML='<img src="' + RE_buttonImage + '" border="1" onclick="clickEncounter(); ' + (RE_disableButtonAfterOneClick ? 'this.onclick=\'\'; this.style.opacity=\'.5\'; this.style.filter = \'alpha(opacity=50\';' : '') + '">'; smrow.parentNode.insertBefore(rerow, smrow); }
// --> </script>
global footer part:
<style type="text/css"> .RE_table {background-color: #111111;} .RE_title {background-color: #001100;} .RE_title font {font-size: 16px; color: #11DD00;} .RE_cell {border: 1px solid #FFFFFF; background-color: #000011;} .RE_name {font-size: 14px; color: #AAAAFF;} </style>
<script type="text/javascript"> <!-- // Random Encounters // v2.0 // by Wormopolis - www.wormocodes.com // request by Ciel // do not repost - keep header intact // Global Footer section
var howManyAcrossInRow=4;
function convertFromTag(encString) { var htmlEncResults='<table id="strikeback" width="100%">', tierwatch=''; if (encString.match(/\[none\](.*?)\[\/none\]/)) { htmlEncResults+='<tr><td class="RE_cell" vAlign="top" align="center"><br>' + RegExp.$1 + '<br><br></td>'; } else { var tiersplit=encString.split(/\[tier=\d+\]/); for (encTier=(tiersplit[0]=='' ? 1 : 0); encTier<tiersplit.length; encTier++) { var datasplit=tiersplit[encTier].split(/\[\/tier\]/)[0].split('[Name= '); if (encTier>1) htmlEncResults+='</tr>'; htmlEncResults+='<tr>'; for (d=1; d<datasplit.length; d++) { var monstersplit=datasplit[d].split('[/Name')[0].split(']['); htmlEncResults+='<td class="RE_cell" vAlign="top"><center class="RE_name">' + monstersplit[0] + '</center><br><br>'; for (m=1; m<monstersplit.length; m++) { var mparts=monstersplit[m].split(']')[0].split('= '); mlabel=mparts[0]; var partsplit=mparts[1].split(','); if (partsplit[0]) { htmlEncResults+= mlabel + '<ul>'; for (p=0; p<partsplit.length; p++) htmlEncResults+= '<li>' + partsplit[p] + '</li>'; htmlEncResults += '</ul><br>'; } } htmlEncResults += '</td>'; if (d>0 && d%howManyAcrossInRow==0 && d<datasplit.length-1) htmlEncResults+= '</tr><tr>'; } } } htmlEncResults +='</tr></table>'; return htmlEncResults; } if (pb_action.match(/display|recent|search2/)) { for (td=document.getElementsByTagName('td'),tt=0; tt<td.length; tt++) { if (td[tt].width=='80%' && td[tt].className.match(/windowbg/) && td[tt].innerHTML.match(/\[randomEncounter\]/)) { var getREstring=td[tt].innerHTML.match(/\[randomEncounter\](.*?)\[\/randomEncounter\]/i); var returnREhtml=convertFromTag(getREstring[1]); td[tt].innerHTML=td[tt].innerHTML.replace(/\[randomEncounter\](.*?)\[\/randomEncounter\]/i,returnREhtml); var sb=document.getElementById('strikeback'); sb.parentNode.parentNode.parentNode.parentNode.parentNode.style.width='100%'; sb.parentNode.parentNode.parentNode.parentNode.parentNode.className='RE_table'; sb.parentNode.parentNode.parentNode.parentNode.parentNode.rows[0].cells[0].className='RE_title'; sb.id=''; } } }
//--> </script>
the global footer part comes with some default CSS you can edit for how the encounter tables look.
[norunubbc]
|
|
killz4food
Not New Member
Posts: 12
killz4food said 0 great things
|
Post by killz4food on Sept 10, 2012 14:02:50 GMT -8
<script type="text/javascript"> <!-- // Random Encounters // v2.0 // by Wormopolis - [url]www.wormocodes.com[/url] // do not repost - keep header intact // board footer section
var RE_buttonImage="http://i197.photobucket.com/albums/aa250/WORMOPOLIS/randenc.gif"; var RE_disableButtonAfterOneClick=true; var RE_usersWhoCanUseButton="admin|user2|user3";
var encounterList=new Array(); /* EXAMPLE (keep this in here - it wont affect your results)
encounterList['Troll']={ Frequency: '2', //this controls how often this monster appears, lower number means more rare Min: '5', //minimum appearing Max: '10', //maximum appearing Stats: [['Strength','3','20'],['Agility','1','16'],['Hit Points','10','30']], //the stats of the monster, you can edit or add more // notice the array structure: [stat name, minimum of stat, maximum of stat]
// above is required to have // below are custom attributes of the monster
Weapons: [['Saw arm', 60%','(20-40)'],[Three finger claw','75%','(15-25)'],['Mace','50%','(30-50)']['Stung','20%','(infected)],100%] // structure: [name, chance, damage or note] // if you want a subset array, the structure is [[name1, chance, damage or note],[name2, chance, note],chance of subset] // so there is a 25% chance of getting club OR mace, and then a 70% chance of club and 30% for mace // subset percentages should add to 100%
Spells: [], // you can leave as an empty array or just omit completely
// below is if the monster appears with other monsters. it can be removed if you wish
};
*/
encounterList[Griever]={ Frequency: '8', Min: '5', Max: '10', Stats: [['Strength','3','20'],['Agility','1','16'],['Hit Points','10','30']], Weapons: [['Saw arm', 60%','(20-40)'],[Three finger claw','75%','(15-25)'],['Mace','50%','(30-50)']['Prodding Arm','100%','(5-15)'],100%], Spells: [], };
var percentageOfARandomEncounter='50%';
// no editing below is necessary unless you know what you are doing
function getEncounterList(type, min, max) { var encResults=[]; erescount=0; var totalAppearing=parseInt(min||encounterList[type].Min) + Math.floor(Math.random()*((max-min)||(parseInt(encounterList[type].Max) - parseInt(encounterList[type].Min)))); for (ta=0; ta<totalAppearing; ta++) { var encresStats=[]; encresStatcount=0; for (er=0; er<encounterList[type].Stats.length; er++) { encresAbscore=parseInt(encounterList[type].Stats[er][1]) + Math.floor(Math.random()*(encounterList[type].Stats[er][2] - encounterList[type].Stats[er][1])); encresStats[encresStatcount++]=encounterList[type].Stats[er][0] +': '+ encresAbscore; } encResults[erescount]=new Array(); dataArray=new Array(); dataArray[0]='Name= ' + type; dataArray[1]='Stats= ' + encresStats; datacount=2; for (part in encounterList[type]) { if (part!='Frequency' && part!='Min' && part!='Max' && part!='Company' && part!='Stats') { var encresParts=[]; encresPartscount=0; for (er=0; er<encounterList[type][part].length; er++) { if (encounterList[type][part][er] instanceof Array && encounterList[type][part][er][0] instanceof Array) { // inclusive group found. create randomresult array and choose one of the items var randomresult=[]; var rr=0; for (rrc=0; rrc<encounterList[type][part][er].length-1; rrc++) { //last element is chance current_rrN=encounterList[type][part][er][rrc][0]; current_rrC=encounterList[type][part][er][rrc][1]; current_rrD=encounterList[type][part][er][rrc][2]; for (rra=0; rra<parseInt(current_rrC); rra++) randomresult[rr++]=current_rrN + ' ' + current_rrD; } var rr_chance= encounterList[type][part][er][ encounterList[type][part][er].length-1 ]; rr_chance= parseInt(rr_chance) / 100.0; var rr_choice= randomresult[ Math.floor(Math.random() * 100) ]; if (Math.random() < rr_chance) encresParts[encresPartscount++] = rr_choice; } else { encresPartChance=parseInt(encounterList[type][part][er][1]) / 100.0; if (Math.random() <= encresPartChance) encresParts[encresPartscount++]=encounterList[type][part][er][0] +' '+ encounterList[type][part][er][2]; } } dataArray[datacount++]=part + '= ' + encresParts;
} } encResults[erescount][0]=encounterList[type].Frequency; encResults[erescount++][1]=dataArray; } if (encounterList[type].Company && !min) { for (ac=0; ac<encounterList[type].Company.length; ac++) { var accomptemp=getEncounterList(encounterList[type].Company[ac][0], encounterList[type].Company[ac][1], encounterList[type].Company[ac][2]); var accompchance=parseInt(encounterList[type].Company[ac][3]) / 100.0; if (Math.random() <= accompchance) encResults=encResults.concat(accomptemp); } } return encResults; }
function convertToTag(encArray) { var taggedEncResults='[randomEncounter]', tierwatch=''; for (encTier=0; encTier<encArray.length; encTier++) { if (encArray[encTier][0]!=tierwatch) { if (tierwatch!='') taggedEncResults+= '[/tier]'; tierwatch=encArray[encTier][0]; taggedEncResults+= '[tier=' + tierwatch + ']'; } for (i=0; i<encArray[encTier][1].length; i++ ) taggedEncResults+= '[' + encArray[encTier][1][i] + ']'; taggedEncResults+= '[/' + encArray[encTier][1][0] + ']'; } taggedEncResults+= '[/tier][/randomEncounter]'; return taggedEncResults; }
function clickEncounter(){ // get list of all encounters with weights and randomize var encList=[]; ecount=0; for (encname in encounterList) { for (ee=0; ee<parseInt(encounterList[encname].Frequency); ee++) encList[ecount++]=encname; } var chosenEnc=encList[Math.floor(Math.random()*ecount)]; var encounterResults=((Math.random())< (parseInt(percentageOfARandomEncounter)/100.0) ? getEncounterList(chosenEnc,0).sort() : whatToSayWhenNothingIsEncountered); var tmpstuff='[table][tr][td][center]Random Encounter![/center][/td][/tr][tr][td]'; if (typeof encounterResults == 'string') { tmpstuff+='[randomEncounter][none]' + encounterResults+ '[/none][/randomEncounter][/td][/tr][/table]'; } else { tmpstuff+=convertToTag(encounterResults) + '[/td][/tr][/table]'; } document.postForm.message.value+='\n' + tmpstuff;
}
if (document.postForm && pb_username.match(new RegExp('^('+RE_usersWhoCanUseButton+')$',''))) { var encmsg=document.postForm.message; var smrow=encmsg.parentNode.parentNode.parentNode.previousSibling; var rerow=smrow.cloneNode(true); rerow.firstChild.firstChild.innerHTML=''; rerow.firstChild.nextSibling.firstChild.innerHTML='<img src="' + RE_buttonImage + '" border="1" onclick="clickEncounter(); ' + (RE_disableButtonAfterOneClick ? 'this.onclick=\'\'; this.style.opacity=\'.5\'; this.style.filter = \'alpha(opacity=50\';' : '') + '">'; smrow.parentNode.insertBefore(rerow, smrow); }
// --> </script>
|
|
|
Post by Wormopolis on Sept 10, 2012 17:00:32 GMT -8
I would leave that first troll alone. it serves as a template for adding monsters and now that you have edited it will mess up future monsters because it was done wrong. it is commented out so it doesnt affect the code. but the one monster you added does. and it has some editing mistakes
encounterList[Griever]={ Frequency: '8', Min: '5', Max: '10', Stats: [['Strength','3','20'],['Agility','1','16'],['Hit Points','10','30']], Weapons: [['Saw arm', 60%','(20-40)'],[Three finger claw','75%','(15-25)'],['Mace','50%','(30-50)']['Prodding Arm','100%','(5-15)'],100%], Spells: [], };
Griever needs to be in quotes the 60% for saw arm needs to have a quote before it missing comma between mace and prodding arm arrays the final "100%" in the weapons array will cause an error because it doesnt match with any of the weapons
|
|
|
Post by Wormopolis on Sept 10, 2012 18:25:28 GMT -8
in the weapons array, you basically have an array of arrays. think of it like this:
Weapons: [ ['Saw arm', 60%','(20-40)'], [Three finger claw','75%','(15-25)'], ['Mace','50%','(30-50)'], ['Prodding Arm','100%','(5-15)'], 100% ]
see how the "100%" at the end doesnt look like the other lines?
|
|