Trouble with alias dieroller

Posted by Silencher on Thu 01 May 2014 03:14 AM — 6 posts, 23,133 views.

#0
Hello,

I made a sort of simple dieroller just out of boredom as an alias. It works fine if I do a simple #d# roll, but if I try to add a bonus or penalty, it doesn't work.

mydice *d* <--original alias
if I did: 1d10
My output would be:
1d10 rolled 5 (or some other number besides 5)

But with:
mydice *d* + * <---'upgraded' alias
If I do my output as 1d10 + 3
My output is:
1d13 rolled 5 (or some other number between 1->13)

What I want is for it to literally do 1d10, then add 3. But that isn't happening.

Below is the body of my alias, can you tell me what is wrong? I think it has to do with me using the '+' in the actual alias command, so maybe I need a way for Lua to ignore that + somehow, so it doesn't add %2 and %3 together?

--body of alias below--
math.randomseed(os.time())
math.random()
numberOfDice = %1
dieSides = %2
result = (math.floor (MtRand () * dieSides) +1)
sum = 0
for i = 1, numberOfDice, 1 do
roll = (math.floor (MtRand () * dieSides) +1)
sum = roll + sum
end
bonus = %3
sum = sum + bonus
Note(numberOfDice .. "d" .. dieSides .. " rolled " .. sum)

--end body of alias--
Australia Forum Administrator #1
Can you post the actual alias please?

Template:copying
For advice on how to copy aliases, timers or triggers from within MUSHclient, and paste them into a forum message, please see Copying XML.
#2

<aliases>
  <alias
   match="mydice *d* + *"
   enabled="y"
   group="testing"
   send_to="12"
   sequence="100"
  >
  <send>math.randomseed(os.time())
math.random() 
numberOfDice = %1
dieSides = %2
result = (math.floor (MtRand () * dieSides) +1)
sum = 0
for i = 1, numberOfDice, 1 do
   roll = (math.floor (MtRand () * dieSides) +1)
   sum = roll + sum
end
bonus = %3
sum = sum + bonus
Note(numberOfDice .. "d" .. dieSides .. " rolled " .. sum)</send>
  </alias>
</aliases>
Amended on Thu 01 May 2014 06:20 AM by Nick Gammon
Australia Forum Administrator #3
I tried your alias out, unchanged, and got this:


mydice 1d10 + 3



1d10 rolled 4
1d10 rolled 11
1d10 rolled 8
1d10 rolled 6
1d10 rolled 8
1d10 rolled 13
1d10 rolled 10
1d10 rolled 7
1d10 rolled 12
1d10 rolled 7
1d10 rolled 7
1d10 rolled 13
1d10 rolled 9


That seems to be working, yes?

Some of the rolls are over 10, which shows that adding 3 is happening.

Quote:

But that isn't happening.


Can you post what you entered, and what you got?





math.randomseed(os.time())
math.random() 


That doesn't do anything, since MtRand does not use math.randomseed.
#4
Oh I see why. I have that alias, but also the original alias:

mydice *d*

If I remove mydice *d* I can't do regular rolls. 1d10.

Is there a way to alter this into one alias that would somehow catch the + and/or - and not add/subtract %2 and %3 together?

mydice *d* is the same as the other alias I posted, except there's no 'bonus' in it. So that 2nd * is catching everything as just %2, rather than %2 + %3.

Basically I need to have the + in the alias not be an operator, I think.
Australia Forum Administrator #5
Template:faq=50
Please read the MUSHclient FAQ - point 50.