Jump to content

fly away if you meet a specific player


Pudge
 Share

Recommended Posts

Hi guys, I'm editing Roboalert, or rather I'm trying to add a method thanks to which the bot will fly to a certain point if it meets a certain player (bot catcher)

    public void LeavePlace()
    {
        robotManager.Events.FiniteStateMachineEvents.OnRunState += (FiniteStateMachineEvents.FSMEngineStateCancelableHandler)((engine, state, cancelable) =>
        {
                Vector3 newpos = new Vector3()
                {
                    X = 5296.862f,
                    Y = 974.8112f,
                    Z = 447.8605f,
                    Type = "Flying"
                };
                Logging.Write("Leave");
                wManager.Wow.Helpers.LongMove.LongMoveByNewThread(newpos);
                if (wManager.Wow.Helpers.LongMove.IsLongMove)
                {
                    Thread.Sleep(20000);
                    Logging.Write("летим");
                }
                
            
        });
    }

I tried to put everything in one method, but it turned out - some shit 

Link to comment
Share on other sites

tried to use this code but it doesn't work at all

 

maybe instead 

 robotManager.Events.FiniteStateMachineEvents.OnRunState += (FiniteStateMachineEvents.FSMEngineStateCancelableHandler)((engine, state, cancelable) =>

 

Will some other code work? Any ideas pls...

Link to comment
Share on other sites

private void initializeEnemiesList()
    {
        if (_settings.enemyAlertEnabled)
        {
            string[] enemySplit = _settings.enemyNamesList.Split(',');
            myEnemyList = new List<string>(enemySplit);
        }

    }
 public void enemyAlert()
    {

        var enemiesNearMe = GetEnemiesNearMe(_settings.enemyScanRange, myEnemyList);
        if (!(ObjectManager.Me.InCombatFlagOnly) && enemiesNearMe.Count > 0 && (DateTime.Now > nextEnemyAlertTime))
        {
            nextEnemyAlertTime = DateTime.Now.AddSeconds(_settings.enemyAlertWaitTime);
            var enemyNames = "";
            foreach (var enemy in enemiesNearMe)
            {
                enemyNames += (enemy.Name + " ");
            }
            moveto();
            Logging.Write("[RoboAlert] Enemies Near Me ");
			wManager.Wow.Helpers.Lua.LuaDoString("BasicScriptErrors:SetScale(6) if BasicScriptErrors:IsShown() then BasicScriptErrors:Hide() end message('HATER "  + enemyNames + "')");

    }

    private void moveto()
    {
        wManager.Events.FightEvents.OnFightLoop += delegate (WoWUnit unit, CancelEventArgs cancelable)
        {
            var enemiesNearMe = GetEnemiesNearMe(_settings.enemyScanRange, myEnemyList);
            if (enemiesNearMe.Count > 0)
    {
                var toPosition = new Vector3(4286.155, -884.4277, 251.7935, "Flying");
                wManager.Wow.Helpers.MovementManager.MoveTo(toPosition);
                while (wManager.Wow.Helpers.MovementManager.InMoveTo && toPosition.DistanceTo(wManager.Wow.ObjectManager.ObjectManager.Me.Position) > 17)
                {
                    System.Threading.Thread.Sleep(10000);
                }
            }
        };
    }

What code could be placed in the body of the method moveto() so that the bot flew to a specific point if the enemy suddenly appeared nearby, And after that the bot returned

Link to comment
Share on other sites

Hi,

No tested but try code like:

    public void Initialize()
    {
        if (_settings.enemyAlertEnabled)
        {
            string[] enemySplit = _settings.enemyNamesList.Split(',');
            myEnemyList = new List<string>(enemySplit);
            robotManager.Events.FiniteStateMachineEvents.OnBeforeCheckIfNeedToRunState += delegate (Engine engine, State state, CancelEventArgs cancelable)
            {
                if (!(state is wManager.Wow.Bot.States.IsAttacked))
                    return;

                moveto();
            };


            wManager.Events.FightEvents.OnFightLoop += delegate (WoWUnit unit, CancelEventArgs cancelable) { moveto(); };
        }

    }
    private void moveto()
    {
        wManager.Events.FightEvents.OnFightLoop += delegate (WoWUnit unit, CancelEventArgs cancelable)
        {
            var enemiesNearMe = GetEnemiesNearMe(_settings.enemyScanRange, myEnemyList);
            if (enemiesNearMe.Count > 0)
            {
                var toPosition = new Vector3(4286.155, -884.4277, 251.7935, "Flying");
                LongMove.LongMoveGo(toPosition);
            }
        };
    }

 

Link to comment
Share on other sites

It’s very strange, sometimes the code works (flies as expected), but in 80% of cases it just farm on, although there is a player next to whom the proc works, sometimes (after loot) it just becomes afk and does nothing.

 

Link to comment
Share on other sites

    public void Initialize()
    {
            if (_settings.enemyAlertEnabled)
            {
                string[] enemySplit = _settings.enemyNamesList.Split(',');
                myEnemyList = new List<string>(enemySplit);
                robotManager.Events.FiniteStateMachineEvents.OnBeforeCheckIfNeedToRunState += delegate (Engine engine, State state, CancelEventArgs cancelable)
                {
                    if (!(state is wManager.Wow.Bot.States.IsAttacked) || ObjectManager.Me.InCombat || ObjectManager.Me.IsCast || ObjectManager.Me.IsLooting())
                        return;
                            while (!wManager.Wow.Helpers.Conditions.IsAttackedAndCannotIgnore)
                            {
                               var enemiesNearMe = GetEnemiesNearMe(_settings.enemyScanRange, myEnemyList);
                               if (enemiesNearMe.Count > 0 && GetUnitsNearMe(50).Count == 0)
                               {
                                    moveto();
                                    Thread.Sleep(200);
                               }
                            }


                };
            }

  

}

    private void moveto()
    {
                wManager.Events.FightEvents.OnFightLoop += delegate (WoWUnit unit, CancelEventArgs cancelable)
                {
                    var toPosition = new Vector3(4286.155, -884.4277, 251.7935, "Flying");
                    LongMove.LongMoveGo(toPosition);
                };        
    }
    public List<WoWUnit> GetUnitsNearMe(int range)
    {
        List<WoWUnit> GetUnitsNearMe = wManager.Wow.ObjectManager.ObjectManager.GetWoWUnitHostile().FindAll(u => (double)u.GetDistance <= range);
        return GetUnitsNearMe;
    }

If the bot is farming and a specific player flies up to it, it simply finishes the mobs and becomes afk (it doesn’t even take loot).

Link to comment
Share on other sites

I have already spent several days trying to come up with something to implement through the plugin and it seems to me that this venture failed, all that I found and that could work to get the bot to go somewhere during grind (immediately after the battle) or (farm ore or grass), the bot can’t just leave and go where I need to. Maybe this can be implemented somehow differently, for example, to call a special state with a high priority, if a specific player is nearby, but I found even less information regarding the forum states

Link to comment
Share on other sites

just in case I’ll publish the code if you suddenly do not want to download the project

Main.cs

using robotManager.Helpful;
using System.Threading;
using robotManager.Products;
using wManager.Wow.Enums;
using wManager.Wow.Helpers;
using wManager.Wow.ObjectManager;
using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Mail;
using System.Net;
using System.Configuration;
using System.ComponentModel;
using System.Text;
using robotManager;
using System.Threading.Tasks;
using robotManager.Events;
using robotManager.FiniteStateMachine;
using System.Linq;
using wManager.Wow.Bot.States;
using System.Drawing;

public class Main : wManager.Plugin.IPlugin
{
    private bool _isLaunched;
    public static bool Enemynear;
    private enum GameState { None, Logged_Out = 0, Logged_In = 1 };
    // enemyAlert
    private DateTime nextEnemyAlertTime;
    DateTime todaysDates;
    public List<string> myEnemyList;
    private bool hasAddedState;

    public void Initialize()
    {
        Logging.Write("[EnemyAlert] Started.");
        _isLaunched = true;
        todaysDates = DateTime.Now;

        //Fixed issue for BN_WHISPER not defined.
        initializeEnemiesList();
        nextEnemyAlertTime = DateTime.Now;
        doStuffLoop();
        FiniteStateMachineEvents.OnBeforeCheckIfNeedToRunState += new FiniteStateMachineEvents.FSMEngineStateCancelableHandler(this.FiniteStateMachineEvents_OnBeforeCheckIfNeedToRunState);

    }
    private void initializeEnemiesList()
    {
        if (_settings.enemyAlertEnabled)
        {
            string[] enemySplit = _settings.enemyNamesList.Split(',');
            myEnemyList = new List<string>(enemySplit);
        }

    }

    public void Dispose()
    {
        nextEnemyAlertTime = DateTime.Now;
        myEnemyList = null;
        FiniteStateMachineEvents.OnBeforeCheckIfNeedToRunState -= new FiniteStateMachineEvents.FSMEngineStateCancelableHandler(this.FiniteStateMachineEvents_OnBeforeCheckIfNeedToRunState);
        _isLaunched = false;
        Logging.Write("[RoboAlert] Disposed.");
    }
    public void Settings()
    {
        _settings.ToForm();
        _settings.Save();
    }

    public void doStuffLoop()
    {

        while (Products.IsStarted && _isLaunched)
        {
            // Products.InPause = true;


            if (!Products.InPause)
            {

                if (_settings.enemyAlertEnabled)
                    GetEnemiesNearMe();
                Thread.Sleep(20000);
            }
        }

    }
    private void FiniteStateMachineEvents_OnBeforeCheckIfNeedToRunState(
  Engine engine,
  robotManager.FiniteStateMachine.State state,
  CancelEventArgs cancelable)
    {
        if (this.hasAddedState)
            return;
        int priority = engine.States.Find((Predicate<robotManager.FiniteStateMachine.State>)(s => s.GetType() == typeof(Grinding))).Priority;
        Engine engine1 = engine;
        LeaveHaters leaveHaters = new LeaveHaters();
        leaveHaters.Priority = priority + 5;
        engine1.AddState((robotManager.FiniteStateMachine.State) leaveHaters);
        Logging.Write("[TSO]: Profession Training state added.", Logging.LogType.Normal, Color.SteelBlue);
        engine.States.Sort();
        this.hasAddedState = true;
    }
    public bool GetEnemiesNearMe()
    {
        var enemiesNearMe = GetEnemiesNearMe(_settings.enemyScanRange, myEnemyList);
        if(!(ObjectManager.Me.InCombatFlagOnly) && enemiesNearMe.Count > 0 && (DateTime.Now > nextEnemyAlertTime))
        {
            nextEnemyAlertTime = DateTime.Now.AddSeconds(_settings.enemyAlertWaitTime);
            Enemynear = true;
            var enemyNames = "";
            foreach (var enemy in enemiesNearMe)
            {
                enemyNames += (enemy.Name + " ");
            }
            Logging.Write("[EnemyAllert] Enemies Near Me ");
            wManager.Wow.Helpers.Lua.LuaDoString("BasicScriptErrors:SetScale(6) if BasicScriptErrors:IsShown() then BasicScriptErrors:Hide() end message('ХЕЙТЕР " + enemyNames + "')");
            return Enemynear;
        }
        return false;          
    }

    private List<WoWPlayer> GetEnemiesNearMe(int range, List<string> enemyName)
    {

        foreach (var enemy in enemyName)
        {
            Logging.Write(enemy);
        }

        List<WoWPlayer> enemiesNearMe = ObjectManager.GetObjectWoWPlayer().FindAll(p => p.GetDistance <= range && enemyName.Contains(p.Name) && p.IsAlive);
        return enemiesNearMe;
    }


    private roboAlertSettings _settings
    {
        get
        {
            try
            {
                if (roboAlertSettings.CurrentSetting == null)
                    roboAlertSettings.Load();
                return roboAlertSettings.CurrentSetting;
            }
            catch
            {
            }
            return new roboAlertSettings();
        }
        set
        {
            try
            {
                roboAlertSettings.CurrentSetting = value;
            }
            catch
            {
            }
        }
    }

    [Serializable]
    public class roboAlertSettings : Settings
    {

        public roboAlertSettings()
        {
            enemyAlertEnabled = true;
            enemyNamesList = "Sosuza,player2,player3";
            enemyAlertWaitTime = 20;
            enemyScanRange = 500;
        }


        [Setting]
        [Category("Enemy Alert Settings")]
        [DisplayName(" Enemy Alert Enabled")]
        public bool enemyAlertEnabled { get; set; }
        [Setting]
        [Category("Enemy Alert Settings")]
        [DisplayName("Enemy Names")]
        [Description("Check for specific Enemy by name. For multiple enemies, use a comma seperated list (Do not include spaces). This can be used in either the Elite Name or Normal Enemy Name.")]
        public string enemyNamesList { get; set; }
        [Setting]
        [Category("Enemy Alert Settings")]
        [DisplayName("Enemy Alert Pulse")]
        [Description("Time to wait until creating another subsequent alert after receiving an Enemy Alert (seconds). This prevents spamming of the alert")]
        public int enemyAlertWaitTime { get; set; }
        [Setting]
        [Category("Enemy Alert Settings")]
        [DisplayName("Enemy Scan Range")]
        [Description("The max range that RoboAlert will scan for enemies near you. (default is 500 units)")]
        public int enemyScanRange { get; set; }

        public static roboAlertSettings CurrentSetting { get; set; }

        public bool Save()
        {
            try
            {
                return Save(AdviserFilePathAndName("EnemyAlert", ObjectManager.Me.Name + "." + Usefuls.RealmName));
            }
            catch (Exception e)
            {
                Logging.WriteError("EnemyAlert > Save(): " + e);
                return false;
            }
        }

        public static bool Load()
        {
            try
            {
                if (File.Exists(AdviserFilePathAndName("EnemyAlert", ObjectManager.Me.Name + "." + Usefuls.RealmName)))
                {
                    CurrentSetting =
                        Load<roboAlertSettings>(AdviserFilePathAndName("EnemyAlert",
                                                                      ObjectManager.Me.Name + "." + Usefuls.RealmName));
                    return true;
                }
                CurrentSetting = new roboAlertSettings();
            }
            catch (Exception e)
            {
                Logging.WriteError("EnemyAlert > Load(): " + e);
            }
            return false;
        }
    }


}

LeaveHaters.cs

using robotManager.Helpful;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Threading;
using wManager.Wow.Bot.Tasks;
using wManager.Wow.Class;
using wManager.Wow.Enums;
using wManager.Wow.Helpers;
using wManager.Wow.ObjectManager;

internal class LeaveHaters : robotManager.FiniteStateMachine.State
{
    private int _priority;

    public override string DisplayName
    {
        get
        {
            return "Test State";
        }
    }

    public override int Priority
    {
        get
        {
            return this._priority;
        }
        set
        {
            this._priority = 99;
        }
    }

    public override bool NeedToRun
    {
        get
        {
            return Main.Enemynear && (!ObjectManager.Me.InCombat && !ObjectManager.Me.IsCast && !ObjectManager.Me.IsLooting());
        }
    }

    public override List<robotManager.FiniteStateMachine.State> NextStates
    {
        get
        {
            return new List<robotManager.FiniteStateMachine.State>();
        }
    }

    public override List<robotManager.FiniteStateMachine.State> BeforeStates
    {
        get
        {
            return new List<robotManager.FiniteStateMachine.State>();
        }
    }

    public override void Run()
    {
        wManager.Events.FightEvents.OnFightLoop += delegate (WoWUnit unit, CancelEventArgs cancelable)
        {
            
            
                var toPosition = new Vector3(4286.155, -884.4277, 251.7935, "Flying");
                LongMove.LongMoveGo(toPosition);
            
        };
    }
    
}

I would be grateful for any help

Link to comment
Share on other sites

 

Wonderful, it finally worked, but he still doesn’t want to mount, he had to add the command manually.

 

 

You can use it to avoid unwanted players, if this occurs, the bot will stop all actions and fly away to the Crystal Song Forest, the position can be changed, it works only in Northrend

plagin.cs

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...