Skip to content
View in the app

A better way to browse. Learn more.

WRobot

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

CanCast Function Issue - Incorrectly Returning True When Target Is Out of Range

Featured Replies

Hello Wrobot community,

I'm currently working on a C# script for WoW 3.3.5a using the Wrobot framework. I've encountered an issue with my CanCast function, where it returns true even if the player is too far away from the target. Here's my original code:

internal static bool CanCast(Spell spell, WoWUnit target, bool canMove = true, bool tank = false)
{
    // Check if the caster is not stunned, not dead, not casting, the target is alive, the spell is usable,
    // the distance to the target is good, and there is no line of sight issue
    if (!ObjectManager.Me.IsStunned && !ObjectManager.Me.IsDead && !ObjectManager.Me.IsCast && !target.IsDead && spell.IsSpellUsable && spell.IsDistanceGood && !TraceLine.TraceLineGo(target.Position) && !target.IsMounted)
    {
        if (target.MaxHealth - target.Health != 0 || tank)
        {
            return true;
        }
    }

    // Return false, indicating the spell cannot be cast
    return false;
}
 
}

The problem seems to be related to the spell.IsDistanceGood condition, which does not seem to be working as intended. I'd appreciate it if anyone could help me identify the issue and suggest a solution.

Thank you in advance for your assistance!

It checks ingame 3D distance vs whatever the spell has as an attribute. That mostly doesn't work due to center-center calculations, hitboxes etc. 
Every server implements it differently too, so you just have to do your own calculation based on what you observe on your server. Good luck.

  • Author

I'm eventully trying to check distance with :

 

playerToHeal.GetDistance <= 40;

But i don't know if u should use :

playerToHeal.GetDistance2D <= 40;

                                or
playerToHeal.GetDistanceZ <= 40;


What is the difference between classic, 2D and Z ?
Thanks

Yes, 2D ignores Z axis and I would generally recommend you never use it unless you specifically know you need it.
PS: Figure out if your server calculates it including hitboxes and such. Otherwise you need to calculate the distance yourself based on Position.

Edited by Matenia

GetDistance2D will return the distance from you to the target, ignoring the Z axis, only useful in very specific situations.

GetDistanceZ will return only the Z distance from you to the target (ignoring X and Y), again, very specific.

GetDistance will return the 3D distance from you to the target. This is the one you want.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.