October 31, 20169 yr 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?
November 2, 20169 yr 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
November 2, 20169 yr 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