Please login or register. Welcome to the Studio, guest!


Quick Links:


newBookmarkLockedFalling

chaoskreator

chaoskreator Avatar
Abandon all hope...

**
Official Member

49


March 2009
Chris, in response to what you said in the other thread about not seeing the array for it to update, I haven't built that part yet. I've been trying to get the user name to pass through the ubbc to the script, but have hit many hang-ups. I'm trying to go about it systematically and trying not to jump around to different aspects. That way, if something breaks, I know right where things went wrong. I'm going to go ahead and start on that soon, though. This variable passing is really ticking me off...


<script type="text/javascript">
var needlvl = "50";
var karmamod = "2.9";
var statmax = "999";
var health = "9";
var magic = "2";
var attack = "7";
var defense = "6";
var agility = "4";
var intelligence = "5";
var usermax = "(admin|username2|username3|username4|username5)";
var monmax = "999999";
var sign = "$";
var money = "10";
var TDs = document.getElementsByTagName("TD");
var maxusers = new RegExp("action=viewprofile&user="+usermax, "gi");
function Attack(a){
var attReg = /\[attack=(\w+)\]/gi;
var attk_string = TDs[a].innerHTML.match(attReg);
if(TDs[a].vAlign=="top" && TDs[a].colSpan=="3")
{
if(TDs[a].innerHTML.match(attReg))
{
TDs[a].innerHTML = TDs[a].innerHTML.replace(attReg,'You have attacked '+attk_string[1]);
Attack(a);
}
}
}
if(location.href.match(/action=(display|(pm|calendar)?view(profile)?)/i) || document.title.match(/Search\s|Preview/i))
{
for(a=0;a<TDs.length;a++)
{
if(TDs[a].width=="20%" && TDs[a].innerHTML.match(/Posts:/i))
{
if(TDs[a].getElementsByTagName("A")[0].href.match(maxusers) || TDs[a].getElementsByTagName("A")[1].href.match(maxusers))
{
var lvl2 = "999";
var hp = statmax;
var mp = statmax;
var attk = statmax;
var def = statmax;
var agl = statmax;
var itl = statmax;
var mon = monmax;
}
else
{
if(TDs[a].innerHTML.match(/Karma: (\d+)/i))
{
var karma = RegExp.$1;
}
if(TDs[a].innerHTML.match(/Posts: (\d+),(\d+)/i))
{
var posts = RegExp.$1 + RegExp.$2;
}
else if(TDs[a].innerHTML.match(/Posts: (\d+)/i))
{
var posts = RegExp.$1;
}
var lvl = parseInt(posts)/needlvl;
var rep = parseInt(karma*karmamod); if(rep<"999")
{
if(rep<"3")
{
var rep2 = "3";
}
else
{
for(karm=0;rep>karm;karm++)
{
var rep2 = parseInt(karm)+1;
}
}
}
else
{
var rep2 = "999";
}
if(lvl < "999")
{
if(lvl < "1")
{
var lvl2 = "1";
}
else
{
for(lev=0;lvl>lev;lev++)
{
var lvl2 = parseInt(lev)+1;
}
}
}
else
{
var lvl2 = "999";
}
var hp = parseInt(rep2)*health;
var mp = parseInt(lvl2)*magic;
var attk = parseInt(rep2)*attack;
var def = parseInt(lvl2)*defense;
var agl = parseInt(rep2)*agility;
var itl = parseInt(lvl2)*intelligence;
var mon = parseInt(posts)*money;
if(hp > statmax){ hp = statmax; }
if(mp > statmax){ mp = statmax; }
if(attk > statmax){ attk = statmax; }
if(def > statmax){ def = statmax; }
if(agl > statmax){ agl = statmax; }
if(itl > statmax){ itl = statmax; }
if(mon > monmax){ mon = monmax; }
}
var stat_menu = "<br /><table border='0' cellpadding='1' cellspacing='0' width='75%'>";
stat_menu += "<tr><td align='center' colspan='2'><a onclick='hideshowstats(this)'>";
stat_menu += "<b><u>Show RPG Stats</u></b></a></td></tr><tr style='display: none;'>";
stat_menu += "<td align='left'>Level: </td><td align='left'> "+lvl2+"</td></tr>";
stat_menu += "<tr style='display: none;'><td align='left'>HP: </td>";
stat_menu += "<td align='left'> "+hp+"</td></tr><tr style='display: none;'>";
stat_menu += "<td align='left'>MP: </td><td align='left'> "+mp+"</td></tr>";
stat_menu += "<tr style='display: none;'><td align='left'>Attack: </td>";
stat_menu += "<td align='left'> "+attk+"</td></tr><tr style='display: none;'>";
stat_menu += "<td align='left'>Defense: </td><td align='left'> "+def+"</td>";
stat_menu += "</tr><tr style='display: none;'><td align='left'>Agility: </td>";
stat_menu += "<td align='left'> "+agl+"</td></tr><tr style='display: none;'>";
stat_menu += "<td align='left'>Intelligence: </td><td align='left'> "+itl+"</td>";
stat_menu += "</tr><tr style='display: none;'><td align='left'>Money: </td>";
stat_menu += "<td align='left'> "+sign+mon+"</td></tr></table>";
TDs[a].innerHTML += stat_menu;
}
Attack(a);
}
if(document.postForm && document.postForm.color)
{
document.postForm.color.parentNode.innerHTML += '<a href=javascript:add("[attack=]","")><img src="http://demonguardians.110mb.com/images/attack.jpg" alt="Attack User" /></a>';
}
function hideshowstats(ext)
{
var n = ext.parentNode.parentNode.parentNode.rows;
if(n[1].style.display == "none"){
ext.innerHTML="<b><u>Hide RPG Stats</u></b>";
for(var b=1;b<n.length;b++){
n[b].style.display = "";
}
}
else
{
ext.innerHTML="<b><u>Show RPG Stats</u></b>";
for(var b=1;b<n.length;b++){
n[b].style.display = "none";
}
}
}
}
</script>

Do or do not. There is no try.


The Realms Beyond
Demon Guardians


Chris

Chris Avatar

