Jump to content

How do you make and use variables?


Macro

Recommended Posts

I want to randomize my spells / actions a bit by using variables so the bot will look human. This might be very very easy but I dont know how to do it, it may help other new people.

 

This is what I am trying to do:

Var Random = (1-3)
  
 if (Frostbolt.KnownSpell && ObjectManager.Target.GetDistance < 30 && Random = 1)
        {
            Frostbolt.Launch();
  			Random = (1-3);
        }
 if (ArcaneMissiles.KnownSpell && ObjectManager.Target.GetDistance < 30 && Random = 2)
        {
            ArcaneMissiles.Launch();
  			Random = (1-3);
        }
 if (Fireball.KnownSpell && ObjectManager.Target.GetDistance < 30 && Random = 3)
        {
            Fireball.Launch();
  			Random = (1-3);
        }

Does anyone know the proper code to do this?

Do I need to put public bool in the beginning of the script?

Link to comment
Share on other sites

var random = new Random().Next(1,4);

You can test it in the dev tools, do this (with execution type set to C#):
 

var random = new Random().Next(1,4);
Logging.Write(random.ToString());

DevTools help:https://marsbars.gitlab.io/unoffical-wrobot-api-docs/articles/devtools.html

Edited by Marsbar
Link to comment
Share on other sites

public class Example1
{
  private static var newVarible = "something";
  public static string newVariable
  { 
        get { return name; }
        set { name = value; }
  }
}

public class Example2
{
  if (Example1.newVariable == "something")
  {
    print(Example1.newVariable);
    //Output: something
  }
}

Keep in mind these are very loosely based examples just to depict what is going on

Ugh...stupid edits removed my code examples...im kind of mad I had a quick lesson in variables for you =/. The above one that survived tries to explain how variables can cross "scopes" and be used across multiple classes. If you are just working with variables within a single class, you only need to declare the variable above the code you will use it in:

public class Example3
{
	var newVariable = "something";
	if (1 = 1)
	{
		print(newVariable);
		//output: something
		newVariable = "something else";
		print(newVariable);
		//output: something else
	}
	else
	{
		print(newVariable);
		//output: something
		newVariable = "something new";
	}
	print(newVariable);
	//output: something else as 1 = 1
}

 

Anyway, here's a snipplet that will work for your particular case:

string[] spells = new [] {"frostbolt", "arcane missles", "fireball"};
string[] shuffled = spells.OrderBy(n => Guid.NewGuid()).ToArray();

if (wManager.Wow.Helpers.SpellManager.KnowSpell(shuffled[0]) && ObjectManager.Target.GetDistance < 30)
{
    wManager.Wow.Helpers.SpellManager.CastSpellByNameLUA(shuffled[0]);
}

Arrays are just groups of variables under one umbrella that are given index numbers (starting at 0) so they can be referenced in a plethora of ways. In this snipplet, your spell names populate a string array called "spells". another array "shuffled" takes the values in "spells" and assigns/reorders them with new Guids- which is basically a tricking the array into shuffling the index numbers of the spells. This means every time the code is called, the contents of shuffled[0] changes randomly.

Tip: declaring a "var" simply tells the interpreter it's on it's own when it comes to parsing the value of the variable. var can be replaced with things like string,int,float etc to designate specifically what kind of value you are storing. In the case above, string[] designates the array will consist of strings, where int[] would designate the array consists of numbers/intergers.

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