• Visit Rebornbuddy
  • Visit Panda Profiles
  • Visit LLamamMagic
  • Proper way to hook TreeStart?

    Discussion in 'Community Developer Forum' started by Wheredidigo, Jun 10, 2015.

    1. Wheredidigo

      Wheredidigo Community Developer

      Joined:
      Dec 15, 2013
      Messages:
      417
      Likes Received:
      8
      Trophy Points:
      18
      Mastahg,

      Code:
      private void AddHooks()
      {
      	Logging.Write(Colors.Pink, string.Format("Adding Destiny V{0} Hooks", Version));
      	var counter = 0;
      	foreach (var logic in Logic)
      	{
      		TreeHooks.Instance.InsertHook("TreeStart", counter, logic.Coroutine);
      		counter++;
      	}
      }
      
      Let's say I have the above code in my Plugin. Now let's say someone else has their own Plugin and it is using the same code because we're good developers and share code that works.

      Now let's say random user "X" is using BOTH of our plugins at the same time.

      If there ever becomes a point where the logic for the coroutines of both plugins becomes true at the same time, they will both try and fight each other to decide what to do.

      An example is with my plugin Destiny and Neverdyne's plugin Agil. If the end user is using the Patrol function of Destiny when Agil has decided it is time to go repair at a mender merchant, what ends up happening is Agil calls a MoveTo to get to the mender merchant and Destiny calls a MoveTo to get to the random mob we are passing by...resulting in a never ending loop of trying to fight back and forth.

      My question is this: Is there a safe way to insert a Hook and make sure that you don't get multiple hooks to the same "leaf"? Right now, there's nothing stopping multiple Plugins from hooking to position 0 in the tree...which is what I believe is causing the issue.

      Thanks,

      -Wheredidigo
       
    2. mastahg

      mastahg Administrator Staff Member

      Joined:
      Feb 27, 2011
      Messages:
      5,345
      Likes Received:
      383
      Trophy Points:
      83
      Whos ever is at spot 0 goes first its that simple. If your hook needs to be doing something then it shouldn't be letting the control flow past it and as such there would be no fighting.
       
    3. Wheredidigo

      Wheredidigo Community Developer

      Joined:
      Dec 15, 2013
      Messages:
      417
      Likes Received:
      8
      Trophy Points:
      18
      I guess the question really is: "What happens when 2 different Plugins Insert a Hook at spot 0?" Is it a matter of whichever routine inserted the hook at Spot 0 Last is the winner?
       
    4. mastahg

      mastahg Administrator Staff Member

      Joined:
      Feb 27, 2011
      Messages:
      5,345
      Likes Received:
      383
      Trophy Points:
      83
      Yep.
       
    5. Wheredidigo

      Wheredidigo Community Developer

      Joined:
      Dec 15, 2013
      Messages:
      417
      Likes Received:
      8
      Trophy Points:
      18
      Perfect. Thank you sir.
       

    Share This Page