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

Me.GotTarget Help

zapman

Member
Joined
Jan 15, 2010
Messages
95
Reaction score
18
I'm trying to get if my target is a RepairMerchant or not. The code below almost returns "You dont have any target" all the time, although I got a target. Sometimes when I start the bot, it works :confused:. Anyone got a clue what I could have done wrong here?

Code:
            //IsRepairMerchant
            if (ObjectManager.Me.GotTarget == true)
            {
                if (ObjectManager.Me.CurrentTarget.IsRepairMerchant == true)
                {<vendor name="\&quot;{0}\&quot;" entry="\&quot;{1}\&quot;" type="\&quot;{2}\&quot;" x="\&quot;{3}\&quot;" y="\&quot;{4}\&quot;" z="\&quot;{5}\&quot;">
                }
                else
                {
                }
            }
            else if (ObjectManager.Me.GotTarget != true)
            {
            }
</vendor>
 
I'm trying to get if my target is a RepairMerchant or not. The code below almost returns "You dont have any target" all the time, although I got a target. Sometimes when I start the bot, it works :confused:. Anyone got a clue what I could have done wrong here?

This is a wild guess, as the fragment isn't enough to make the determination, but...

My guess is that you're not 'returning to the Honorbuddy core' to allow it to update the ObjectManager state between the time you acquire the target and the time you run this fragment.

You can force it, by calling ObjectManager.Upate(), but that is wrong to do 100% of the time. If you need to call Update() to have your code work, it says you need to refactor your code. If you throw in Update() and leave it there (i.e., not refactoring), I guarantee you will have horrible problems in other ways later on. What's worse is that doing this can adversely affect other things running at the same time--such as Plugins and such.

cheers & good luck with it,
chinajade
 
Thanks a lot chinajade! You were right about the update! This code was located in a button that I had on my plugin GUI and when the bot is turned off I guess the ObjectManager dose not get updated? Now if I set the bot to Combat / Healbot everything works well!
 
Last edited:
Chinajade isn't *entirely* correct.

While its usually bad to force our object manager to update, there are cases where you just plain need to. (I won't go over the many ways, but anything that returns a .NET object, usually requires some form of object manager update. Any static-ish properties are usually volatile. [E.g. Me.HealthPercent can, and usually will, be a volatile read, where it is always correct, so long as 'Me' is correct. Hint: Me should rarely, if ever, change. This is excluding loading screens of course.])

However; in your case, you just don't want to do what you were doing. :)
 
Chinajade isn't *entirely* correct.

While its usually bad to force our object manager to update, there are cases where you just plain need to. (I won't go over the many ways, but anything that returns a .NET object, usually requires some form of object manager update. Any static-ish properties are usually volatile. [E.g. Me.HealthPercent can, and usually will, be a volatile read, where it is always correct, so long as 'Me' is correct. Hint: Me should rarely, if ever, change. This is excluding loading screens of course.])

However; in your case, you just don't want to do what you were doing. :)

Thanks Apoc! That made me understand it better! Mutch appreciated :)
 
You are also right in updating it from the GUI if you need to use the API from the GUI - we also do that!
 
Back
Top