Jump to content

Check whether an item is usable


Seminko

Recommended Posts

Heya,

I have a working script that will use a Mana Agate when on 10% mana and create a new one.

The issue is Mana Agate has a cooldown. How do I check whether it is off cooldown?

I google a bit and came up with this, but something is off:

bool spellName = Lua.LuaDoString<bool>("start, duration, enable = GetActionCooldown(37); return enable;");
if (ObjectManager.Me.ManaPercentage < 10 && ItemsManager.HasItemById(5514) && spellName)
{
	ItemsManager.UseItem(5514);
	Thread.Sleep(Usefuls.Latency + 1300);
}

 

Link to comment
Share on other sites

Hello, with code like:

        string s = wManager.Wow.Helpers.ItemsManager.GetItemSpell(5514);
        if (!string.IsNullOrWhiteSpace(s))
        {
            bool isUsable = wManager.Wow.Helpers.SpellManager.SpellUsableLUA(s);
        }

 

Link to comment
Share on other sites

8 hours ago, Droidz said:

Hello, with code like:


        string s = wManager.Wow.Helpers.ItemsManager.GetItemSpell(5514);
        if (!string.IsNullOrWhiteSpace(s))
        {
            bool isUsable = wManager.Wow.Helpers.SpellManager.SpellUsableLUA(s);
        }

 

I'm a C# virgin, please bear with me.

It says that isUsable doesn't exist in the current context. Does that mean that 'string.IsNullOrWhiteSpace(s)' returned true?

Here's my code:

string s = wManager.Wow.Helpers.ItemsManager.GetItemSpell(5514);
if (!string.IsNullOrWhiteSpace(s))
{
	bool isUsable = wManager.Wow.Helpers.SpellManager.SpellUsableLUA(s);
}
if (ObjectManager.Me.ManaPercentage < 10 && ItemsManager.HasItemById(5514) && isUsable)
{
	ItemsManager.UseItem(5514);
	Logging.WriteDebug("Using Mana Agate");
	Thread.Sleep(Usefuls.Latency + 1500);
}

 

Link to comment
Share on other sites

32 minutes ago, Seminko said:

I'm a C# virgin, please bear with me.

It says that isUsable doesn't exist in the current context. Does that mean that 'string.IsNullOrWhiteSpace(s)' returned true?

Here's my code:


string s = wManager.Wow.Helpers.ItemsManager.GetItemSpell(5514);
if (!string.IsNullOrWhiteSpace(s))
{
	bool isUsable = wManager.Wow.Helpers.SpellManager.SpellUsableLUA(s);
}
if (ObjectManager.Me.ManaPercentage < 10 && ItemsManager.HasItemById(5514) && isUsable)
{
	ItemsManager.UseItem(5514);
	Logging.WriteDebug("Using Mana Agate");
	Thread.Sleep(Usefuls.Latency + 1500);
}

 

EDIT: it seems that GetItemSpell did not exist in vanilla? Sorry for not mentioning it.

isUsable is declared in the "if" so everything outside the "if" can't see the variable

string s = wManager.Wow.Helpers.ItemsManager.GetItemSpell(5514);
bool isUsable = false;
if (!string.IsNullOrWhiteSpace(s))
{
    // Set
	isUsable = wManager.Wow.Helpers.SpellManager.SpellUsableLUA(s);
}
if (ObjectManager.Me.ManaPercentage < 10 && ItemsManager.HasItemById(5514) && isUsable)
{
	ItemsManager.UseItem(5514);
	Logging.WriteDebug("Using Mana Agate");
	Thread.Sleep(Usefuls.Latency + 1500);
}

Give it a try.

Link to comment
Share on other sites

1 hour ago, iMod said:

isUsable is declared in the "if" so everything outside the "if" can't see the variable

Give it a try.

Is this how Csharp works? Wow, that's strange...

Nevertheless, still no go --> not all code paths return a value

Link to comment
Share on other sites

28 minutes ago, Seminko said:

Is this how Csharp works? Wow, that's strange...

Nevertheless, still no go --> not all code paths return a value

Yes thats how csharp works :D can't find some strange stuff. If you are walking in the left room you are not able to see what happens in the right one.

Well if you need a return value

string s = wManager.Wow.Helpers.ItemsManager.GetItemSpell(5514);
bool isUsable = false;
if (!string.IsNullOrWhiteSpace(s))
{
    // Set
	isUsable = wManager.Wow.Helpers.SpellManager.SpellUsableLUA(s);
}
if (ObjectManager.Me.ManaPercentage < 10 && ItemsManager.HasItemById(5514) && isUsable)
{
	ItemsManager.UseItem(5514);
	Logging.WriteDebug("Using Mana Agate");
	Thread.Sleep(Usefuls.Latency + 1500);
}

// Return
return isUsable;

 

29 minutes ago, Seminko said:

