Adblock breaks this site

Help grabbing combat levels!

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

  1. 0h n035

    0h n035 Active Member

    Joined:
    Feb 1, 2007
    Posts:
    163
    Referrals:
    0
    Sythe Gold:
    0
    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!
     
  2. Raid500

    Raid500 Forum Addict

    Joined:
    Feb 11, 2007
    Posts:
    592
    Referrals:
    1
    Sythe Gold:
    0
    Help grabbing combat levels!

    That's a bunch of javascript, convert it into php then you will be able to use it ;)
     
  3. 0h n035

    0h n035 Active Member

    Joined:
    Feb 1, 2007
    Posts:
    163
    Referrals:
    0
    Sythe Gold:
    0
    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.
     
  4. Hell Bomb

    Hell Bomb Newcomer

    Joined:
    Jun 28, 2009
    Posts:
    24
    Referrals:
    1
    Sythe Gold:
    0
    Help grabbing combat levels!

    IPB will let you use php o.0
     
  5. speedster239

    speedster239 Forum Addict
    Java Programmers

    Joined:
    Jan 21, 2007
    Posts:
    313
    Referrals:
    0
    Sythe Gold:
    0
    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. >


 
 
Adblock breaks this site