Jump to content
This site uses cookies! Learn More

This site uses cookies!

By continuing to use this site, you agree to allow us to store cookies on your computer. :)

Stresse

Casting Spell on WoWUnit Without Targeting (Player OR Mob)

Recommended Posts

Howdy y'all!

My C# is finally at the point where I am starting to be able to develop full products (profiles, fightclasses, etc.).

I'm working on a fightclass template (which I'll post once functional) that people can adapt for any class they want (I'm developing it for my Disc Priest, so it already has to be able to do some niche stuff).

@Smokie gave some great code in this post on how to cast spells on yourself and party members (maybe other players, too, I haven't tested).
 

SpellManager.CastSpellByNameOn("Rejuvenation", p.Name);
SpellManager.CastSpellByNameOn("Rejuvenation","PlayerName");
SpellManager.CastSpellByNameOn("Rejuvenation", ObjectManager.Me.Name);

"Really any code with a name string will work"

That code works fantastically for players! But mobs share names and so require us to use their LuaId, which, to my knowledge, isn't retrievable using Wrobot methods/properties (if I'm wrong, please set me straight).

I actually can't even figure out how to get the LuaId using Lua and the only way I've seen anyone attempt to implement this functionality did so (a long time ago, most of the code is unusable, actually).

public static bool CastSpell(Spell spell, WoWUnit unit, bool force)
	{
		//	Handle bullshit units
		if (unit == null || !unit.IsValid || unit.IsDead || !spell.KnownSpell || !spell.IsSpellUsable)
		{
			return false;
		}

		//	Check If Toon is Wanding
		if (spell.Name == "Shoot" && IsAutoRepeating("Shoot"))
		{
			return true;
		}

  		//	Fuck off if toon is already casting and (force == false)
		if (ObjectManager.Me.Casting() && !force)
			return false;
  
		//	Stop moving if spell needs to be cast
		if (spell.CastTime > 0)
			MovementManager.StopMoveTo(false, Usefuls.Latency + 500);

  		//	Force cast spell if (force == true)
		if (force)
			Lua.LuaDoString("SpellStopCasting();");
  
		//	Cast AoE spells by location
		if (AreaSpells.Contains(spell.Name))
		{
			Lua.LuaDoString("CastSpellByName(\"" + spell.Name + "\")");
			ClickOnTerrain.Pulse(unit.Position);
		}
		else
		{
            //	Rely on Auto Self Cast
			WoWUnit temp = ObjectManager.Target;
			bool onSelf= unit.Guid == ObjectManager.Me.Guid;

          	//	Face unit to cast
			if (!onSelf)
			{
				MovementManager.Face(unit);
				_disableTargeting= true;
				TargetUnit(unit);
			}
          	//	Default to self casting
			SpellManager.CastSpellByNameOn(spell, ObjectManager.Me.Name);
          
			//	Handle non-self targets
			if (!onSelf)
			{
				if (temp.Guid == 0 || !temp.IsValid)
				{
					Lua.LuaDoString("ClearTarget();");  //	This clears the current target...which defeats the purpose, yea?
				}
				else
				{
					TargetUnit(temp);
				}
				//  Interact.InteractObjectis also given as a possibility, but, as I understand it, that would also change targets
				_disableTargeting= false;
			}
		}
		return true;
	}

I don't understand the use of Locktargeting and so can't figure out how to remove code rot or whether or not this should actually work as a "Mouseover Cast"- type cast (for classes/situation where focusing on a new WoWUnit would be undesirable but applying a dot or whatever is necessary).

Hoping someone can help me figure it out! 

Share this post


Link to post
Share on other sites

For that method to work, you need to set  Pacific wowunit as unit1, unit 2 etc in your code, I don’t have my laptop on my so I can’t really help but give each wowunit it’s own number and go from there. 

 

Ps: I don’t remember you at all, I don’t remember a lot ..... I was drunk a lot more then I thought.

Share this post


Link to post
Share on other sites

Hahaha, it was someone else's topic, I've just been cannibalizing code from all over for a couple months now.

"Learning C# By Botting", I'm here to say, should be developed as a teaching technique.

 

Share this post


Link to post
Share on other sites
7 minutes ago, Smokie said:

For that method to work, you need to set  Pacific wowunit as unit1, unit 2 etc in your code, I don’t have my laptop on my so I can’t really help but give each wowunitit’s own number and go from there.

If I give them designations in my code, don't I run into the same issue (that I can't get their LuaId to use for the CastSpellOn method?

Share this post


Link to post
Share on other sites

No tested, but use code like:

public static bool CastSpell(Spell spell, WoWUnit unit, bool force)
{
    //	Handle bullshit units
    if (unit == null || !unit.IsValid || unit.IsDead || !spell.KnownSpell || !spell.IsSpellUsable)
    {
        return false;
    }

    //	Check If Toon is Wanding
    if (spell.Name == "Shoot" && IsAutoRepeating("Shoot"))
    {
        return true;
    }

    //	Fuck off if toon is already casting and (force == false)
    if (ObjectManager.Me.IsCast && !force)
        return false;

    //	Stop moving if spell needs to be cast
    if (spell.CastTime > 0)
        MovementManager.StopMoveTo(false, Usefuls.Latency + 500);

    //	Force cast spell if (force == true)
    if (force)
        Lua.LuaDoString("SpellStopCasting();");

    //	Cast AoE spells by location
    if (AreaSpells.Contains(spell.Name))
    {
        Lua.LuaDoString("CastSpellByName(\"" + spell.NameInGame + "\")");
        ClickOnTerrain.Pulse(unit.Position);
    }
    else
    {
        //	Face unit to cast
        if (!unit.IsLocalPlayer)
            MovementManager.Face(unit);

        if (unit.IsLocalPlayer || unit.Type == WoWObjectType.Player)
            SpellManager.CastSpellByNameOn(spell.NameInGame, unit.Name);
        if (unit.IsMyTarget)
            SpellManager.CastSpellByNameOn(spell.NameInGame, "target");
        else
        {
            var old = ObjectManager.Me.MouseOverGuid;
            ObjectManager.Me.MouseOverGuid = unit.Guid;
            SpellManager.CastSpellByNameOn(spell.NameInGame, "mouseover");
            ObjectManager.Me.MouseOverGuid = old;
        }
    }
    return true;
}

 

Share this post


Link to post
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.

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.


×
×
  • Create New...