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


Quick Links:


newBookmarkLockedFalling

crazynarutard

crazynarutard Avatar

*****
Senior Studio Member

1,470


August 2005
I think a great code for beginners to learn from:

<script type="text/javascript">
/*Simplest RPG
created by CrAzY_J
This copyright must stay intact at all times*/

function RpG(name,multi)
{
 var TD = document.getElementsByTagName( "TD" );
 for( t = 0 ; t<TD.length ; t ++)
 {
  if( TD[t].width == "20%" && TD[t].innerHTML.match(/Posts:/))
  {
   var Posts = parseInt(TD[t].innerHTML.split(/Posts: /)[1].split(/<\//)[0].replace(/,/g,''));
   TD[t].appendChild ( document.createElement( "br" ));
   TD[t].appendChild ( document.createTextNode ( name + ": " + Math.floor ( Posts*parseInt ( multi ) ) ) );
  }
 }
}

RpG( "Money" , "4" );
RpG( "HP" , "2" );
</script>



Eric

Eric Avatar



1,442


November 2005
I must say, I'm rather impressed at the simplicity of this RPG. Good job Crazy.

One thing though, why did you put the number in quotes, and then parseInt it later? It could have been just as easily a number to start with :P.

crazynarutard

crazynarutard Avatar

*****
Senior Studio Member

1,470


August 2005
eric said:
I must say, I'm rather impressed at the simplicity of this RPG. Good job Crazy.

One thing though, why did you put the number in quotes, and then parseInt it later? It could have been just as easily a number to start with :P.

I knowz.

But don't you think some users would get confused with where they have to add the quotes? :P

edit: and where not to


Last Edit: Nov 21, 2005 2:28:05 GMT by crazynarutard

Eric

Eric Avatar



1,442


November 2005
Not really, but ok :P.

Also, if you multiply a quote that can be a number by any number, it still works :P.

crazynarutard

crazynarutard Avatar

*****
Senior Studio Member

1,470


August 2005
eric said:
Not really, but ok :P.

Also, if you multiply a quote that can be a number by any number, it still works :P.

....shutup :P

Eric

Eric Avatar



1,442


November 2005
You mind if I make a version of this?

crazynarutard

crazynarutard Avatar

*****
Senior Studio Member

1,470


August 2005
eric said:
You mind if I make a version of this?

and show everyone how big of a noob I am compared to you? :(

sure :P


Last Edit: Nov 21, 2005 3:13:51 GMT by crazynarutard

Eric

Eric Avatar



1,442


November 2005
Alright I changed for the most part 2 things.
1) I made it an object and have it only execute the part to add all the stats once, otherwise you are wasting time and whatnot.
2) I wanted a slightly more advanced way of doing stats... So I added another option to use an "x" variable and do what you want with it.

Edit 3rd & 4th Things:
3) Added levels, and the posts required to get that level. x now refers to the level and the multiplier goes by the level.
4) Optimized more, added a function to append

<script type="text/javascript">
<!--
/*Simplest RPG
created by CrAzY_J
This copyright must stay intact at all times
Object Version*/

var RPG = new function()
{
   this.stats = new Array();
   this.PPL = 1;
   this.addStat = function(name, equation)
   {
      if(arguments[2])
         this.stats.push(new Array(name, equation + "", 1));
      else
         this.stats.push(new Array(name, parseInt(equation), 0));
   }
   this.appendStat = function(obj, name, stat)
   {
      obj.appendChild(document.createElement("br"));
      obj.appendChild(document.createTextNode(name + ": " + stat));
   }
   this.showStats = function()
   {
      var TD = document.getElementsByTagName('td');
      var posts = 0;
      var a = 0;
      var e = 0;
      var statCalc = 0;
      var level = 1;
      for(var t = 0; t < TD.length; t++)
      {
         if(TD[t].width == "20%" && TD[t].innerHTML.match(/Posts: ([0-9,]+)/))
         {
            posts = parseInt(RegExp.$1.replace(/,/g,''));
            level = Math.floor(posts / this.PPL) + 1;
            this.appendStat(TD[t], "Level", level);
            for(a = 0; a < this.stats.length; a++)
            {
               if(this.stats[2])
                  statCalc = Math.floor(eval(this.stats
[1].replace("x", level)));
               else
                  statCalc = Math.floor(level * this.stats
[1]);
               this.appendStat(TD[t], this.stats
[0], statCalc);
            }
         }
      }
   }
}

RPG.PPL = 17;

RPG.addStat("Gil", "x * 5 + 6", 1);
RPG.addStat("HP", "13");
RPG.addStat("MP", "11");

RPG.showStats();

// -->
</script>


Have fun.


Last Edit: Nov 22, 2005 4:07:44 GMT by Eric

crazynarutard

crazynarutard Avatar

*****
Senior Studio Member

1,470


August 2005
I like the use of x :P

Eric

Eric Avatar



1,442


November 2005
crazyj said:
I like the use of x :P
I wasn't gonna do it at first, but I thought it would be cool to allow users to get something different than a multiple and maybe add/subtract numbers :P.

Eric

Eric Avatar



1,442


November 2005
Modified, see my post to take a look :P

crazynarutard

crazynarutard Avatar

*****
Senior Studio Member

1,470


August 2005
:o Levels. really nice Eric :P

Chris

Chris Avatar

******
Head Coder

19,519


June 2005
I like the touch... :P

peter
Guest
Pretty cool, both of ya :)

People should keep extending it now, carrying on from Eric's ;) :P

Chris

Chris Avatar

******
Head Coder

19,519


June 2005
What we could do is, give items to certain users or at certain levels.

newBookmarkLockedFalling