What's new
  • Visit Rebornbuddy
  • Visit Panda Profiles
  • Visit LLamamMagic
  • Visit Resources
  • Visit Downloads
  • Visit Portal

Check if HasAura() is from me or not?

Kloppe

New Member
Joined
Apr 22, 2012
Messages
57
Reaction score
0
How do I check if the HasAura("spells name") is from me or another player?
 
How do I check if the HasAura("spells name") is from me or another player?

You need to check the guid of the aura against your guid.

For exact details: code in visual studios, use intellisense, win
 
Thanks kaihaider

I try to use a code like this (Ultimate PvP Suite Plugin by Phelon):

Code:
		private static WoWPlayer AddedCheck()
        {
            return (from Unit in ObjectManager.GetObjectsOfType<WoWPlayer>(false)
                    orderby Unit.HealthPercent
                    where Unit.IsAlive
                    where Unit.IsPlayer
                    where Unit.Distance < 20
                    where !Unit.IsFriendly
                    where !Unit.IsPet
                    where Unit.InLineOfSpellSight
                    where !Unit.HasAura("Spell Name")
                    [B]where Unit.ActiveAuras["Spell Name"].CreatorGuid != Me.Guid[/B]
                    select Unit).LastOrDefault();
        }

The HasAura will work fine, but the check if the guid is from me gives me:
Code:
[BGBuddy PVP Suite] Targetting Error: System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
   at System.ThrowHelper.ThrowKeyNotFoundException()
   at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
   at BGBuddyPVPSuite.Targeting.<AddedCheck>b__c(WoWPlayer Unit) in c:\U\Honorbuddy_2.0.0.5883\Plugins\pvp\Targeting.cs:line 118
   at System.Linq.Enumerable.<>c__DisplayClassf`1.<CombinePredicates>b__e(TSource x)
   at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
   at System.Linq.Enumerable.LastOrDefault[TSource](IEnumerable`1 source)
   at BGBuddyPVPSuite.Targeting.AddedCheck() in c:\U\Honorbuddy_2.0.0.5883\Plugins\pvp\Targeting.cs:line 109
   at BGBuddyPVPSuite.Targeting.PulseTargeting() in c:\U\Honorbuddy_2.0.0.5883\Plugins\pvp\Targeting.cs:line 88
I can compile the plugin, but upon running I get that error.
 
you might be missing an include

can I see your code?

edit: also, you can attach honorbuddy as a process in visual studios, then when the error pops it will tell you exactly where it is, and it generally has a list of possible fixes if you click on a floating icon that pops up. Makes it really really easy to fix errors :D
 
Last edited:
Code:
        private bool IsMyAuraActive(WoWUnit Who, String What)
        {
            return Who.GetAllAuras().FirstOrDefault(p => p.CreatorGuid == Me.Guid && p.Name == What) != null;
        }
Use this.
 
I don't want to copy paste another mans work, I edit targeting.cs from http://www.thebuddyforum.com/honorbuddy-forum/plugins/pvp/51190-plugin-ultimate-pvp-suite.html
I just add:
Code:
where !Unit.HasAura("Corruption")
where Unit.ActiveAuras["Corruption"].CreatorGuid != Me.Guid

And to a routine among the other where like:

Code:
		private static WoWPlayer EnemyNewbie()
        {
            return (from Unit in ObjectManager.GetObjectsOfType<WoWPlayer>(false)
                    orderby Unit.HealthPercent
                    where Unit.IsAlive
                    where Unit.IsPlayer
                    where Unit.Distance < 39
                    where !Unit.IsFriendly
                    where !Unit.IsPet
                    where Unit.InLineOfSpellSight
                    where !Unit.HasAura("Corruption")
                    where Unit.ActiveAuras["Corruption"].CreatorGuid != Me.Guid
                    select Unit).FirstOrDefault();
        }

That about MSVS I didn't know, have to look into that.
 
Don't worry so much about copying someone's code. The license under which code is released here just states that you must give credit when you use someone's code. It would suck if someone jacked your whole project, but it is really meant for honest people like you that want to learn and try something new.

Also, for a method like this, it is always good to take in a spell name. A HasMyAura method is an integral part of any CC.
 
Try these, will return your aura timeleft. Return 0 if aura expire or no exists
#region MyCreatedAuraTimeLeft
private double MyCreatedAuraTimeLeft(string auraName, WoWUnit unit)
{
using (new FrameLock())
{
if (unit == null)
return 0;

WoWAura aura = (from a in unit.Auras
where a.Value.CreatorGuid == Me.Guid &&
0 == string.Compare(a.Value.Name, auraName, true)
select a.Value).FirstOrDefault();

if (aura == null)
{
return 0;
}
else
{
return aura.TimeLeft.TotalMilliseconds;
}
}
}
#endregion

#region MyCreatedAuraStackCount
private double MyCreatedAuraStackCount(string auraName, WoWUnit unit)
{
using (new FrameLock())
{
if (unit == null)
return 0;

WoWAura aura = (from a in unit.Auras
where a.Value.CreatorGuid == Me.Guid &&
0 == string.Compare(a.Value.Name, auraName, true)
select a.Value).FirstOrDefault();

if (aura == null)
{
return 0;
}
else
{
return aura.StackCount;
}
}
}
#endregion
 
I don't want to copy paste another mans work<wowplayer>
we're talkin bout a simple LINQ expression, or if u prefer the easy way with time-consuming loops the it is a simple for each
nothing to give credits.
U should give credits (to prevent any problems, but u don't have to in this case)
</wowplayer>If using code from another CC, you must give credit for the code. No questions asked. [Simple snippets, such as object searches, simple Lua calls, etc, may be excluded]
Source: http://www.thebuddyforum.com/honorb.../12433-rules-cc-plugin-development-rules.html

There're not very much ways to write this snippet.
Who should we give credits for this? :) but...
that'S another topic<wowplayer>

Mastahg and tuanha gave u two good examples how to check this :)

</wowplayer>
 
though you may have accomplished what you needed based on other code, just so you are aware, when you do
Code:
where [B]![/B]Unit.HasAura("Corruption")
where Unit.ActiveAuras["Corruption"].CreatorGuid != Me.Guid
you're saying "when the unit does not have corruption" AND "the unit's corruption aura was created by me". you're trying to get information about the corruption aura when you've explicitly specified that the unit not have the corruption aura, which is why you got [BGBuddy PVP Suite] Targetting Error: System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
You simply want to remove the negation operator "!"
 
Back
Top