******
Head Coder

19,519


June 2005
<script type="text/javascript">
var needlvl = "50";
var karmamod = "2.9";
var statmax = "999";
var health = "9";
var magic = "2";
var attack = "7";
var defense = "6";
var agility = "4";
var intelligence = "5";
var usermax = "(admin|username2|username3|username4|username5)";
var monmax = "999999";
var sign = "$";
var money = "10";
var TDs = document.getElementsByTagName("TD");
var maxusers = new RegExp("action=viewprofile&user="+usermax, "gi");
var attReg = /\[attack=(\w+)\]/gi;
function Attack(a){
if(TDs[a].vAlign=="top" && TDs[a].colSpan=="3")
{
if(TDs[a].innerHTML.match(attReg))
{
TDs[a].innerHTML = TDs[a].innerHTML.replace(attReg,'You have attacked '+RegExp.$1);
Attack(a);
}
}
}
if(location.href.match(/action=(display|(pm|calendar)?view(profile)?)/i) || document.title.match(/Search\s|Preview/i))
{
for(a=0;a<TDs.length;a++)
{
if(TDs[a].width=="20%" && TDs[a].innerHTML.match(/Posts:/i))
{
if(TDs[a].getElementsByTagName("A")[0].href.match(maxusers) || TDs[a].getElementsByTagName("A")[1].href.match(maxusers))
{
var lvl2 = "999";
var hp = statmax;
var mp = statmax;
var attk = statmax;
var def = statmax;
var agl = statmax;
var itl = statmax;
var mon = monmax;
}
else
{
if(TDs[a].innerHTML.match(/Karma: (\d+)/i))
{
var karma = RegExp.$1;
}
if(TDs[a].innerHTML.match(/Posts: (\d+),(\d+)/i))
{
var posts = RegExp.$1 + RegExp.$2;
}
else if(TDs[a].innerHTML.match(/Posts: (\d+)/i))
{
var posts = RegExp.$1;
}
var lvl = parseInt(posts)/needlvl;
var rep = parseInt(karma*karmamod);
if(rep<"999")
{
if(rep<"3")
{
var rep2 = "3";
}
else
{
for(karm=0;rep>karm;karm++)
{
var rep2 = parseInt(karm)+1;
}
}
}
else
{
var rep2 = "999";
}
if(lvl < "999")
{
if(lvl < "1")
{
var lvl2 = "1";
}
else
{
for(lev=0;lvl>lev;lev++)
{
var lvl2 = parseInt(lev)+1;
}
}
}
else
{
var lvl2 = "999";
}
var hp = parseInt(rep2)*health;
var mp = parseInt(lvl2)*magic;
var attk = parseInt(rep2)*attack;
var def = parseInt(lvl2)*defense;
var agl = parseInt(rep2)*agility;
var itl = parseInt(lvl2)*intelligence;
var mon = parseInt(posts)*money;
if(hp > statmax){ hp = statmax; }
if(mp > statmax){ mp = statmax; }
if(attk > statmax){ attk = statmax; }
if(def > statmax){ def = statmax; }
if(agl > statmax){ agl = statmax; }
if(itl > statmax){ itl = statmax; }
if(mon > monmax){ mon = monmax; }
}
var stat_menu = "<br /><table border='0' cellpadding='1' cellspacing='0' width='75%'>";
stat_menu += "<tr><td align='center' colspan='2'><a onclick='hideshowstats(this)'>";
stat_menu += "<b><u>Show RPG Stats</u></b></a></td></tr><tr style='display: none;'>";
stat_menu += "<td align='left'>Level: </td><td align='left'> "+lvl2+"</td></tr>";
stat_menu += "<tr style='display: none;'><td align='left'>HP: </td>";
stat_menu += "<td align='left'> "+hp+"</td></tr><tr style='display: none;'>";
stat_menu += "<td align='left'>MP: </td><td align='left'> "+mp+"</td></tr>";
stat_menu += "<tr style='display: none;'><td align='left'>Attack: </td>";
stat_menu += "<td align='left'> "+attk+"</td></tr><tr style='display: none;'>";
stat_menu += "<td align='left'>Defense: </td><td align='left'> "+def+"</td>";
stat_menu += "</tr><tr style='display: none;'><td align='left'>Agility: </td>";
stat_menu += "<td align='left'> "+agl+"</td></tr><tr style='display: none;'>";
stat_menu += "<td align='left'>Intelligence: </td><td align='left'> "+itl+"</td>";
stat_menu += "</tr><tr style='display: none;'><td align='left'>Money: </td>";
stat_menu += "<td align='left'> "+sign+mon+"</td></tr></table>";
TDs[a].innerHTML += stat_menu;
}
Attack(a);
}
if(document.postForm && document.postForm.color)
{
document.postForm.color.parentNode.innerHTML += '<a href=javascript:add("[attack=]","")><img src="http://demonguardians.110mb.com/images/attack.jpg" alt="Attack User" /></a>';
}
function hideshowstats(ext)
{
var n = ext.parentNode.parentNode.parentNode.rows;
if(n[1].style.display == "none"){
ext.innerHTML="<b><u>Hide RPG Stats</u></b>";
for(var b=1;b<n.length;b++){
n[b].style.display = "";
}
}
else
{
ext.innerHTML="<b><u>Show RPG Stats</u></b>";
for(var b=1;b<n.length;b++){
n[b].style.display = "none";
}
}
}
}
</script>


I did a few quick mods around the Attack function and now it -should- work how you want. :P Hopefully.

chaoskreator

chaoskreator Avatar
Abandon all hope...

**
Official Member

49


March 2009
That's so funny. I came up with this code for a fix:

<script type="text/javascript">
var needlvl = "50";
var minkarm = "3";
var karmamod = "2.9";
var statmax = "999";
var health = "9";
var magic = "2";
var attack = "7";
var defense = "6";
var agility = "4";
var intelligence = "5";
var usermax = "(admin|username2|username3|username4|username5)";
var monmax = "999999";
var sign = "$";
var money = "10";

var TDs = document.getElementsByTagName("TD");
var maxusers = new RegExp("action=viewprofile&user="+usermax, "gi");

