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


Quick Links:


newBookmarkLockedFalling

Quacker Jack

Quacker Jack Avatar

*****
ProNation

1,664


December 2007
Cool. Will do, Mr. Helpful.

Devin

Devin Avatar

**
Official Member

90


August 2007
Post it here when you are done =P
AFK Aug 2011 - ???

I'll be actively developing codes, tutorials, and templates when I return, later this year.

Aaron

Aaron Avatar
Bad Wolf

****
Dedicated Studio Member

859


November 2006
Please note that semicolons must not be used on lines that end in curly braces and separate variable declarations (which you need not worry about now).

Was a little confused, here. Variable declarations how? Like var; ? And with the curly braces, you do just mean the opening brace of the block, right? 'cause there's nothing wrong with {}; =p

Beyond that, I certainly like the approach.

Devin

Devin Avatar

**
Official Member

90


August 2007
Aaron Avatar
Please note that semicolons must not be used on lines that end in curly braces and separate variable declarations (which you need not worry about now).

Was a little confused, here. Variable declarations how? Like var; ? And with the curly braces, you do just mean the opening brace of the block, right? 'cause there's nothing wrong with {}; =p

Beyond that, I certainly like the approach.


I dunno what I was trying to write when I said separate variable declarations. :P I think I was talking about object literals. And yeah, I meant left parenthesis/braces only of course. Although it isn't necessarily suggested to include semicolons after right braces/parentheses either.
AFK Aug 2011 - ???

I'll be actively developing codes, tutorials, and templates when I return, later this year.

chaoskreator

chaoskreator Avatar
Abandon all hope...

**
Official Member

49


March 2009
Awesome tutorial. It cleared up a couple of things for me.

I have a question, though. You were talking about using regular expressions in match() being able to be saved for later use. Say my code is this:

var TDs = document.getElementsByTagName("TD");
function ubbc(a)
{
var ubbc_string = TDs[a].innerHTML.match(/\[ubbc=(\w+)\]/gi);

if(TDs[a].innerHTML.match(/\[ubbc=(\w+)\]/gi))
{
if(aTD[a].colSpan=="3" && aTD[a].vAlign=="top")
{
TDs[a].innerHTML=TDs[a].innerHTML.replace(/\[ubbc\=(\w+)\]/gi,'UBBC ACTION HERE '+ubbc_string[1]);
ubbc(a);
}
}
}

How would I go about getting the string that was RegEx'd in the line:
var ubbc_string = TDs.innerHTML.match(/\[ubbc=(\w+)\]/gi);?
I need the word string passed into a variable, but other than a complex split(), I can't envision any way to do this.

Another problem I have with the code above is that since document.getElementsByTagName("TD"); pulls all instances of the TD tag, TDs
.innerHTML.match(/\[ubbc=(\w+)\]/gi) checks each instance of the TD tag for the string, causing ubbc_string to return an array mostly of nulls, with only a few usuable returns. I need to figure out a way to get around this somehow.

Any suggestions?



Last Edit: Apr 10, 2009 17:10:37 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
Chaoskreator: I can answer a few of those.

1) ubbc_string now contains the results of the match. It -should- contain an array of all the matches for that particular cell.

2) You're not checking every cell in the TDs array. You're checking a specific cell. That cell is TDs (so the a-th element of the array). That's why it is inside a function with a as the sole parameter.

Hopefully that helps a bit.


chaoskreator

chaoskreator Avatar
Abandon all hope...

**
Official Member

49


March 2009
So, you're saying that if I were to use alert(ubbc_string); right below that variable's declaration, that I would get a single alert box with [ubbc=whatever] as the text?
Because that is sooo not what happens. lol
Do or do not. There is no try.


The Realms Beyond
Demon Guardians


Chris

Chris Avatar

******
Head Coder

19,519


June 2005

chaoskreator

chaoskreator Avatar
Abandon all hope...

**
Official Member

49


March 2009
The idea is that the ubbc code is supposed to pass the name of the person being attacked to the script. The script will then modify stats accordingly.
EDIT: I hope the spacing and tabs look okay. I posted this from my phone.
The actual code I'm using is:

