Jump to content

Plugin for robots/response to player attack


Recommended Posts

@Droidz
Good afternoon. I encountered a problem that my bot does not respond to an attack from a renegade. I'm trying to create a plugin so that my character can respond to attacks from any players, but it's not working yet.
Here is my code, added it to the .cs, but the bot doesn’t even see my plugin.
Please help me with this, because my bot stands out very much when it just runs and absorbs all the player's attacks.
I would be very grateful for your help.


 

using PluginTutorial;
using robotManager.Helpful;
using System.Collections.Generic;
using System.Drawing;
using System.Threading;
using wManager.Plugin;
using wManager.Wow.Helpers;
using wManager.Wow.ObjectManager;

namespace YourNamespace
{
    public class Class1
    {
        private WoWUnit? attacker;

        public void Run()
        {
            var enemies = ObjectManager.GetWoWUnitAttackables().Where(u => u.IsTargetingMe && u.IsPlayer);
            if (enemies.Any())
            {
                foreach (var enemy in enemies)
                {
                    Logging.Write($"Attacking player {enemy.Name} in response to being attacked.");
                    Attack(enemy);
                }
            }
        }

        public void OnEvent(EventArgs args)
        {
            if (args is WRobotEventUnitBeingAttacked)
            {
                var eventArgs = (WRobotEventUnitBeingAttacked)args;
                attacker = eventArgs.Attacker;
            }
        }

        private void Attack(WoWUnit target)
        {
            target.Target;
            MovementManager.StopMove();
           
        }
    }
}

 

Link to comment
Share on other sites

Hello,

Your code is wrong, the code would look more like this (not tested):

using System.Linq;
using System.Windows.Forms;
using robotManager.Helpful;
using wManager.Wow.Bot.States;
using wManager.Wow.Helpers;
using wManager.Wow.ObjectManager;

public class Main : wManager.Plugin.IPlugin
{
    public void Initialize()
    {
        robotManager.Events.FiniteStateMachineEvents.OnBeforeCheckIfNeedToRunState += (engine, state, cancelable) =>
        {
            if (state is IsAttacked &&
                Conditions.InGameAndConnectedAndAliveAndProductStartedNotInPause)
            {
                var enemies = ObjectManager
                    .GetObjectWoWPlayer()
                    .Where(u =>
                        u.IsValid &&
                        u.IsAlive &&
                        u.PlayerFaction != ObjectManager.Me.PlayerFaction &&
                        u.IsTargetingMe &&
                        u.InCombatFlagOnly
                    );
                if (enemies.Any())
                {
                    var enemy = enemies.First();
                    Logging.Write($"Attacking player {enemy.Name} in response to being attacked.");
                    Fight.StartFight(enemy.Guid);
                }
            }
        };
    }

    public void Dispose()
    {
        Logging.Write("Disposed.");
    }

    public void Settings()
    {
        MessageBox.Show("No settings for this plugin.");
    }
}

 

Link to comment
Share on other sites

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...