function Attack(a)
{
if(attReg = TDs[a].innerHTML.match(/\[attack=([^<]+)\]/gi))
this.attk_string = RegExp.$1;
if(TDs[a].vAlign=="top" && TDs[a].colSpan=="3")
{
if(TDs[a].innerHTML.match(attReg))
{
TDs[a].innerHTML = TDs[a].innerHTML.replace(attReg,'You have attacked '+attk_string);
Attack(a);
}
}
}

if(location.href.match(/action=(display|(pm|calendar)?view(profile)?)/i) || document.title.match(/Search\s|Preview/i))
{
for(a=0;a<TDs.length;a++)
{
if(TDs[a].width=="20%" && TDs[a].innerHTML.match(/Posts:/i))
{
if(TDs[a].getElementsByTagName("A")[0].href.match(maxusers) || TDs[a].getElementsByTagName("A")[1].href.match(maxusers))
{
var lvl2 = "999";
var hp = statmax;
var mp = statmax;
var attk = statmax;
var def = statmax;
var agl = statmax;
var itl = statmax;
var mon = monmax;
}
else
{
if(TDs[a].innerHTML.match(/Karma: (\d+)/i))
{
var karma = RegExp.$1;
}
if(TDs[a].innerHTML.match(/Posts: (\d+),(\d+)/i))
{
var posts = RegExp.$1 + RegExp.$2;
}
else if(TDs[a].innerHTML.match(/Posts: (\d+)/i))
{
var posts = RegExp.$1;
}
var lvl = parseInt(posts)/needlvl;
var rep = parseInt(karma*karmamod);
if(rep<"999")
{
if(rep<"minkarm")
{
var rep2 = "minkarm";
}
else
{
for(karm=0;rep>karm;karm++)
{
var rep2 = parseInt(karm)+1;
}
}
}
else
{
var rep2 = "999";
}
if(lvl < "999")
{
if(lvl < "1")
{
var lvl2 = "1";
}
else
{
for(lev=0;lvl>lev;lev++)
{
var lvl2 = parseInt(lev)+1;
}
}
}
else
{
var lvl2 = "999";
}
var hp = parseInt(rep2)*health;
var mp = parseInt(lvl2)*magic;
var attk = parseInt(rep2)*attack;
var def = parseInt(lvl2)*defense;
var agl = parseInt(rep2)*agility;
var itl = parseInt(lvl2)*intelligence;
var mon = parseInt(posts)*money;
if(hp > statmax){ hp = statmax; }
if(mp > statmax){ mp = statmax; }
if(attk > statmax){ attk = statmax; }
if(def > statmax){ def = statmax; }
if(agl > statmax){ agl = statmax; }
if(itl > statmax){ itl = statmax; }
if(mon > monmax){ mon = monmax; }
}
var stat_menu = "<br /><table border='0' cellpadding='1' cellspacing='0' width='75%'>";
stat_menu += "<tr><td align='center' colspan='2'><a onclick='hideshowstats(this)'>";
stat_menu += "<b><u>Show RPG Stats</u></b></a></td></tr><tr style='display: none;'>";
stat_menu += "<td align='left'>Level: </td><td align='left'> "+lvl2+"</td></tr>";
stat_menu += "<tr style='display: none;'><td align='left'>HP: </td>";
stat_menu += "<td align='left'> "+hp+"</td></tr><tr style='display: none;'>";
stat_menu += "<td align='left'>MP: </td><td align='left'> "+mp+"</td></tr>";
stat_menu += "<tr style='display: none;'><td align='left'>Attack: </td>";
stat_menu += "<td align='left'> "+attk+"</td></tr><tr style='display: none;'>";
stat_menu += "<td align='left'>Defense: </td><td align='left'> "+def+"</td>";
stat_menu += "</tr><tr style='display: none;'><td align='left'>Agility: </td>";
stat_menu += "<td align='left'> "+agl+"</td></tr><tr style='display: none;'>";
stat_menu += "<td align='left'>Intelligence: </td><td align='left'> "+itl+"</td>";
stat_menu += "</tr><tr style='display: none;'><td align='left'>Money: </td>";
stat_menu += "<td align='left'> "+sign+mon+"</td></tr></table>";
TDs[a].innerHTML += stat_menu;
}
Attack(a);
}
if(document.postForm && document.postForm.color)
{
document.postForm.color.parentNode.innerHTML += '<a href=javascript:add("[attack=]","")><img src="http://demonguardians.110mb.com/images/attack.jpg" alt="Attack User" /></a>';
}
function hideshowstats(ext)
{
var n = ext.parentNode.parentNode.parentNode.rows;
if(n[1].style.display == "none")
{
ext.innerHTML="<b><u>Hide RPG Stats</u></b>";
for(var b=1;b<n.length;b++)
{
n[b].style.display = "";
}
}
else
{
ext.innerHTML="<b><u>Show RPG Stats</u></b>";
for(var b=1;b<n.length;b++)
{
n[b].style.display = "none";
}
}
}
}
</script>



EDIT: Both of our codes broke the UBBC button, however. LOL


Last Edit: Apr 11, 2009 19:53:06 GMT by chaoskreator
Do or do not. There is no try.


The Realms Beyond
Demon Guardians


Chris

Chris Avatar

******
Head Coder

19,519


June 2005
Haha. My bad. What's broken about it anyway? Just not adding to the textarea or just now showing the button?

chaoskreator

chaoskreator Avatar
Abandon all hope...

**
Official Member

49


March 2009
Not showing the button. I'm working on getting the rest of the code in place now. I should have most of it done later. I'll post an update.


EDIT: This is what I've got so far, but it's broke. I'm going to go through and start fixing things and adding the rest later. I have to take a break. LOL


<script type="text/javascript">
// Editable Options begin
var needlvl = "50";
var minkarm = "3";
var karmamod = "2.9";
var statmax = "9999";
var health = "9";
var magic = "2";
var attack = "7";
var defense = "6";
var agility = "4";
var intelligence = "5";
var usermax = "(admin|username2|username3|username4|username5)";
var monmax = "999999";
var sign = "$";
var money = "10";
// Editable Options end

