Jump to content

Recommended Posts

Hello, I created a plugin that when it's not in battleground it goes to the gem vendor and buy a gem if honor is enough, otherwise it goes into a "wait position".

The problem is when he moves, doesnt matter if to go to the vendor or to the wait position, it moves for like 10 yards, then stops, then moves again, then stops and so on.... It's bottish as hell and I don't understand why this behaviour, why doesnt he run all the way to the destination without stopping every 10 steps? I didn't add any sleep in the code.

This is the code

using System;
using robotManager.Products;
using wManager.Plugin;
using wManager.Wow.Enums;
using robotManager.Helpful;
using System.Threading;
using wManager.Wow;
using wManager.Wow.Helpers;
using wManager.Wow.ObjectManager;

public class Main : wManager.Plugin.IPlugin
{
    const int HONORREQUIRED = 10000;
    bool _running;
    public void Initialize()
    {
        _running = true;
        while (_running)
        {
		if (Conditions.InGameAndConnectedAndAliveAndProductStartedNotInPause && !Conditions.IsAttackedAndCannotIgnore && !Battleground.IsInBattleground())
                {
		   		    var zone = Lua.LuaDoString<string>("return GetZoneText()");
                    var h = Lua.LuaDoString<int>("local points = GetHonorCurrency(); return points;");
                    if (h >= HONORREQUIRED && zone == "Stormwind City")
                    {
                       	wManager.Wow.Bot.Tasks.GoToTask.ToPositionAndIntecractWithNpc(new Vector3(-5768.91, 419.931, 103.921), 34081); 
			
			Lua.LuaDoString<int>("BuyMerchantItem(9,1)");
		    }
		    // Wait Position
		    if (h < HONORREQUIRED && zone == "Stormwind City")
		    {
			wManager.Wow.Bot.Tasks.GoToTask.ToPosition(new Vector3(-5814.899, 650.6406, 94.55161));

			
                    }
			
                }
        }
    }

    public void Dispose()
    {
        _running = false;
    }

    public void Settings()
    {
    }
}

Can anyone help me figuring how to fix this? Thanks

Link to comment
https://wrobot.eu/forums/topic/10042-help-with-plugin-working-50-easy/
Share on other sites

wManager.Wow.Bot.Tasks.GoToTask.ToPosition(new Vector3(-5814.899, 650.6406, 94.55161));

 

This code is blocking - but your loop should have a Thread.Sleep anyway to keep your CPU from exploding.
I'm guessing SOMETHING interrupts your code - so add some logging to see if the above quoted code actually returns anything. It probably breaks early, so maybe try an exitCondition for the function call that's basically just if you're getting attacked.
Or do MovementManager.Go(PathFinder.FindPath(vector3)), that will never terminate unless your movement is otherwise interruped (say by fightclass, plugin, etc). On the downside, you need to add a sleep until it reaches the final destination, because it's not blocking.

Edit:
You could also calculate the path ONCE and then just walk it in your loop. Pseudo code below, I don't have a PC right now, just doing this from the top of my head.

using System;
using robotManager.Products;
using wManager.Plugin;
using wManager.Wow.Enums;
using robotManager.Helpful;
using System.Threading;
using wManager.Wow;
using wManager.Wow.Helpers;
using wManager.Wow.ObjectManager;

public class Main : wManager.Plugin.IPlugin
{
    const int HONORREQUIRED = 10000;
    bool _running;
	List<Vector3> pathToFollow = new List<Vector3>();
	
    public void Initialize()
    {
        _running = true;
        while (_running)
        {
			if (Conditions.InGameAndConnectedAndAliveAndProductStartedNotInPause && !Conditions.IsAttackedAndCannotIgnore && !Battleground.IsInBattleground())
			{
				if(!pathToFollow.IsEmpty() && ObjectManager.Me.Position.DistanceTo(pathToFollow[pathToFollow.Count - 1]) > 5)
				{
					MovementManager.Go(pathToFollow);
					//wait until we reach last point or enter combat
					while(ObjectManager.Me.Position.DistanceTo(pathToFollow[pathToFollow.Count - 1]) > 5)
					{
						Thread.Sleep(500);
						if(Conditions.IsAttackedAndCannotIgnore || !Conditions.InGameAndConnectedAndAliveAndProductStartedNotInPause)
						{
							break;
						}
					}
				}
					
				var zone = Lua.LuaDoString<string>("return GetZoneText()");
				var h = Lua.LuaDoString<int>("local points = GetHonorCurrency(); return points;");
				if (h >= HONORREQUIRED && zone == "Stormwind City")
				{
					pathToFollow = PathFinder.FindPath(new Vector3(-5768.91, 419.931, 103.921));
					wManager.Wow.Bot.Tasks.GoToTask.ToPositionAndIntecractWithNpc(new Vector3(-5768.91, 419.931, 103.921), 34081); 
					Lua.LuaDoString<int>("BuyMerchantItem(9,1)");
				}
				// Wait Position
				if (h < HONORREQUIRED && zone == "Stormwind City")
				{
					pathToFollow = PathFinder.FindPath(new Vector3(-5814.899, 650.6406, 94.55161));
					wManager.Wow.Bot.Tasks.GoToTask.ToPosition(new Vector3(-5814.899, 650.6406, 94.55161));
				}
				
			}
			Thread.Sleep(500);
        }
    }

    public void Dispose()
    {
        _running = false;
    }

    public void Settings()
    {
    }
}

 

Edited by Matenia

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...