Macro Help :D

I’m trying to write a macro that on spell casts has a %chance to say a message or %chance to say 1 of 3 messages, however I don’t want it to say it on every cast. I’m currently using this macro, {/run RandomRoll(1,50) = A; if A=1 SendChatMessage (“Get Em”,“Say”); end} I have also tried {/run local rng = math.random(50); if rng=1 then SendChatMessage(“Get Em’”); if rng=2 then SendChatMessage("**** them up"); if rng=3 then SendChatMessage(“Attack”); end}
Any help would be appreciated.

1-50 leaves a huge opportunity for nothing to happen eg. you could potentially roll any single number 10 times or more in a row. Reduce the upper limit to get something acceptable knowing you could still roll any non-messaging (or messaging) numbers multiple times.

random does not take previous results into consideration given the same conditions.

/run local rng, msg = random(1,7) if rng==1 then msg = "Get Em" elseif rng==3 then msg = "**** them up" elseif rng==7 then msg = "Attack" end if msg then SendChatMessage(msg) end

The problem is that WoW macro’s don’t allow if then statements. The solution was presented to me by Frosto on the Classic WoW general board.
So, something you can do is assign a random number to a variable, e.g. /run MyVar = random(0, 9); the random function takes a start and end number and will return a random number within that range.

You can have a list of things you’d like to say, such as, MyList = ["Hello", "Hey", "What's up?", "Yo!"];

Where, if you call the greeting at the index in that list, you will get the greeting you’d expect. For example MyList[0] is “Hello”, MyList[1] is “Hey”, and so on…

However, if you call MyList[100] or any other value that is not an index of the list, then you will get nothing returned.

Using that, you should be able to do what you want to do. Here’s a more complete example to point you in the right direction:

NOTE : I’ve used 0 through 10 for the range, so this should usually not send a message.

/run randNum = random(0, 10); 
/run myList = {"Hello","Hey","What's up?","Yo!"};
/run SendChatMessage(myList[randNum], "SAY");

You could also do that in 1 line, if you prefer. Also I think /script is an alias for /run or vice versa, but they seem to do the same thing:

/script randNum = random(0, 10); myList = {"Hello","Hey","What's up?","Yo!"}; SendChatMessage(myList[randNum], "SAY");

P.S. The large chance of nothing is intentional. In a raid I click this button maybe 1000 times, if it said something more then a small percentage it would be annoying spam.

Yes they do. Your syntax in the OP is just wrong, use Fizzle’s.

Similarly, the code in your second post will throw errors whenever it tires to reference an index outside the range of the array.

1 Like

The code works though? Maybe classic and retail run on different rule sets?

It “works” because it’s executed each time you hit the button regardless of previous errors. You’re just not seeing what a mess it is because you have errors disabled.