BTW, why are we using SpellUsable when we want to check if an ITEM is usable? --- Mana Agate has a CD

Maybe because its a spell at the end and handled like this way. I'm not that familar with items so i can't say that much.

Link to comment
Share on other sites

2 minutes ago, iMod said:

Yes thats how csharp works :D can't find some strange stuff. If you are walking in the left room you are not able to see what happens in the right one.

Well if you need a return value

Omg, you're right, I accidentaly deleted return true.

Back to Csharp, I'm quite familiar with AutoIt and when you declare a variable it can be reached from anywhere in the whole script, that's why i'm so confused. :)

 

Now i tried finding out the issue but it seems even though I have the item and the item is usable it returns false:

			string s = wManager.Wow.Helpers.ItemsManager.GetItemSpell(5514);
			bool isUsable = false;
			if (!string.IsNullOrWhiteSpace(s))
			{
				isUsable = wManager.Wow.Helpers.SpellManager.SpellUsableLUA(s);
			}
			else
			{
				Logging.WriteDebug("Error1");
			}
			if (isUsable) //(ObjectManager.Me.ManaPercentage < 10 && ItemsManager.HasItemById(5514) && isUsable)
			{
				ItemsManager.UseItem(5514);
				Logging.WriteDebug("Using Mana Agate");
				Thread.Sleep(Usefuls.Latency + 1500);
			}
			else
			{
				Logging.WriteDebug("Error2");
			}

 

Link to comment
Share on other sites

Just now, Seminko said:

Omg, you're right, I accidentaly deleted return true.

Back to Csharp, I'm quite familiar with AutoIt and when you declare a variable it can be reached from anywhere in the whole script, that's why i'm so confused. :)

 

Now i tried finding out the issue but it seems even though I have the item and the item is usable it returns false:


			string s = wManager.Wow.Helpers.ItemsManager.GetItemSpell(5514);
			bool isUsable = false;
			if (!string.IsNullOrWhiteSpace(s))
			{
				isUsable = wManager.Wow.Helpers.SpellManager.SpellUsableLUA(s);
			}
			else
			{
				Logging.WriteDebug("Error1");
			}
			if (isUsable) //(ObjectManager.Me.ManaPercentage < 10 && ItemsManager.HasItemById(5514) && isUsable)
			{
				ItemsManager.UseItem(5514);
				Logging.WriteDebug("Using Mana Agate");
				Thread.Sleep(Usefuls.Latency + 1500);
			}
			else
			{
				Logging.WriteDebug("Error2");
			}

 

C# is a object oriented programming language and not a script language.
Just use the developer tool in the bot and test your c# conditions with it and you will find out what returns false.

Link to comment
Share on other sites

Just now, iMod said:

C# is a object oriented programming language and not a script language.
Just use the developer tool in the bot and test your c# conditions with it and you will find out what returns false.

isUsable returns false
Link to comment
Share on other sites

Just now, Seminko said:

isUsable returns false

replace
 

isUsable = wManager.Wow.Helpers.SpellManager.SpellUsableLUA(s);


with
 

isUsable = Lua.LuaDoString<bool>(string.Format("local isUsable, notEnoughMana = IsUsableItem({0}); return isUsable;", s));

and give it a try

Link to comment
Share on other sites

3 minutes ago, iMod said:

replace
 


isUsable = wManager.Wow.Helpers.SpellManager.SpellUsableLUA(s);


with
 


isUsable = Lua.LuaDoString<bool>(string.Format("local isUsable, notEnoughMana = IsUsableItem({0}); return isUsable;", s));

and give it a try

IsUsableItem does not seem to exist in Vanilla. The closest to I was able to find for vanilla is GetActionCooldown

Not sure how to structure it though.

Link to comment
Share on other sites

1 minute ago, Seminko said:

IsUsableItem does not seem to exist in Vanilla. The closest to I was able to find for vanilla is GetActionCooldown

Oh Vanilla, sorry then i'm out ;) I have no clue about Vanilla.

Link to comment
Share on other sites

9 hours ago, Droidz said:

Hello, with code like:


        string s = wManager.Wow.Helpers.ItemsManager.GetItemSpell(5514);
        if (!string.IsNullOrWhiteSpace(s))
        {
            bool isUsable = wManager.Wow.Helpers.SpellManager.SpellUsableLUA(s);
        }

 

I think we need to use GetActionCooldown --> http://wowprogramming.com/docs/api/GetActionCooldown

Link to comment
Share on other sites

@Droidz Alright, so updated your script but it still says it's not usable for some reason:

string s = wManager.Wow.Helpers.ItemsManager.GetItemSpell(5514);
if (!string.IsNullOrWhiteSpace(s))
{
	bool isUsable = wManager.Wow.Helpers.SpellManager.SpellUsableLUA(s);
	if (isUsable)
	{
		Logging.WriteDebug("Usable");
	}
	else
	{
		Logging.WriteDebug("Not usable");
	}
}

 

