HB2 crashes when i change targets and at random times in the fight.. Code: public static void ThreadLoop() { while (Styx.Plugins.PluginManager.Plugins.Count() == 0) Thread.Sleep(100); for (int i = 0; i < Styx.Plugins.PluginManager.Plugins.Count(); i++) { myPlugin = Styx.Plugins.PluginManager.Plugins[i]; if (myPlugin.Plugin.PluginName == "Hotkey") break; } while (true) { int Holder2 = 0; Holder2 = Convert.ToInt32(GetAsyncKeyState(Keys.C).ToString()); if (Holder2 == 1 || Holder2 == -32767 || Holder2 == -32768) { Logging.Write(Holder2.ToString()); if (!Me.CurrentTarget.Buffs.ContainsKey("Immolate") ) { if (SpellManager.CanCastSpell("Immolate") && Me.CurrentTarget.HealthPercent > 0) { SpellManager.CastSpell("Immolate"); Logging.Write("Immolate"); } } else { if (SpellManager.CanCastSpell("Conflagrate") && Me.CurrentTarget.HealthPercent > 0) { SpellManager.CastSpell("Conflagrate"); Logging.Write("Conflagrate"); } if (SpellManager.CanCastSpell("Chaos Bolt") && Me.CurrentTarget.HealthPercent > 0) { SpellManager.CastSpell("Chaos Bolt"); Logging.Write("Chaos Bolt"); } if (SpellManager.CanCastSpell("Incinerate") && Me.CurrentTarget.HealthPercent > 0 ) { SpellManager.CastSpell("Incinerate"); Logging.Write("Incinerate"); } } } Thread.Sleep(75); } }
How about this? Code: public static void ThreadLoop() { while (Styx.Plugins.PluginManager.Plugins.Count() == 0) Thread.Sleep(100); for (int i = 0; i < Styx.Plugins.PluginManager.Plugins.Count(); i++) { myPlugin = Styx.Plugins.PluginManager.Plugins[i]; if (myPlugin.Plugin.PluginName == "Hotkey") break; } while (true) { //int Holder2 = 0; int Holder2 = Convert.ToInt32(GetAsyncKeyState(Keys.C).ToString()); if (Holder2 == 1 || Holder2 == -32767 || Holder2 == -32768) { string hold2 = Holder2.ToString; Logging.Write(hold2); if (!Me.CurrentTarget.Buffs.ContainsKey("Immolate") ) { if (SpellManager.CanCastSpell("Immolate") && Me.CurrentTarget.HealthPercent > 0) { SpellManager.CastSpell("Immolate"); Logging.Write("Immolate"); } } else { if (SpellManager.CanCastSpell("Conflagrate") && Me.CurrentTarget.HealthPercent > 0) { SpellManager.CastSpell("Conflagrate"); Logging.Write("Conflagrate"); } if (SpellManager.CanCastSpell("Chaos Bolt") && Me.CurrentTarget.HealthPercent > 0) { SpellManager.CastSpell("Chaos Bolt"); Logging.Write("Chaos Bolt"); } if (SpellManager.CanCastSpell("Incinerate") && Me.CurrentTarget.HealthPercent > 0 ) { SpellManager.CastSpell("Incinerate"); Logging.Write("Incinerate"); } } } Thread.Sleep(75); } } I can't really check the code myself; but post back and tell me if it works. Cheers.
Check if CurrentTarget is null. (Or for the much faster approach; check if CurrentTargetGuid == 0) You're crashing because you're trying to access a property on a null object.
I am tring it right now, asking your advice. would you think this would the best placment for the check? Code: if (Holder == 1 || Holder == -32767 || Holder == -32768) { if ([B]Me.GotTarget && Me.CurrentTarget.CurrentTargetGuid == 0[/B]) { if (Me.ManaPercent > 10) { if (!Me.CurrentTarget.Buffs.ContainsKey("Corruption")) { SpellManager.CastSpell("Corruption"); } if (!Me.CurrentTarget.Buffs.ContainsKey("Curse of Agony")) { SpellManager.CastSpell("Curse of Agony"); } if (!Me.CurrentTarget.Buffs.ContainsKey("Haunt")) { SpellManager.CastSpell("Haunt"); } if (!Me.CurrentTarget.Buffs.ContainsKey("Unstable Affiction")) { SpellManager.CastSpell("Unstable Affiction"); } if (Me.CurrentTarget.HealthPercent > 25) { SpellManager.CastSpell("Shadow Bolt"); } else { SpellManager.CastSpell("Drain Soul"); } } else { SpellManager.CastSpell("Life Tap"); } } BTW thank you for the help
I changed the spell check to make sure it was not another reason it was makiing it crash.. Code: if (Holder == 1 || Holder == -32767 || Holder == -32768) { if (Me.GotTarget && Me.CurrentTarget.CurrentTargetGuid == 0) { Logging.Write(Convert.ToString(Me.CurrentTarget.CurrentTargetGuid)); if (Me.ManaPercent > 10) { if (!Me.CurrentTarget.Buffs.ContainsKey("Corruption")) { SpellManager.CastSpell("Corruption"); } else { if (!Me.CurrentTarget.Buffs.ContainsKey("Curse of Agony")) { SpellManager.CastSpell("Curse of Agony"); } else { if (!Me.CurrentTarget.Buffs.ContainsKey("Haunt")) { SpellManager.CastSpell("Haunt"); } else { if (!Me.CurrentTarget.Buffs.ContainsKey("Unstable Affliction")) { SpellManager.CastSpell("Unstable Affliction"); } else { if (Me.CurrentTarget.HealthPercent > 25) { SpellManager.CastSpell("Shadow Bolt"); } else { SpellManager.CastSpell("Drain Soul"); } } } } } } else { SpellManager.CastSpell("Life Tap"); }
Try: Code: if (Me.GotTarget && !Me.CurrentTarget.CurrentTargetGuid == 0) instead. Your code above is checking to see if the current guid is 0, it should be checking to see that it isn't 0 to proceed.
Code: public static void ThreadLoop() { while (Styx.Plugins.PluginManager.Plugins.Count() == 0) Thread.Sleep(100); for (int i = 0; i < Styx.Plugins.PluginManager.Plugins.Count(); i++) { myPlugin = Styx.Plugins.PluginManager.Plugins[i]; if (myPlugin.Plugin.PluginName == "Hotkey") break; } while (true) { if ((GetAsyncKeyState(Keys.C) & 1) != 0) { if (Me.CurrentTargetGuid != 0) { if (!Me.CurrentTarget.Buffs.ContainsKey("Immolate") ) { if (SpellManager.CanCastSpell("Immolate") && Me.CurrentTarget.HealthPercent > 0) { SpellManager.CastSpell("Immolate"); Logging.Write("Immolate"); } } else { if (SpellManager.CanCastSpell("Conflagrate") && Me.CurrentTarget.HealthPercent > 0) { SpellManager.CastSpell("Conflagrate"); Logging.Write("Conflagrate"); } if (SpellManager.CanCastSpell("Chaos Bolt") && Me.CurrentTarget.HealthPercent > 0) { SpellManager.CastSpell("Chaos Bolt"); Logging.Write("Chaos Bolt"); } if (SpellManager.CanCastSpell("Incinerate") && Me.CurrentTarget.HealthPercent > 0 ) { SpellManager.CastSpell("Incinerate"); Logging.Write("Incinerate"); } } } } Thread.Sleep(100); } }