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.

How can i cast a spell at a player by playername?

Featured Replies

I tried 

CastSpellByID(spellID, "targetName")

sometimes it works but sometimes it is doing strange stuff and target my toon or is casting at my current target.
May someone got a idea how i can realize it lie healbot for example that i don't need a target selected to heal it?

UPDATE:
I found a solution for it but my problem now is that the bot only starts healing if he has a target doesn*t matter what. Any tipps?

Like this (not tested):

    public static void CastByPlayerName(int spellId, string playerName)
    {
        string lua = "CastSpellByID(spellID, 'focus')";
        var target = ObjectManager.GetObjectWoWPlayer().FirstOrDefault(p => p.Name == playerName);
        try
        {
            if (target != null && !target.IsValid)
                return;

            if (target.IsMyTarget)
            {
                Lua.LuaDoString(lua.Replace("spellID", spellId.ToString()).Replace("'focus'", "'target'"));
            }
            else if (target.Guid == ObjectManager.Me.FocusGuid)
            {
                Lua.LuaDoString(lua.Replace("spellID", spellId.ToString()));
            }
            else
            {
                var currentFocus = ObjectManager.Me.FocusGuid;
                ObjectManager.Me.FocusGuid = target.Guid;
                Lua.LuaDoString(lua.Replace("spellID", spellId.ToString()));
                ObjectManager.Me.FocusGuid = currentFocus;
            }

        }
        catch { }
    }

In second argument of castspellby... (in legion version), it is not player name, but it is unitid http://wow.gamepedia.com/UnitId

  • Author

Thanks for you answer but i'm using the focus for the tank so i'm not able to use your way.

I wrote another method for it wich works fine. The only problem i noticed is that i always need a target to get the bot starting the routine. If i dont have a target the bot does nothing.

Heal method:

        /// <summary>
        /// Cast a heal
        /// </summary>
        /// <param name="spell">The heal you want to cast</param>
        /// <param name="target">The target you want to heal</param>
        /// <param name="healthProcent">The health procent we want to heal</param>
        /// <param name="buffTimeLeft">Recast if buff is under the given time</param>
        /// <param name="stacks">How much stacks you want at the target</param>
        /// <param name="debuff">The debuff we are looking for</param>
        /// <param name="owner">Flag that determines if we need to be the owner</param>
        /// <returns>Returns true if we can cast the spell otherwise false</returns>
        public static bool CastHeal(Spell spell, WoWUnit target, int healthProcent, int buffTimeLeft = 0, int stacks = 0, Spell debuff = null, bool owner = true)
        {
            // Need heal?
            if (target.HealthPercent > healthProcent)
            {
                // Skip
                return false;
            }

            // Wait until global cooldown is done
            Thread.Sleep(SpellManager.GlobalCooldownTimeLeft());

            bool hasDebuff;
            if (debuff != null)
            {
                hasDebuff = Functions.HasBuff(debuff, target, buffTimeLeft, stacks, owner);
            }
            else
            {
                hasDebuff = Functions.HasBuff(spell, target, buffTimeLeft, stacks, owner);
            }

            // Validate spell
            if (!ObjectManager.Me.IsStunned && !ObjectManager.Me.IsDead && !ObjectManager.Me.IsCast && !target.IsDead && spell.KnownSpell && spell.IsSpellUsable && spell.IsDistanceGood && !hasDebuff)
            {
                if (target.Guid == ObjectManager.Me.Guid)
                {
                    // Cast on self
                    Lua.LuaDoString($"CastSpellByID({spell.Id}, \"player\")");
                }
                else
                {
                    // Cast on target
                    Lua.LuaDoString($"CastSpellByID({spell.Id}, \"{target.Name}\")");
                }

                // Log
                Logging.WriteDebug($"Cast: {spell.NameInGame}");

                // Return
                return true;
            }

            // Return
            return false;
        }


HasBuff method:

        /// <summary>
        /// Determines if the given target has the buff with the given conditions
        /// </summary>
        /// <param name="spell">The spell you want to check</param>
        /// <param name="target">The target you want to check</param>
        /// <param name="buffTimeLeft">Recast if buff time is under the given time</param>
        /// <param name="stacks">How much stacks you want at the target</param>
        /// <param name="owner">Flag that determines if we need to be the owner</param>
        /// <returns>Returns true if the target has the spell on it with the given conditions otherwise false</returns>
        public static bool HasBuff(Spell spell, WoWUnit target, int buffTimeLeft = 0, int stacks = 0, bool owner = true)
        {
            // Get target auras
            List<Aura> auraList = target.GetAllBuff();

            // Get aura
            Aura aura = null;
            if (owner)
            {
                // Set
                aura = auraList.Where(s => s.ToString().Contains(spell.Name) && s.Owner == ObjectManager.Me.Guid).FirstOrDefault();
            }
            else
            {
                // Set
                aura = auraList.FirstOrDefault(s => s.ToString().Contains(spell.Name));
            }

            // Any found?
            if (aura != null)
            {
                // Validate
                if (aura.TimeLeftSeconde > buffTimeLeft && aura.Stack >= stacks)
                {
                    // Return
                    return true;
                }
            }

            // Return
            return false;
        }


Hope it will help some people who dealing with stuff like that :)

Info: It wont work with copy & paste, you need to correct some lines, i'm sorry for that but this are just snippets out of my own framework.

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.