Help grabbing combat levels!

Discussion in 'Web Programming' started by 0h n035, Aug 17, 2009.

Help grabbing combat levels!
  1. Unread #1 - Aug 17, 2009 at 7:32 AM
  2. 0h n035
    Joined:
    Feb 1, 2007
    Posts:
    163
    Referrals:
    0
    Sythe Gold:
    0

    0h n035 Active Member

    Help grabbing combat levels!

    Alright, so I'll be honest, I HAVE NO IDEA ABOUT JAVASCRIPT! So, basically, I want, when the button is clicked, for this to grab my levels and calculate the combat levels. Simple. Well... Not for me. Here are my codes ATM (thanks Tip.it):

    Code:
    <script language="JavaScript" type="text/javascript">
    function expToLevel(exp,hp){
    // Converts exp to level. HP is bool and should be true when working on HP exp
      var points = 0;
      var output = 0;
      for (var lvl = 1; lvl <= 150; lvl++)
      {
        points += Math.floor(lvl + 300*Math.pow(2, lvl/7.))
        if (lvl >= 1)
    	{
          if (output > exp)
          {
            lvl = lvl - 1;
    		if((lvl < "10") && hp){return "10";}  // Can't have < 10 hp
    		else if(lvl == "0"){return "1";}
    		else if(lvl > "99"){return "99";}
    		else{return lvl;}
          }
          output = Math.floor(points/4);
        }
      }
      return 0;
    }
    
    function calcCombat(attLvl,strLvl,defLvl,hpLvl,magLvl,ranLvl,praLvl,sumLvl){
      var combatSum;
      var combatNoSum;
      var based;
      
      // "Base Combat"
      var defVal = 0.25 * defLvl;
      var hpVal = 0.25 * hpLvl;
      var praVal = 0.25 * Math.floor(praLvl/2);	//Uneven levels "don't count"
      var sumVal = 0.25 * Math.floor(sumLvl/2);
      var baseCombatSum = defVal + hpVal + praVal + sumVal;
      var baseCombatNoSum = defVal + hpVal + praVal;
      
      if(((attLvl + strLvl) < (magLvl * 1.5)) && (ranLvl <= magLvl)){	// Magic Based
        var magVal = Math.floor(magLvl * 1.5) * 0.325;	// Uneven levels "count for 2/3rds"
        combatSum = baseCombatSum + magVal;
    	combatNoSum = baseCombatNoSum + magVal;
        based = "magic";
      }
      else if(((attLvl + strLvl) < (ranLvl * 1.5)) && (magLvl < ranLvl)){	// Ranged Based
        var ranVal = Math.floor(ranLvl * 1.5) * 0.325;
    	combatSum = baseCombatSum + ranVal;
    	combatNoSum = baseCombatNoSum + ranVal;
    	based = "ranged";
      }
      else{	// Melee Based
        var attVal = attLvl * 0.325;
    	var strVal = strLvl * 0.325;
    	combatSum = baseCombatSum + attVal + strVal;
    	combatNoSum = baseCombatNoSum + attVal + strVal;
    	based = "melee";
      }
      
      var result = new Array(combatSum, combatNoSum, based);
      return result;
    }
    function GrabTheStats(){
    var GrabStats = http://hiscore.runescape.com/index_lite.ws?player=Zezima;
    var GrabStats_array = GrabStats.split(",");
    	  attLvl = expToLevel(GrabStats_array[0],false);
    	  strLvl = expToLevel(GrabStats_array[1],false);
    	  defLvl = expToLevelGrabStats_array[2],false);
    	  hpLvl = expToLevel(GrabStats_array[3],true);
    	  magLvl = expToLevel(GrabStats_array[4],false);
    	  ranLvl = expToLevel(GrabStats_array[5],false);
    	  praLvl = expToLevel(GrabStats_array[6],false);
    	  sumLvl = expToLevel(GrabStats_array[7],false);
    calcResult = calcCombat(attLvl,strLvl,defLvl,hpLvl,magLvl,ranLvl,praLvl,sumLvl);
    document.getElementById('outputlocation').value = calcResult[0] + "," + calcResult[1];
    }
    </script>
    Code:
    <input type="text" name="playername" id="outputlocation"/>
    <input type="button" onclick="GrabTheStats();" value="CLICK ME" />
    Could someone help me to get this working? I want the end result to be "P2P Combat,F2P Combat".

    Thanks!
     
  3. Unread #2 - Aug 22, 2009 at 11:37 PM
  4. Raid500
    Joined:
    Feb 11, 2007
    Posts:
    592
    Referrals:
    1
    Sythe Gold:
    0

    Raid500 Forum Addict

    Help grabbing combat levels!

    That's a bunch of javascript, convert it into php then you will be able to use it ;)
     
  5. Unread #3 - Aug 23, 2009 at 4:09 AM
  6. 0h n035
    Joined:
    Feb 1, 2007
    Posts:
    163
    Referrals:
    0
    Sythe Gold:
    0

    0h n035 Active Member

    Help grabbing combat levels!

    Tip.it do it like that (with javascript) :eek: I just changed it around a little, and now it's broken :\

    Also, I need this to stay as javascript, since I'm going to use it on my IPB board, where it will call GrabTheStats({content}) on their username field, so it displays their combat level next to it.
     
  7. Unread #4 - Sep 2, 2009 at 6:23 PM
  8. Hell Bomb
    Joined:
    Jun 28, 2009
    Posts:
    24
    Referrals:
    1
    Sythe Gold:
    0

    Hell Bomb Newcomer

    Help grabbing combat levels!

    IPB will let you use php o.0
     
  9. Unread #5 - Sep 2, 2009 at 8:01 PM
  10. speedster239
    Joined:
    Jan 21, 2007
    Posts:
    313
    Referrals:
    0
    Sythe Gold:
    0

    speedster239 Forum Addict
    Java Programmers

    Help grabbing combat levels!

    You're never going to get anywhere unless you build your own code from the ground up. That way you understand every in and out and should be able to fix it yourself. Also, you should check out using PHP. It provides great functionality for this application. In fact, I've used it for this very purpose in the past to grab stats for stat signatures :).
     
< Need Form Script | Need vBulliten setup to my forum. >

Users viewing this thread
1 guest


 
 
Adblock breaks this site