Jump to content

Better way to detect when in combat?


roguehippo

Recommended Posts

I was just wondering if there was a better way to detect if i am in combat because when using if(myPlayer().isincombat) it will detect it most of the time but if i am not getting attacked ,like if i was in a safe spot, than it doest really work that well. 

If you found out could you PM me or comment back on this post ? Would be much appreciated, I'm having the same problem and have been trying to fix it all together for awhile now

Link to comment
Share on other sites

I usually spam the Scripting Help topics faster than this, the isUnderAttack() and isFighting() methods are a bit vague in my opinion and they aren't exacly what scripters expect, same for getInteracting() as when you stop interacting you are still in combat. There is, however, a more reliable method, namely Character#getCombatTime(). You will have to work with client cycles instead of raw time and instead verify for a given diference in client cycles since last hitsplat which determines if a given Character (don't forget Player extends Character, not only NPC). I know this works for ranged and melee which always yield a hitsplat onhit therefore updating the combat time of that Character instance. For magic however (range too if you want maximum accuracy), you can rely on the Projectiles class. If a projectile is sent from a Character, means that Character is definately attacking someone and their target is locked in combat.

  • Like 1
Link to comment
Share on other sites

I usually spam the Scripting Help topics faster than this, the isUnderAttack() and isFighting() methods are a bit vague in my opinion and they aren't exacly what scripters expect, same for getInteracting() as when you stop interacting you are still in combat. There is, however, a more reliable method, namely Character#getCombatTime(). You will have to work with client cycles instead of raw time and instead verify for a given diference in client cycles since last hitsplat which determines if a given Character (don't forget Player extends Character, not only NPC). I know this works for ranged and melee which always yield a hitsplat onhit therefore updating the combat time of that Character instance. For magic however (range too if you want maximum accuracy), you can rely on the Projectiles class. If a projectile is sent from a Character, means that Character is definately attacking someone and their target is locked in combat.

i will definitely look into the more in depth way instead of just using underattack as you are right they are a bit vague. thanks for the responce, hopefully i can make my script as perfect as possible for the community!

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