Jump to content

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


wafihsn

Recommended Posts

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");
}
Link to comment
Share on other sites

 

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
Link to comment
Share on other sites

 

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 

Link to comment
Share on other sites

 

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
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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