Seminko 41 Posted July 2, 2017 Share Posted July 2, 2017 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 https://wrobot.eu/forums/topic/6346-check-whether-an-item-is-usable/ Share on other sites More sharing options...
Droidz 2755 Posted July 3, 2017 Share Posted July 3, 2017 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 https://wrobot.eu/forums/topic/6346-check-whether-an-item-is-usable/#findComment-28764 Share on other sites More sharing options...
Seminko 41 Posted July 3, 2017 Author Share Posted July 3, 2017 On 7/3/2017 at 9:58 AM, 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); } Expand 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 https://wrobot.eu/forums/topic/6346-check-whether-an-item-is-usable/#findComment-28782 Share on other sites More sharing options...
iMod 99 Posted July 3, 2017 Share Posted July 3, 2017 On 7/3/2017 at 4:14 PM, 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. Expand 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 https://wrobot.eu/forums/topic/6346-check-whether-an-item-is-usable/#findComment-28786 Share on other sites More sharing options...
Seminko 41 Posted July 3, 2017 Author Share Posted July 3, 2017 On 7/3/2017 at 4:45 PM, iMod said: isUsable is declared in the "if" so everything outside the "if" can't see the variable Give it a try. Expand Is this how Csharp works? Wow, that's strange... Nevertheless, still no go --> not all code paths return a value Link to comment https://wrobot.eu/forums/topic/6346-check-whether-an-item-is-usable/#findComment-28787 Share on other sites More sharing options...
Seminko 41 Posted July 3, 2017 Author Share Posted July 3, 2017 BTW, why are we using SpellUsable when we want to check if an ITEM is usable? --- Mana Agate has a CD Link to comment https://wrobot.eu/forums/topic/6346-check-whether-an-item-is-usable/#findComment-28788 Share on other sites More sharing options...
iMod 99 Posted July 3, 2017 Share Posted July 3, 2017 On 7/3/2017 at 6:12 PM, Seminko said: Is this how Csharp works? Wow, that's strange... Nevertheless, still no go --> not all code paths return a value Expand 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; On 7/3/2017 at 6:15 PM, Seminko said: BTW, why are we using SpellUsable when we want to check if an ITEM is usable? --- Mana Agate has a CD Expand 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 https://wrobot.eu/forums/topic/6346-check-whether-an-item-is-usable/#findComment-28789 Share on other sites More sharing options...
Seminko 41 Posted July 3, 2017 Author Share Posted July 3, 2017 On 7/3/2017 at 6:45 PM, 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 Expand 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 https://wrobot.eu/forums/topic/6346-check-whether-an-item-is-usable/#findComment-28790 Share on other sites More sharing options...
iMod 99 Posted July 3, 2017 Share Posted July 3, 2017 On 7/3/2017 at 6:53 PM, 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"); } Expand 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 https://wrobot.eu/forums/topic/6346-check-whether-an-item-is-usable/#findComment-28791 Share on other sites More sharing options...
Seminko 41 Posted July 3, 2017 Author Share Posted July 3, 2017 On 7/3/2017 at 6:59 PM, 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. Expand isUsable returns false Link to comment https://wrobot.eu/forums/topic/6346-check-whether-an-item-is-usable/#findComment-28792 Share on other sites More sharing options...
iMod 99 Posted July 3, 2017 Share Posted July 3, 2017 On 7/3/2017 at 7:00 PM, Seminko said: isUsable returns false Expand 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 https://wrobot.eu/forums/topic/6346-check-whether-an-item-is-usable/#findComment-28793 Share on other sites More sharing options...
Seminko 41 Posted July 3, 2017 Author Share Posted July 3, 2017 On 7/3/2017 at 7:05 PM, 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 Expand 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 https://wrobot.eu/forums/topic/6346-check-whether-an-item-is-usable/#findComment-28794 Share on other sites More sharing options...
iMod 99 Posted July 3, 2017 Share Posted July 3, 2017 On 7/3/2017 at 7:08 PM, Seminko said: IsUsableItem does not seem to exist in Vanilla. The closest to I was able to find for vanilla is GetActionCooldown Expand Oh Vanilla, sorry then i'm out ;) I have no clue about Vanilla. Link to comment https://wrobot.eu/forums/topic/6346-check-whether-an-item-is-usable/#findComment-28795 Share on other sites More sharing options...
Seminko 41 Posted July 3, 2017 Author Share Posted July 3, 2017 Oh damn... I thought we were on to sth... well, thanks anyways Link to comment https://wrobot.eu/forums/topic/6346-check-whether-an-item-is-usable/#findComment-28796 Share on other sites More sharing options...
Seminko 41 Posted July 3, 2017 Author Share Posted July 3, 2017 On 7/3/2017 at 9:58 AM, 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); } Expand I think we need to use GetActionCooldown --> http://wowprogramming.com/docs/api/GetActionCooldown Link to comment https://wrobot.eu/forums/topic/6346-check-whether-an-item-is-usable/#findComment-28799 Share on other sites More sharing options...
Seminko 41 Posted July 3, 2017 Author Share Posted July 3, 2017 @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 https://wrobot.eu/forums/topic/6346-check-whether-an-item-is-usable/#findComment-28800 Share on other sites More sharing options...
Seminko 41 Posted July 4, 2017 Author Share Posted July 4, 2017 @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 https://wrobot.eu/forums/topic/6346-check-whether-an-item-is-usable/#findComment-28844 Share on other sites More sharing options...
reapler 154 Posted July 4, 2017 Share Posted July 4, 2017 @Seminko It crashes because you are looping the Dispose method(you call Dispose from Gui and this method calls itself again & again). Just remove Dispose(); in method "public void Dispose()". Link to comment https://wrobot.eu/forums/topic/6346-check-whether-an-item-is-usable/#findComment-28845 Share on other sites More sharing options...
Seminko 41 Posted July 4, 2017 Author Share Posted July 4, 2017 Omg, that's it! Thanks @reapler ! Link to comment https://wrobot.eu/forums/topic/6346-check-whether-an-item-is-usable/#findComment-28846 Share on other sites More sharing options...
valetine 4 Posted November 15, 2017 Share Posted November 15, 2017 On 7/4/2017 at 4:58 PM, Seminko said: Omg, that's it! Thanks @reapler ! Expand hello,did you solved this issue? Link to comment https://wrobot.eu/forums/topic/6346-check-whether-an-item-is-usable/#findComment-35037 Share on other sites More sharing options...
Seminko 41 Posted November 15, 2017 Author Share Posted November 15, 2017 On 11/15/2017 at 1:07 AM, valetine said: hello,did you solved this issue? Expand 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 https://wrobot.eu/forums/topic/6346-check-whether-an-item-is-usable/#findComment-35044 Share on other sites More sharing options...
TheSmokie 242 Posted October 21, 2019 Share Posted October 21, 2019 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 https://wrobot.eu/forums/topic/6346-check-whether-an-item-is-usable/#findComment-56034 Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now