Link to comment
Share on other sites

@Droidz @iMod guys save me, this is now not related to vanilla or retail.

I solved the problem using Timer but for that to work I had to scrap the static bool Pulse and put everything under the main routine.

It works great, unfortunately, something got probably wrong with Dispose since when I click the stop button in the bot GUI, it crashes.

HELP!

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using System.ComponentModel;
using System.Diagnostics;
using System.Threading;

using robotManager.Helpful;
using robotManager.Products;

using wManager.Wow.Helpers;
using wManager.Wow.ObjectManager;

using Timer = robotManager.Helpful.Timer;

public class CustomProfile : Custom_Profile.ICustomProfile
{
	private const int CastEverySeconds = 120;
	private bool _isRunning;
    private Timer _timer;
    public void Pulse()
    {
		try
        {
            while (wManager.Wow.Helpers.Conditions.ProductIsStarted)
			{
				if (wManager.Wow.Helpers.Conditions.InGameAndConnectedAndAliveAndProductStartedNotInPause)
				{
					try
					{
						if (!ObjectManager.Me.HaveBuff("Arcane Intellect") && !ObjectManager.Me.InCombat && !ObjectManager.Me.IsMounted && SpellManager.SpellUsableLUA("Arcane Intellect"))
						{
							SpellManager.CastSpellByNameLUA("Arcane Intellect", true);
							Logging.WriteDebug("Buffed [Arcane Intellect]");
							Thread.Sleep(Usefuls.Latency + 1500);
						}
						if (!ObjectManager.Me.HaveBuff("Ice Armor") && !ObjectManager.Me.IsMounted && SpellManager.SpellUsableLUA("Ice Armor") && !ObjectManager.Me.InCombat)
						{
							SpellManager.CastSpellByNameLUA("Ice Armor");
							Logging.WriteDebug("Buffed [Ice Armor]");
							Thread.Sleep(Usefuls.Latency + 1500);
						}
						if (!ObjectManager.Me.HaveBuff("Dampen Magic") && !ObjectManager.Me.InCombat && !ObjectManager.Me.IsMounted && SpellManager.SpellUsableLUA("Dampen Magic"))
						{
							SpellManager.CastSpellByNameLUA("Dampen Magic", true);
							Logging.WriteDebug("Buffed [Dampen Magic]");
							Thread.Sleep(Usefuls.Latency + 1500);
						}
						if (!ItemsManager.HasItemById(5514) && !ObjectManager.Me.InCombat && !ObjectManager.Me.IsMounted && SpellManager.SpellUsableLUA("Conjure Mana Agate"))
						{
							SpellManager.CastSpellByNameLUA("Conjure Mana Agate");
							Logging.WriteDebug("Conjure Mana Agate");
							Thread.Sleep(Usefuls.Latency + 2000);
						}
						if (ItemsManager.HasItemById(5514) && !ObjectManager.Me.IsMounted && ObjectManager.Me.ManaPercentage < 15 && (_timer == null || _timer.IsReady))
						{
							ItemsManager.UseItem(5514);
							_timer = new Timer(CastEverySeconds * 1000);
							Logging.WriteDebug("Using Mana Agate");
							Thread.Sleep(Usefuls.Latency + 1500);
						}
					}
					catch (Exception e)
					{
						try
						{
							Dispose();
						}
						catch
						{
						}
						Logging.WriteError("Buffer > Pulse(): " + e);
						Products.ProductStop();
					}
				}
				Thread.Sleep(Usefuls.Latency + 1000);
			}
        }
        catch (Exception e)
        {
            Logging.WriteError("CustomProfile > Pulse(): " + e);
        }
    }

    public void Dispose()
    {
        try
        {
            Dispose();
        }
        catch (Exception e)
        {
            Logging.WriteError("CustomProfile > Dispose(): " + e);
        }
    }
}

 

Link to comment
Share on other sites

  • 4 months later...
6 hours ago, valetine said:

hello,did you solved this issue?

I use timer for these. So basically this:

						if (ItemsManager.HasItemById(5514) && !ObjectManager.Me.IsMounted && ObjectManager.Me.ManaPercentage < 15 && (_timer == null || _timer.IsReady))
						{
							ItemsManager.UseItem(5514);
							_timer = new Timer(CastEverySeconds * 1000);
							Logging.WriteDebug("Using Mana Agate");
							Thread.Sleep(Usefuls.Latency + 1500);
						}

 

Link to comment
Share on other sites

  • 1 year later...

I know this post is from 2017 but i thought this may help

GetItemInfo(itemID or "itemString" or "itemName" or "itemLink")
Lua.LuaDoString<bool>("if GetItemCooldown('Hearthstone') == 0 then return true else return false end")

you can use this method also 

Lua.LuaDoString<bool>("if GetItemCooldown("+"Hearthstone"+") == 0 then return true else return false end")

it works within a string. tested

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...