Jump to content

[HELP] how to detect "Attack Mode" and how to intract with entinty


Recommended Posts

Posted

Hey there , im new on runescape os and im making my own script .

 

i am having issu with 2 things , i need to check if my player is in "attack mode" then wait until he is finish .
second problem is i can intract with entitys , i want my player to collect bones but nothing happens ,
ill paste my code and plz tell me what i did wrong..

if(getInventory().isFull())
         getInventory().interact("Bury", "Bones");
     else{
         Entity bones = getObjects().closest("Bones");
         NPC chiken = getNpcs().closest("Chicken");
         NPC cow = getNpcs().closest("Cow");
         NPC cowcalf = getNpcs().closest("Cow Calf");
         
         if (chiken != null) //attack chicken
             if (!myPlayer().isAnimating())
                 chiken.interact("Attack");
         if (cow != null) //attack cow
             if (!myPlayer().isAnimating())
                 cow.interact("Attack");
         if (cowcalf != null) //attack cow calf
             if (!myPlayer().isAnimating())
                 cowcalf.interact("Attack");
         if (bones != null) //take Bones
             if (!myPlayer().isAnimating())
             bones.interact("Take");
}
Posted (edited)

 

Hey there , im new on runescape os and im making my own script .

 

i am having issu with 2 things , i need to check if my player is in "attack mode" then wait until he is finish .

second problem is i can intract with entitys , i want my player to collect bones but nothing happens ,

ill paste my code and plz tell me what i did wrong..

if(getInventory().isFull())
         getInventory().interact("Bury", "Bones");
     else{
         Entity bones = getObjects().closest("Bones");
         NPC chiken = getNpcs().closest("Chicken");
         NPC cow = getNpcs().closest("Cow");
         NPC cowcalf = getNpcs().closest("Cow Calf");
         
         if (chiken != null) //attack chicken
             if (!myPlayer().isAnimating())
                 chiken.interact("Attack");
         if (cow != null) //attack cow
             if (!myPlayer().isAnimating())
                 cow.interact("Attack");
         if (cowcalf != null) //attack cow calf
             if (!myPlayer().isAnimating())
                 cowcalf.interact("Attack");
         if (bones != null) //take Bones
             if (!myPlayer().isAnimating())
             bones.interact("Take");
}

 

 

Items on the ground are GroundItems not RS2Objects. So to get the bones you need to do:

GroundItem bones = getGroundItems().closest("Bones");

To check if your player is attacking something you can do:

if(myPlayer().getInteracting() != null)

Or this may work too:

getCombat().isFighting()

Also FYI you don't need a separate variable for each target NPC. You can get the closest out of all of them with one statement:

NPC enemy = S.getNpcs().closest("Chicken", "Cow", "Cow calf");

But you may also want to check that those npcs are not under attack themselves, and that they are not dead. Perhaps something like:

NPC enemy = getNpcs().closest(new NameFilter<>("Chicken", "Cow", "Cow calf"), npc -> !npc.isUnderAttack() && npc.getHealthPercent() > 0);
Edited by Explv
  • Like 1
Posted

 

Items on the ground are GroundItems not Objects. So to get the bones you need to do:

GroundItem bones = getGroundItems().closest("Bones");

To check if your player is attacking something you can do:

if(myPlayer().getInteracting() != null)

Or this may work too:

getCombat().isFighting()

Also FYI you don't need a separate variable for each target NPC. You can get the closest out of all of them with one statement:

NPC enemy = S.getNpcs().closest("Chicken", "Cow", "Cow calf");

But you may also want to check that those npcs are not under attack themselves, and that they are not dead. Perhaps something like:

NPC enemy = getNpcs().closest(new NameFilter<>("Chicken", "Cow", "Cow calf"), npc -> !npc.isUnderAttack() && npc.getHealthPercent() > 0);

thanx man .. :)  im on the right way now 

Posted

 

Items on the ground are GroundItems not Objects. So to get the bones you need to do:

GroundItem bones = getGroundItems().closest("Bones");

To check if your player is attacking something you can do:

if(myPlayer().getInteracting() != null)

Or this may work too:

getCombat().isFighting()

Also FYI you don't need a separate variable for each target NPC. You can get the closest out of all of them with one statement:

NPC enemy = S.getNpcs().closest("Chicken", "Cow", "Cow calf");

But you may also want to check that those npcs are not under attack themselves, and that they are not dead. Perhaps something like:

NPC enemy = getNpcs().closest(new NameFilter<>("Chicken", "Cow", "Cow calf"), npc -> !npc.isUnderAttack() && npc.getHealthPercent() > 0);

Explv is a boss, always see him helping people with scripting and putting out some quality scripts

  • Like 2

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...