// Grab our table and super-user information
var TDs = document.getElementsByTagName("TD");
var maxusers = new RegExp("action=viewprofile&user="+usermax, "gi");

// The main attack function
function Attack(a)
{
// Our RegExp's
var attReg = TDs[a].innerHTML.match(/\[attack\]([^<]+)\[\/attack\]/gi);
var usrReg = TDs[a].innerHTML.match(/Hey, ([^<]+), you have/gi);
var hpReg = TDs[a].innerHTML.match(/HP: (\d+)/gi);
var defReg = TDs[a].innerHTML.match(/Defense: (\d+)/gi);
var aglReg = TDs[a].innerHTML.match(/Agility: (\d+)/gi);
// End RegExp's

if(attReg)
this.attkd_usr = RegExp.$1;
if(usrReg)
this.attacker = RegExp.$1;
 
// grab the attacked user's stats
if(TDs[a].width=="20%" && TDs[a].innerHTML.match(/Posts:/i) && TDs[a].innerHTML.match(attkd_usr))
{
if(defReg)
this.usr_def = RegExp.$1;
if(aglReg)
this.usr_agl = RegExp.$1;
}

// grab the attacking user's stats
if(TDs[a].width=="20%" && TDs[a].innerHTML.match(/Posts:/i) && TDs[a].innerHTML.match(attacker))
{
if(attkReg)
this.attkr_attk = RegExp.$1;
if(intReg)
this.attkr_int = RegExp.$1;
}

// Calculate damage
var attk_success = parseInt(attkr_int/usr_agl);
var attk_percentage = parseInt(attkr_attk/usr_def);
var damage = attk_success*attk_percentage;
damage = parseInt(damage);

// display all of the information, replacing the UBBC
if(TDs[a].vAlign=="top" && TDs[a].colSpan=="3")
{
if(TDs[a].innerHTML.match(attReg))
{
TDs[a].innerHTML = TDs[a].innerHTML.replace(attReg,''+attacker+', you have attacked '+attkd_usr+' for '+damage+' damage.');
Attack(a);
}
}
}

if(location.href.match(/action=(display|(pm|calendar)?view(profile)?)/i) || document.title.match(/Search\s|Preview/i))
{
for(a=0;a<TDs.length;a++)
{
if(TDs[a].width=="20%" && TDs[a].innerHTML.match(/Posts:/i))
{
// Set the super users' stats
if(TDs[a].getElementsByTagName("A")[0].href.match(maxusers) || TDs[a].getElementsByTagName("A")[1].href.match(maxusers))
{
var lvl2 = "999";
var hp = statmax;
var mp = statmax;
var attk = statmax;
var def = statmax;
var agl = statmax;
var itl = statmax;
var mon = monmax;
}
else
{
// Grab user information for stats calculation
if(TDs[a].innerHTML.match(/Karma: (\d+)/i))
{
var karma = RegExp.$1;
}
if(TDs[a].innerHTML.match(/Posts: (\d+),(\d+)/i))
{
var posts = RegExp.$1 + RegExp.$2;
}
else if(TDs[a].innerHTML.match(/Posts: (\d+)/i))
{
var posts = RegExp.$1;
}
// Stats calculations
var lvl = parseInt(posts)/needlvl;
var rep = parseInt(karma*karmamod);
if(rep<"999")
{
if(rep<"minkarm")
{
var rep2 = "minkarm";
}
else
{
for(karm=0;rep>karm;karm++)
{
var rep2 = parseInt(karm)+1;
}
}
}
else
{
var rep2 = "999";
}
if(lvl < "999")
{
if(lvl < "1")
{
var lvl2 = "1";
}
else
{
for(lev=0;lvl>lev;lev++)
{
var lvl2 = parseInt(lev)+1;
}
}
}
else
{
var lvl2 = "999";
}
var hp = parseInt(rep2)*health;
var mp = parseInt(lvl2)*magic;
var attk = parseInt(rep2)*attack;
var def = parseInt(lvl2)*defense;
var agl = parseInt(rep2)*agility;
var itl = parseInt(lvl2)*intelligence;
var mon = parseInt(posts)*money;
if(hp > statmax){ hp = statmax; }
if(mp > statmax){ mp = statmax; }
if(attk > statmax){ attk = statmax; }
if(def > statmax){ def = statmax; }
if(agl > statmax){ agl = statmax; }
if(itl > statmax){ itl = statmax; }
if(mon > monmax){ mon = monmax; }
}

// display stat container
var stat_menu = "<br /><table border='0' cellpadding='1' cellspacing='0' width='75%'>";
stat_menu += "<tr><td align='center' colspan='2'><a onclick='hideshowstats(this)'>";
stat_menu += "<b><u>Show RPG Stats</u></b></a></td></tr><tr style='display: none;'>";
stat_menu += "<td align='left'>Level: </td><td align='left'> "+lvl2+"</td></tr>";
stat_menu += "<tr style='display: none;'><td align='left'>HP: </td>";
stat_menu += "<td align='left'> "+hp+"</td></tr><tr style='display: none;'>";
stat_menu += "<td align='left'>MP: </td><td align='left'> "+mp+"</td></tr>";
stat_menu += "<tr style='display: none;'><td align='left'>Attack: </td>";
stat_menu += "<td align='left'> "+attk+"</td></tr><tr style='display: none;'>";
stat_menu += "<td align='left'>Defense: </td><td align='left'> "+def+"</td>";
stat_menu += "</tr><tr style='display: none;'><td align='left'>Agility: </td>";
stat_menu += "<td align='left'> "+agl+"</td></tr><tr style='display: none;'>";
stat_menu += "<td align='left'>Intelligence: </td><td align='left'> "+itl+"</td>";
stat_menu += "</tr><tr style='display: none;'><td align='left'>Money: </td>";
stat_menu += "<td align='left'> "+sign+mon+"</td></tr></table>";
TDs[a].innerHTML += stat_menu;
}
Attack(a);
}

// code for UBBC
if(document.postForm && document.postForm.color)
{
document.postForm.color.parentNode.innerHTML += '<a href=javascript:add("[attack][/attack]","")><img src="http://demonguardians.110mb.com/images/attack.jpg" alt="Attack User" /></a>';
}

// hide or show stats
function hideshowstats(ext)
{
var n = ext.parentNode.parentNode.parentNode.rows;
if(n[1].style.display == "none")
{
ext.innerHTML="<b><u>Hide RPG Stats</u></b>";
for(var b=1;b<n.length;b++)
{
n[b].style.display = "";
}
}
else
{
ext.innerHTML="<b><u>Show RPG Stats</u></b>";
for(var b=1;b<n.length;b++)
{
n[b].style.display = "none";
}
}
}
}
</script>



