Jump to content

fighting algorithm


dokato

Recommended Posts

Ok, so I've tried out 100000 things to make my fighting scripts as good as possible but it still keeps dissapointing me.

Currently I'm using this one, its an example that should kill chickens at the new chicken area in lumbridge:

http://pastebin.com/xGX3bTfD

And PLEASE, for those who have little to none expierence with fighting scripts, dont post obvious stuff like do this..., or you should better do that..., cuz the chance is big I've alrdy tried it lol. Or just dont post at all in that case. 

 

Just a call out for help to those who have expierence with this kind of stuff.

Edited by dokato
Link to comment
Share on other sites

Well firstly, you don't need to iterate the npc's in the region to get the best one you can just use filters for that and return the npc best suited based on the conditions you provide. 

 

1) Get the instance of the NPC

2) Check if your player is interacting with it

3) If not attack if yes, sleep

 

I would give you the code for it but then I don't think you would learn from it unless you familiarize yourself with the api by digging through it.

Link to comment
Share on other sites

@Botre

it will sometimes click on another chicken while he's alrdy in combat with a chicken, and sometimes while he's fighting a chicken, it will reclick on the chicken, while it is alrdy fighting it.

And after it has killed the chicken, it will keep clicking on it till it completely dissapears (the animation of one dying and dissapearing).


Well firstly, you don't need to iterate the npc's in the region to get the best one you can just use filters for that and return the npc best suited based on the conditions you provide. 

 

1) Get the instance of the NPC

2) Check if your player is interacting with it

3) If not attack if yes, sleep

 

I would give you the code for it but then I don't think you would learn from it unless you familiarize yourself with the api by digging through it.

 

"1) Get the instance of the NPC"

if i do that, and the chicken is alrdy under attack by someone else, it will do nothing and wait till it's dead, while it should be looking for another one to kill, that can be located a bit further than the one in the instance. So basically it is wasting time while he could be attacking another one.

 

Or do you mean something else, or did i misunderstand u?

Edited by dokato
Link to comment
Share on other sites

@Botre

it will sometimes click on another chicken while he's alrdy in combat with a chicken, and sometimes while he's fighting a chicken, it will reclick on the chicken, while it is alrdy fighting it.

And after it has killed the chicken, it will keep clicking on it till it completely dissapears (the animation of one dying and dissapearing).

 

"1) Get the instance of the NPC"

if i do that, and the chicken is alrdy under attack by someone else, it will do nothing and wait till it's dead, while it should be looking for another one to kill, that can be located a bit further than the one in the instance. So basically it is wasting time while he could be attacking another one.

 

Or do you mean something else, or did i misunderstand u?

i meant use filters;

NPC chicken = getNpcs().closest(new Filter<NPC>({
    @Override
    public boolean match(NPC npc){
       return npc.getName().equalsIgnoreCase("chicken") && !npc.isUnderAttack() && getMap().canReach(npc) && npc.getHealth() > 0;
    }
});

Don't copy and paste cos I wrote that with no code assist so the filter could be wrong. This in essence will return the closest chicken that you can attack, is reachable, has health > 0, not currently being attacked. Of course you can tweak the boolean as you wish but that's all you need really.

 

Much more efficient/cleaner/easy to read & understand happy.png

Edited by Divinity
  • Like 2
Link to comment
Share on other sites

i meant use filters;

NPC chicken = getNpcs().closest(new Filter<NPC>({
    @Override
    public boolean match(NPC npc){
       return npc.getName().equalsIgnoreCase("chicken") && !npc.isUnderAttack() && getMap().canReach(npc) && npc.getHealth() > 0;
    }
});

Don't copy and paste cos I wrote that with no code assist so the filter could be wrong. This in essence will return the closest chicken that you can attack, is reachable, has health > 0, not currently being attacked. Of course you can tweak the boolean as you wish but that's all you need really.

 

Much more efficient/cleaner/easy to read & understand happy.png

 

Alek is going to kill you for not using a stream + lambda :x

  • Like 2
Link to comment
Share on other sites

i meant use filters;

NPC chicken = getNpcs().closest(new Filter<NPC>({
    @Override
    public boolean match(NPC npc){
       return npc.getName().equalsIgnoreCase("chicken") && !npc.isUnderAttack() && getMap().canReach(npc) && npc.getHealth() > 0;
    }
});

Don't copy and paste cos I wrote that with no code assist so the filter could be wrong. This in essence will return the closest chicken that you can attack, is reachable, has health > 0, not currently being attacked. Of course you can tweak the boolean as you wish but that's all you need really.

 

Much more efficient/cleaner/easy to read & understand happy.png

Wauwohmy.png ohmy.png ohmy.png , didnt know that, thank you man!!!

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...