Resource [Snippet] Some useful little snippets (combat related)

Discussion in 'Tutorials & Resources' started by Salvation, Mar 30, 2014.

  1. Code (Text):
    1.  
    2.     public static SpriteItem getCurrentWeapon() {
    3.         return Equipment.getItemIn(Slot.WEAPON);
    4.     }
    5.  
    6.     public static boolean equipWeapon(final String weapon) {
    7.         SpriteItem currentWeapon;
    8.         final SpriteItem item = Inventory.getFirstItem(weapon);
    9.         if (item != null && item.interact("Wield")) {
    10.             for (int i = 0; i < 10; i++) {
    11.                 if ((currentWeapon = getCurrentWeapon()) != null
    12.                         && currentWeapon.getDefinition().getName().equalsIgnoreCase(weapon)) {
    13.                     return true;
    14.                 }
    15.                 Execution.delay(100, 200);
    16.             }
    17.         }
    18.  
    19.         return (currentWeapon = getCurrentWeapon()) != null
    20.                 && currentWeapon.getDefinition().getName().equalsIgnoreCase(weapon);
    21.     }
    22.  
    23.     public static boolean isPlayerIdle() {
    24.         final Player p = Players.getLocal();
    25.         return p == null || p.getInteractingEntity() == null;
    26.     }
    27.  
    28.     public static boolean isUnderAttack(final boolean healthbar) {
    29.         final Player player = Players.getLocal();
    30.         if (player == null || (healthbar && player.getHealthGauge() == null)) {
    31.             return false;
    32.         }
    33.  
    34.         for (final Npc n : Npcs.getLoaded()) {
    35.             final Actor a = n.getInteractingEntity();
    36.             if (a != null && a.equals(player)) {
    37.                 return true;
    38.             }
    39.         }
    40.  
    41.         for (final Player p : Players.getLoaded()) {
    42.             final Actor a = p.getInteractingEntity();
    43.             if (a != null && a.equals(player)) {
    44.                 return true;
    45.             }
    46.         }
    47.         return false;
    48.     }
    49.  
    50.     public static int getSpecialEnergy() {
    51.         return Varps.getAt(300).getBits() / 10;
    52.     }
    53.  
    54.     public static boolean isSpecialAttackSelected() {
    55.         return Varps.getAt(301).getBits() == 1;
    56.     }
    57.  
    58.     public static boolean specialAttack() {
    59.         if (!Tab.COMBAT_OPTIONS.isOpen() && !Tab.COMBAT_OPTIONS.open()) {
    60.             return false;
    61.         }
    62.  
    63.         if (isSpecialAttackSelected()) {
    64.             return true;
    65.         }
    66.  
    67.         final InterfaceComponent ic = Interfaces.getAt(593, 43);
    68.         if (ic == null || !ic.isValid()) {
    69.             return false;
    70.         }
    71.  
    72.         return ic.click();
    73.     }
    74.  
    75.     public static int getHealth() {
    76.         final InterfaceComponent ic = Interfaces.getAt(548, 76);
    77.         if (ic != null && ic.isValid() && ic.getText() != null) {
    78.             try {
    79.                 return Integer.parseInt(ic.getText().trim());
    80.             } catch (final NumberFormatException e) {
    81.                 e.printStackTrace();
    82.             }
    83.         }
    84.         return Skill.CONSTITUTION.getCurrentLevel();
    85.     }
    86.  
    87.     public static int getDamage() {
    88.         return Skill.CONSTITUTION.getBaseLevel() - getHealth();
    89.     }
    90.  
     
    #1 Salvation, Mar 30, 2014
    Last edited: Apr 5, 2014
  2. Code (Text):
    1.  
    2. getCurrentWeapon().equals(weapon);
    3.  
    Your comparing a SpriteItem to a String, that doesn't work.
     
  3. Remind me not to program again after drinking a twelvepack.
     
    Arbiter likes this.
  4. Lol xD
     

Share This Page

Loading...