Last Edit: Apr 12, 2009 4:20:58 GMT by chaoskreator
Do or do not. There is no try.


The Realms Beyond
Demon Guardians


Chris

Chris Avatar

******
Head Coder

19,519


June 2005
Undo the change I made in the other thread... that may have been what broke it. =/

chaoskreator

chaoskreator Avatar
Abandon all hope...

**
Official Member

49


March 2009
It's not that. I'm not sure what the problem is. I've been too sick to even really bother with it.
Do or do not. There is no try.


The Realms Beyond
Demon Guardians


chaoskreator

chaoskreator Avatar
Abandon all hope...

**
Official Member

49


March 2009
Okay, so I made a few minor changes and tested the code out with JSLint (which absolutely hates me, by the way).

Here's the code:
// Editable Options begin
var needlvl = "50";
var minkarm = "3";
var karmamod = "2.9";
var statmax = "9999";
var health = "9";
var magic = "2";
var attack = "7";
var defense = "6";
var agility = "4";
var intelligence = "5";
var usermax = "(admin|username2|username3|username4|username5)";
var monmax = "999999";
var sign = "$";
var money = "10";
// Editable Options end

// Grab our table and super-user information
var TDs = document.getElementsByTagName("TD");
var maxusers = new RegExp("action=viewprofile&user="+usermax, "gi");

// The main attack function
function Attack(a)
{
// Our RegExp's
var attReg = TDs[a].innerHTML.match(/\[attack=([^<]+)\]/gi);
var usrReg = TDs[a].innerHTML.match(/Hey, ([^<]+), you have/gi);
var hpReg = TDs[a].innerHTML.match(/HP: (\d+)/gi);
var defReg = TDs[a].innerHTML.match(/Defense: (\d+)/gi);
var aglReg = TDs[a].innerHTML.match(/Agility: (\d+)/gi);
// End RegExp's

if(attReg){
this.attkd_usr = RegExp.$1;}
if(usrReg){
this.attacker = RegExp.$1;}

// grab the attacked user's stats
if(TDs[a].width=="20%" && TDs[a].innerHTML.match(/Posts:/i) && TDs[a].innerHTML.match(attkd_usr))
{
if(defReg){
this.usr_def = RegExp.$1;}
if(aglReg){
this.usr_agl = RegExp.$1;}
}

// grab the attacking user's stats
if(TDs[a].width=="20%" && TDs[a].innerHTML.match(/Posts:/i) && TDs[a].innerHTML.match(attacker))
{
if(attkReg){
this.attkr_attk = RegExp.$1;}
if(intReg){
this.attkr_int = RegExp.$1;}
}

// Calculate damage
var attk_success = parseInt(attkr_int/usr_agl, 10);
var attk_percentage = parseInt(attkr_attk/usr_def, 10);
var damage = attk_success*attk_percentage;
damage = parseInt(damage, 10);

// display all of the information, replacing the UBBC
if(TDs[a].vAlign=="top" && TDs[a].colSpan=="3")
{
if(TDs[a].innerHTML.match(attReg))
{
TDs[a].innerHTML = TDs[a].innerHTML.replace(attReg,''+attacker+', you have attacked '+attkd_usr+' for '+damage+' damage.');
Attack(a);
}
}
}