<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 attk_string = TDs[a].innerHTML.match(/\[attack=(\w+)\]/gi);
    if(TDs[a].innerHTML.match(/\[attack=(\w+)\]/gi))
    {
        if(TDs[a].vAlign=="top" && TDs[a].colSpan=="3")
        {
            TDs[a].innerHTML=TDs[a].innerHTML.replace(/\[attack\=(\w+)\]/gi,'You have attacked '+attk_string[1]);
            Attack(a);
        }
    }
}
if(location.href.match(/action=(display|viewprofile|search2|recent|post)/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)
    {
        dpF=document.postForm;
        dpF.color.parentNode.innerHTML+='<a href=javascript:add("[attack=]","")><img src="http://demonguardians.110mb.com/images/attack.jpg" alt="Attack User" /></a>';
    }
    function hideshowstats(ext)
    {
        if(ext.parentNode.parentNode.parentNode.rows[1].style.display=="none")        {            ext.innerHTML="<b><u>Hide RPG Stats</u></b>";
            ext.parentNode.parentNode.parentNode.rows[1].style.display="";
            ext.parentNode.parentNode.parentNode.rows[2].style.display="";
            ext.parentNode.parentNode.parentNode.rows[3].style.display="";
            ext.parentNode.parentNode.parentNode.rows[4].style.display="";
            ext.parentNode.parentNode.parentNode.rows[5].style.display="";
            ext.parentNode.parentNode.parentNode.rows[6].style.display="";
            ext.parentNode.parentNode.parentNode.rows[7].style.display="";
            ext.parentNode.parentNode.parentNode.rows[8].style.display="";
        }
        else
        {
            ext.innerHTML="<b><u>Show RPG Stats</u></b>";
            ext.parentNode.parentNode.parentNode.rows[1].style.display="none";
            ext.parentNode.parentNode.parentNode.rows[2].style.display="none";
            ext.parentNode.parentNode.parentNode.rows[3].style.display="none";
            ext.parentNode.parentNode.parentNode.rows[4].style.display="none";
            ext.parentNode.parentNode.parentNode.rows[5].style.display="none";
            ext.parentNode.parentNode.parentNode.rows[6].style.display="none";
            ext.parentNode.parentNode.parentNode.rows[7].style.display="none";
            ext.parentNode.parentNode.parentNode.rows[8].style.display="none";
        }
    }
}
</script>



Last Edit: Apr 10, 2009 22:34: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
I'm gonna do a bunch of clean up and post my changes in red. You're using my really old base, and it is extremely poor. >.< That code was 2005 or 2004 I think. Hopefully I don't break anything.

<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){
[red]var attReg = /\[attack=(\w+)\]/gi;[/red]
var attk_string = TDs.innerHTML.match([red]attReg[/red]);
[red] if(TDs
.vAlign=="top" && TDs.colSpan=="3")
{
if(TDs
.innerHTML.match(attReg))
{[/red]
TDs
.innerHTML = TDs.innerHTML.replace([red]attReg[/red],'You have attacked '+attk_string[1]);
Attack(a);
}
}
}
if([red]location.href.match(/action=(display|(pm|calendar)?view(profile)?)/i) || document.title.match(/Search\s|Preview/i)[/red])
{
for(a=0;a<TDs.length;a++)
{
if(TDs
.width=="20%" && TDs.innerHTML.match(/Posts:/i))
{
if(TDs
.getElementsByTagName("A")[0].href.match(maxusers) || TDs.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
.innerHTML.match(/Karma: (\d+)/i))
{
var karma = RegExp.$1;
}
if(TDs
.innerHTML.match(/Posts: (\d+),(\d+)/i))
{
var posts = RegExp.$1 + RegExp.$2;
}
else if(TDs
.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
.innerHTML += stat_menu;
}
Attack(a);
}
if(document.postForm[red] && document.postForm.color[/red])
{
[red]document.postForm[/red].color.parentNode.innerHTML += '<a href=javascript:add("[attack=]","")><img src="http://demonguardians.110mb.com/images/attack.jpg" alt="Attack User" /></a>';
}
function hideshowstats(ext)
{
[red]var n = ext.parentNode.parentNode.parentNode.rows;[/red]
if([red]n[/red][1].style.display == "none"){
ext.innerHTML="<b><u>Hide RPG Stats</u></b>";
[red]for(var b=1;b<n.length;b++){
n.style.display = "";
}[/red]
}
else
{
ext.innerHTML="<b><u>Show RPG Stats</u></b>";
[red]for(var b=1;b<n.length;b++){
n.style.display = "none";
}[/red]
}
}
}
</script>



Now, we need to do what you're talking about. As it stands, I don't see any array of user data for it to update.... So yeah, totally confused there.


Last Edit: Apr 11, 2009 4:34:26 GMT by Chris

Aaron

Aaron Avatar
Bad Wolf

****
Dedicated Studio Member

859


November 2006
Can I play, too? =o

chaoskreator

chaoskreator Avatar
Abandon all hope...

**
Official Member

49


March 2009
Sorry about stretching the page, there. I'll fix that in a little while.
Okay, so I'll work from the code above. I'm also going to make my own thread for this project so as not to keep mucking up other people's threads.
Do or do not. There is no try.


The Realms Beyond
Demon Guardians


[lUkE]™

[lUkE]™ Avatar

*
New Member

21


October 2009
Best lesson on here :D
*thumbs up*



codercommunity.proboards.com/index.cgi

A site for coders and graphic designers. Also get your forum rated! More people see your forum that way! JOIN NOW AND ENJOY YOUR SELF! ;D


newBookmarkLockedFalling