if(location.href.match(/action=(display|(pm|calendar)?view(profile)?)/i) || document.title.match(/Search\s|Preview/i))
{
for(a=0;a<TDs.length;a++)
{
if(TDs[a].width=="20%" && TDs[a].innerHTML.match(/Posts:/i))
{
// Set the super users' stats
if(TDs[a].getElementsByTagName("A")[0].href.match(maxusers) || TDs[a].getElementsByTagName("A")[1].href.match(maxusers))
{
var lvl2 = "999";
var hp = statmax;
var mp = statmax;
var attk = statmax;
var def = statmax;
var agl = statmax;
var itl = statmax;
var mon = monmax;
}
else
{
// Grab user information for stats calculation
if(TDs[a].innerHTML.match(/Karma: (\d+)/i))
{
var karma = RegExp.$1;
}
if(TDs[a].innerHTML.match(/Posts: (\d+),(\d+)/i))
{
var posts = RegExp.$1 + RegExp.$2;
}
else if(TDs[a].innerHTML.match(/Posts: (\d+)/i))
{
var posts = RegExp.$1;
}
// Stats calculations
var lvl = parseInt(posts)/needlvl;
var rep = parseInt(karma*karmamod);
if(rep<"999")
{
if(rep<"minkarm")
{
var rep2 = "minkarm";
}
else
{
for(karm=0;rep>karm;karm++)
{
var rep2 = parseInt(karm)+1;
}
}
}
else
{
var rep2 = "999";
}
if(lvl < "999")
{
if(lvl < "1")
{
var lvl2 = "1";
}
else
{
for(lev=0;lvl>lev;lev++)
{
var lvl2 = parseInt(lev)+1;
}
}
}
else
{
var lvl2 = "999";
}
var hp = parseInt(rep2)*health;
var mp = parseInt(lvl2)*magic;
var attk = parseInt(rep2)*attack;
var def = parseInt(lvl2)*defense;
var agl = parseInt(rep2)*agility;
var itl = parseInt(lvl2)*intelligence;
var mon = parseInt(posts)*money;
if(hp > statmax){ hp = statmax; }
if(mp > statmax){ mp = statmax; }
if(attk > statmax){ attk = statmax; }
if(def > statmax){ def = statmax; }
if(agl > statmax){ agl = statmax; }
if(itl > statmax){ itl = statmax; }
if(mon > monmax){ mon = monmax; }
}

// display stat container
var stat_menu = "<br /><table border='0' cellpadding='1' cellspacing='0' width='75%'>";
stat_menu += "<tr><td align='center' colspan='2'><a onclick='hideshowstats(this)'>";
stat_menu += "<b><u>Show RPG Stats</u></b></a></td></tr><tr style='display: none;'>";
stat_menu += "<td align='left'>Level: </td><td align='left'> "+lvl2+"</td></tr>";
stat_menu += "<tr style='display: none;'><td align='left'>HP: </td>";
stat_menu += "<td align='left'> "+hp+"</td></tr><tr style='display: none;'>";
stat_menu += "<td align='left'>MP: </td><td align='left'> "+mp+"</td></tr>";
stat_menu += "<tr style='display: none;'><td align='left'>Attack: </td>";
stat_menu += "<td align='left'> "+attk+"</td></tr><tr style='display: none;'>";
stat_menu += "<td align='left'>Defense: </td><td align='left'> "+def+"</td>";
stat_menu += "</tr><tr style='display: none;'><td align='left'>Agility: </td>";
stat_menu += "<td align='left'> "+agl+"</td></tr><tr style='display: none;'>";
stat_menu += "<td align='left'>Intelligence: </td><td align='left'> "+itl+"</td>";
stat_menu += "</tr><tr style='display: none;'><td align='left'>Money: </td>";
stat_menu += "<td align='left'> "+sign+mon+"</td></tr></table>";
TDs[a].innerHTML += stat_menu;
}
Attack(a);
}

// code for UBBC
if(document.postForm && document.postForm.color)
{
document.postForm.color.parentNode.innerHTML += '<a href=javascript:add("[attack=]","")><img src="http://demonguardians.110mb.com/images/attack.jpg" alt="Attack User" /></a>';
}

// hide or show stats
function hideshowstats(ext)
{
var n = ext.parentNode.parentNode.parentNode.rows;
if(n[1].style.display == "none")
{
ext.innerHTML="<b><u>Hide RPG Stats</u></b>";
for(var b=1;b<n.length;b++)
{
n[b].style.display = "";
}
}
else
{
ext.innerHTML="<b><u>Show RPG Stats</u></b>";
for(var b=1;b<n.length;b++)
{
n[b].style.display = "none";
}
}
}
}


And here's what JSLint spit back at me. I am so confused by some of these errors... My JavaScript debugger says there are no errors.

Error:

Implied global: a 75 77 80 94 98 102 177 179, attacker 48, attkReg 50, attkd_usr 39, attkr_attk 58, attkr_int 57, document 19 73 183 185, intReg 52, karm 117 119, lev 135 137, location 73, usr_agl 57, usr_def 58

Problem at line 104 character 31: 'posts' is already defined.

var posts = RegExp.$1;

Problem at line 107 character 27: Missing radix parameter.

var lvl = parseInt(posts)/needlvl;

Problem at line 108 character 27: Missing radix parameter.

var rep = parseInt(karma*karmamod);

Problem at line 119 character 38: 'rep2' is already defined.

var rep2 = parseInt(karm)+1;

Problem at line 119 character 40: Missing radix parameter.

var rep2 = parseInt(karm)+1;

Problem at line 125 character 30: 'rep2' is already defined.

var rep2 = "999";

Problem at line 131 character 34: 'lvl2' is already defined.

var lvl2 = "1";

Problem at line 137 character 38: 'lvl2' is already defined.

var lvl2 = parseInt(lev)+1;

Problem at line 137 character 40: Missing radix parameter.

var lvl2 = parseInt(lev)+1;

Problem at line 143 character 30: 'lvl2' is already defined.

var lvl2 = "999";

Problem at line 145 character 24: 'hp' is already defined.

var hp = parseInt(rep2)*health;

Problem at line 145 character 26: Missing radix parameter.

var hp = parseInt(rep2)*health;

Problem at line 146 character 24: 'mp' is already defined.

var mp = parseInt(lvl2)*magic;

Problem at line 146 character 26: Missing radix parameter.

var mp = parseInt(lvl2)*magic;

Problem at line 147 character 26: 'attk' is already defined.

var attk = parseInt(rep2)*attack;

Problem at line 147 character 28: Missing radix parameter.

var attk = parseInt(rep2)*attack;

Problem at line 148 character 25: 'def' is already defined.

var def = parseInt(lvl2)*defense;

Problem at line 148 character 27: Missing radix parameter.

var def = parseInt(lvl2)*defense;

Problem at line 149 character 25: 'agl' is already defined.

var agl = parseInt(rep2)*agility;

Problem at line 149 character 27: Missing radix parameter.

var agl = parseInt(rep2)*agility;

Problem at line 150 character 25: 'itl' is already defined.

var itl = parseInt(lvl2)*intelligence;

Problem at line 150 character 27: Missing radix parameter.

var itl = parseInt(lvl2)*intelligence;

Problem at line 151 character 25: 'mon' is already defined.

var mon = parseInt(posts)*money;

Problem at line 151 character 27: Missing radix parameter.

var mon = parseInt(posts)*money;

Problem at line 189 character 5: Function statements cannot be placed in blocks. Use a function expression or move the statement to the top of the outer function.

function hideshowstats(ext)

Problem at line 203 character 22: 'b' is already defined.

for(var b=1;b<n.length;b++)



Global Attack, TDs, agility, agl, attack, attk, def, defense, health, hideshowstats, hp, intelligence, itl, karma, karmamod, lvl, lvl2, magic, maxusers, minkarm, mon, money, monmax, mp, needlvl, posts, rep, rep2, sign, stat_menu, statmax, usermax

23 Attack(a)
Variable aglReg, attReg, attk_percentage, attk_success, damage, defReg, usrReg
Outer TDs
Global RegExp, attacker, attkReg, attkd_usr, attkr_attk, attkr_int, intReg, parseInt, usr_agl, usr_def
Unused hpReg

189 hideshowstats(ext)
Variable b, n

/*members $1, $2, attacker, attkd_usr, attkr_attk, attkr_int, colSpan,
   color, display, getElementsByTagName, href, innerHTML, length, match,
   parentNode, postForm, replace, rows, style, title, usr_agl, usr_def,
   vAlign, width
*/



Last Edit: Apr 14, 2009 20:44:55 GMT by chaoskreator
Do or do not. There is no try.


The Realms Beyond
Demon Guardians


Chris

Chris Avatar

******
Head Coder

19,519


June 2005
There are no errors. Ignore it. =/ Your program is assuming that you want to use coding standards that I consider BS. Basically, it's telling you that you declared variables global when you shouldn't have and that you're redefining the hp/mp/etc. variable whenever you update it.

chaoskreator

chaoskreator Avatar
Abandon all hope...

**
Official Member

49


March 2009
Okay, I get it. JSLint is retarded. Anyway, I actually have some free time today, so I might actually update some code. lol
Do or do not. There is no try.


The Realms Beyond
Demon Guardians


Aaron

Aaron Avatar
Bad Wolf

****
Dedicated Studio Member

859


November 2006
Quite the opposite of "retarded," actually; they just aren't issues you need to worry about.


Last Edit: Apr 25, 2009 20:14:04 GMT by Aaron

chaoskreator

chaoskreator Avatar
Abandon all hope...

**
Official Member

49


March 2009
Well, it confused me and told me things I didn't like. It's retarded to me. That's not saying much, though... I'm working on a project that's far beyond my JavaScripting abilities. ;)
Do or do not. There is no try.


The Realms Beyond
Demon Guardians


chaoskreator

chaoskreator Avatar
Abandon all hope...

**
Official Member

49


March 2009
So, I'm trying an alternate idea...

EDIT: I removed the code that I was working on and had posted here because it was absolute crap. I have a new piece I'm working on that I completely re-did.
Now, I have to figure out a good mathematical system to modify the stats. Can anyone point me in the direction of some good information about the mathematical functions of JavaScript?

I'll post the updated code later.


Last Edit: Apr 27, 2009 1:58:24 GMT by chaoskreator
Do or do not. There is no try.


The Realms Beyond
Demon Guardians


chaoskreator

chaoskreator Avatar
Abandon all hope...

**
Official Member

49


March 2009

<script type="text/javascript">
<!--
var needlvl = "50";
var karmamod = "2.9";
var minkarm = "3";
var statmax = "999";
var health = "9";
var magic = "2";
var attack = "7";
var defense = "6";
var agility = "4";
var intelligence = "5";
var usermax = "(admin|username2|username3|username4|username5)";
var monmax = "999999";
var sign = "$";
var money = "10";
var TDs = document.getElementsByTagName("TD");
var maxusers = new RegExp("action=viewprofile&user="+usermax, "gi");

function hideshowstats(ext)
{
var n = ext.parentNode.parentNode.parentNode.rows;
if(n[1].style.display == "none")
{
ext.innerHTML="<b><u>Hide RPG Stats</u></b>";
for(var b=1;b<n.length;b++)
{
n[b].style.display = "";
}
}
else
{
ext.innerHTML="<b><u>Show RPG Stats</u></b>";
for(var b=1;b<n.length;b++)
{
n[b].style.display = "none";
}
}
}

function Attack(a)
{
if(TDs[a].width=="20%" && TDs[a].innerHTML.match(/Posts:/i))
{
if(TDs[a].getElementsByTagName("A")[0].href.match(maxusers) || TDs[a].getElementsByTagName("A")[1].href.match(maxusers))
{
var lvl2 = "999";
var hp = statmax;
var mp = statmax;
var attk = statmax;
var def = statmax;
var agl = statmax;
var itl = statmax;
var mon = monmax;
}
else
{
if(TDs[a].innerHTML.match(/Karma: (\d+)/i))
{
var karma = RegExp.$1;
}
if(TDs[a].innerHTML.match(/Posts: (\d+),(\d+)/i))
{
var posts = RegExp.$1 + RegExp.$2;
}
else if(TDs[a].innerHTML.match(/Posts: (\d+)/i))
{
var posts = RegExp.$1;
}
var lvl = parseInt(posts)/needlvl;
var rep = parseInt(karma*karmamod);
if(rep<"999")
{
if(rep<minkarm)
{
var rep2 = minkarm;
}
else
{
for(karm=0;rep>karm;karm++)
{
var rep2 = parseInt(karm)+1;
}
}
}
else
{
var rep2 = "999";
}
if(lvl < "999")
{
if(lvl < "1")
{
var lvl2 = "1";
}
else
{
for(lev=0;lvl>lev;lev++)
{
var lvl2 = parseInt(lev)+1;
}
}
}
else
{
var lvl2 = "999";
}
var hp = parseInt(rep2)*health;
var mp = parseInt(lvl2)*magic;
var attk = parseInt(rep2)*attack;
var def = parseInt(lvl2)*defense;
var agl = parseInt(rep2)*agility;
var itl = parseInt(lvl2)*intelligence;
var mon = parseInt(posts)*money;
if(hp > statmax){ hp = statmax; }
if(mp > statmax){ mp = statmax; }
if(attk > statmax){ attk = statmax; }
if(def > statmax){ def = statmax; }
if(agl > statmax){ agl = statmax; }
if(itl > statmax){ itl = statmax; }
if(mon > monmax){ mon = monmax; }
}
var stat_menu = "<br /><table border='0' cellpadding='1' cellspacing='0' width='75%'>";
stat_menu += "<tr><td align='center' colspan='2'><a onclick='hideshowstats(this)'>";
stat_menu += "<b><u>Show RPG Stats</u></b></a></td></tr>";
stat_menu += "<tr style='display: none;'><td align='left'>Level: "+lvl2+"</td></tr>";
stat_menu += "<tr style='display: none;'><td align='left'>HP: "+hp+"</td></tr>";
stat_menu += "<tr style='display: none;'><td align='left'>MP: "+mp+"</td></tr>";
stat_menu += "<tr style='display: none;'><td align='left'>Attack:  "+attk+"</td></tr>";
stat_menu += "<tr style='display: none;'><td align='left'>Defense: "+def+"</td></tr>";
stat_menu += "<tr style='display: none;'><td align='left'>Agility: "+agl+"</td></tr>";
stat_menu += "<tr style='display: none;'><td align='left'>Intelligence: "+itl+"</td></tr>";
stat_menu += "<tr style='display: none;'><td align='left'>Money: "+sign+mon+"</td></tr></table>";
TDs[a].innerHTML += stat_menu;
}

if(TDs[a].innerHTML.match(/\[attack\]([^<]+)\[\/attack\]\[attkr\]([^<]+)\[\/attkr\]/gi))
{

if(TDs[a].colSpan=="3" && TDs[a].vAlign=="top")
{
var usr=RegExp.$1;
var attkr=RegExp.$2;

if(TDs[a].width=="20%" && TDs[a].innerHTML.match(/Posts:/i) && TDs[a].innerHTML.match(usr))
{
if(TDs[a].innerHTML.match(/Defense: (\d+)/))
{
var usrDef=RexExp.$1;
}
}

TDs[a].innerHTML=TDs[a].innerHTML.replace(/\[attack\]([^<]+)\[\/attack\]\[attkr\]([^<]+)\[\/attkr\]/, attkr+', you have attacked '+usr+', who has Defense of '+usrDef);
}
}
}

if(this.location.href.match(/action=(display|(pm|calendar)?view(profile)?)/i) || document.title.match(/Search\s|Preview/i) && (!document.postForm && !document.postForm.color))
{
for(a=0;a<TDs.length;a++)
{
Attack(a);
}
}
if(document.postForm && document.postForm.color)
{
for(a=0;a<TDs.length;a++)
{
if(attkrReg = TDs[a].innerHTML.match(/Hey, ([^<]+), you have/gi))
{
var attkr = RegExp.$1;
}
}
document.postForm.color.parentNode.innerHTML += '<a href=javascript:add("[attack][/attack][attkr]'+attkr+'[/attkr]","")><img src="http://demonguardians.110mb.com/images/attack.jpg" alt="Attack User" /></a>';
}
//-->
</script>

TDs[a].innerHTML=TDs[a].innerHTML.replace(/\[attack\]([^<]+)\[\/attack\]\[attkr\]([^<]+)\[\/attkr\]/, attkr+', you have attacked '+usr+', who has Defense of '+usrDef)
}
}
}

if(this.location.href.match(/action=(display|(pm|calendar)?view(profile)?)/i) || document.title.match(/Search\s|Preview/i) && (!document.postForm && !document.postForm.color))
{
for(a=0;a<TDs.length;a++)
{
Attack(a);
}
}
else if(document.postForm && document.postForm.color)
{
for(a=0;a<TDs.length;a++)
{
if(attkrReg = TDs[a].innerHTML.match(/Hey, ([^<]+), you have/gi))
{
var attkr = RegExp.$1;
}
}
document.postForm.color.parentNode.innerHTML += '<a href=javascript:add("[attack][/attack][attkr]'+attkr+'[/attkr]","")><img src="http://demonguardians.110mb.com/images/attack.jpg" alt="Attack User" /></a>';
}
//-->
</script>


This is the new code I've been working with. I have two issues, though...
The first is the fact that the Defense is undefined when I try to add it into the post.
This has got to be something to do with this section:

if(TDs[a].innerHTML.match(/\[attack\]([^<]+)\[\/attack\]\[attkr\]([^<]+)\[\/attkr\]/gi))
{

if(TDs[a].colSpan=="3" && TDs[a].vAlign=="top")
{
var usr=RegExp.$1;
var attkr=RegExp.$2;

if(TDs[a].width=="20%" && TDs[a].innerHTML.match(/Posts:/i) && TDs[a].innerHTML.match(usr))
{
if(TDs[a].innerHTML.match(/Defense: (\d+)/))
{
var usrDef=RexExp.$1;
}
}

TDs[a].innerHTML=TDs[a].innerHTML.replace(/\[attack\]([^<]+)\[\/attack\]\[attkr\]([^<]+)\[\/attkr\]/, attkr+', you have attacked '+usr+', who has Defense of '+usrDef);
}
}
}



The second is that there is this blurb of JavaScript that shows up in the footer of the topic.

Screenshot:

Do or do not. There is no try.


The Realms Beyond
Demon Guardians


Chris

Chris Avatar

******
Head Coder

19,519


June 2005
For the not working, I'll take another look in a bit.

The extra JS is pretty obvious:

   document.postForm.color.parentNode.innerHTML += '<a href=javascript:add("[attack][/attack][attkr]'+attkr+'[/attkr]","")><img src="http://demonguardians.110mb.com/images/attack.jpg" alt="Attack User" /></a>';
}
//-->
</script>

           TDs[a].innerHTML=TDs[a].innerHTML.replace(/\[attack\]([^<]+)\[\/attack\]\[attkr\]([^<]+)\[\/attkr\]/, attkr+', you have attacked '+usr+', who has Defense of '+usrDef)
       }
   }
}

if(this.location.href.match(/action=(display|(pm|calendar)?view(profile)?)/i) || document.title.match(/Search\s|Preview/i) && (!document.postForm && !document.postForm.color))
{
   for(a=0;a<TDs.length;a++)
   {
       Attack(a);
   }
}
else if(document.postForm && document.postForm.color)
{
   for(a=0;a<TDs.length;a++)
   {
       if(attkrReg = TDs[a].innerHTML.match(/Hey, ([^<]+), you have/gi))
       {
           var attkr = RegExp.$1;
       }
   }
   document.postForm.color.parentNode.innerHTML += '<a href=javascript:add("[attack][/attack][attkr]'+attkr+'[/attkr]","")><img src="http://demonguardians.110mb.com/images/attack.jpg" alt="Attack User" /></a>';
}
//-->
</script>


You repeated a part twice on accident. Just delete the repeat.

newBookmarkLockedFalling