mIRC Homepage

A simple dice roller script?

Posted By: Feyl0rd

A simple dice roller script? - 10/02/15 11:53 PM

So currently I use:
Code:
on *:text:!d20:#:msg $chan $nick rolled a ( $r(1,20) ).

As a way to roll dice. But I've been experimenting with the idea of being able to do !d(X) and it roll the X as the maximum end of the $r.
Currently I have:
Code:
on *:text:!d*:#:{
  var %h = $$1
  msg $chan $nick rolled a ( ($r(1,%h) ) .
}

But it spits out ( ). So I decided to make it say %h instead and it takes the whole !d* no matter what it is. So if I did !d50 it would enter in:
Code:
( ($r(1,!d50) 

Any idea of how I can fix this?
Posted By: Nillen

Re: A simple dice roller script? - 11/02/15 02:33 AM

Assuming you want it to be !d50 and not !d 50 you use
Code:
var %h = $right($1,2-)
$1 in your case translates into !d50 , making it random between 1 and !d50, which isn't a proper value.
Posted By: Feyl0rd

Re: A simple dice roller script? - 11/02/15 04:35 AM

Yeah I mentioned that in my post, also thanks for responding! Yeah. When I had it echo instead it was just spitting out what I typed instead.
Posted By: Feyl0rd

Re: A simple dice roller script? - 11/02/15 04:39 AM

Thanks for the help by the way! I noticed that for whatever reason !d9 will spit out a blank ( ). Any idea why? I'll be running a lot of different numbers and see what results I get.

I have a feeling it's only the single digits - which isn't that hard to work around. (Just make 9 different !d1-9s) But I'm curious is there a way for it to read single digits as well? I assume that (1,-2) has something to do with why it can only receive multiple digit inputs... or something. shocked

Back. So far it only works for two digit numbers. I'll try and come up with a work around.


Code:
on *:text:!d*:#:{
  var %h = $right($1,2-)
  if %h < 10 {
    var %h = $right($1,1-)
    msg $chan $nick rolled a ( $r(1,%h) ).
  }
  else {
  msg $chan $nick rolled a ( $r(1,%h) ). }
}

Is what I have so far... unsure of how I can get it to read the single digit ones. Still works with the two digit ones though! So that's pretty hype.
Posted By: Nillen

Re: A simple dice roller script? - 11/02/15 08:46 AM

Oops, my miss. I meant for it to be $right($1,-2) instead of 2-. Habit of typing I guess, sorry.
Posted By: Majeye

Re: A simple dice roller script? - 11/02/15 06:47 PM

How could this be done with switching the trigger event?

!d20 --> the d in this triggers another command I have. How could we switch it to say "!dice20" and have it still work?

right now with the way its coded; "!dice20" yields:

NAME rolled a ( ).

It doesn't actually roll.
Posted By: Feyl0rd

Re: A simple dice roller script? - 11/02/15 07:16 PM

If you have a command that uses !d something and triggers off of that then you can either switch the on text event to be !diceX where X is the number you'd like to roll.
Before:
Code:
on *:text:!d20:#:msg $chan $nick rolled a ( $r(1,20) ).

The above code will roll a d20 when !d20 is typed in the channel. If you want it to be !dice20 then change !d20 to be what you would like. Example:
Code:
on *:text:!dice20:#:msg $chan $nick rolled a ( $r(1,20) ).

It will now instead roll a d20 only when !dice20 is said.
Posted By: Majeye

Re: A simple dice roller script? - 11/02/15 07:17 PM

Originally Posted By: Feyl0rd
If you have a command that uses !d something and triggers off of that then you can either switch the on text event to be !diceX where X is the number you'd like to roll.
Before:
Code:
on *:text:!d20:#:msg $chan $nick rolled a ( $r(1,20) ).

The above code will roll a d20 when !d20 is typed in the channel. If you want it to be !dice20 then change !d20 to be what you would like. Example:
Code:
on *:text:!dice20:#:msg $chan $nick rolled a ( $r(1,20) ).

It will now instead roll a d20 only when !dice20 is said.


How could you get that to work with this?

Code:
on *:text:!d*:#:{
  var %h = $right($1,2-)
  if %h < 10 {
    var %h = $right($1,1-)
    msg $chan $upper($nick) rolled a ( $r(1,%h) ).
  }
  else {
  msg $chan $upper($nick) rolled a ( $r(1,%h) ). }
}
Posted By: Feyl0rd

Re: A simple dice roller script? - 11/02/15 07:41 PM

Here's the finished product if anyone was interested. With Nillens help and a bit of help from the help files:
Code:
on *:text:!d*:#:{
  var %h = $right($1,-2)
  if %h < 0 { msg $chan $nick %h is not a valid entry. }
  if %h isletter { msg $chan $nick %h is not a valid entry. }
  else { msg $chan $nick rolled a ( $r(1,%h) ). }
}

Thank you Nillen!
Hope this helps anyone who needs it.
Posted By: Majeye

Re: A simple dice roller script? - 11/02/15 08:18 PM

Originally Posted By: Feyl0rd
Here's the finished product if anyone was interested. With Nillens help and a bit of help from the help files:
Code:
on *:text:!d*:#:{
  var %h = $right($1,-2)
  if %h < 0 { msg $chan $nick %h is not a valid entry. }
  if %h isletter { msg $chan $nick %h is not a valid entry. }
  else { msg $chan $nick rolled a ( $r(1,%h) ). }
}

Thank you Nillen!
Hope this helps anyone who needs it.


The code by itself is working as intended;

However...

If you type !d<and anything else here>, it returns with <and anything else here> is not a valid entry.

Meaning.. if you have any other command that starts with !d, the !d command will also post.

Therefore; the trigger event !d needs to be changed. But, if you change !d to anything else.. say "!dice".. then the entire code doesn't work.

Any idea how to change it? what causes the problem?

I would love the dice roll trigger event to be !dice*, but it doesn't work the current way it is written.
Posted By: Feyl0rd

Re: A simple dice roller script? - 11/02/15 09:01 PM

It has to do with the ($1,-2) I assume. Change the !d* to something else that's just a single letter or number. !a-z pr !0-9. Unless you experiment with changing the -2 it'll have to stay !Xy where X is the trigger and y is the requested number. I'll try a few things and report back if anything works.
Posted By: Feyl0rd

Re: A simple dice roller script? - 11/02/15 09:04 PM

Back, got it to work.
Code:
on *:text:!roll*:#:{
  var %h = $right($1,-5)
  if %h < 0 { msg $chan $nick %h is not a valid entry. }
  if %h isletter { msg $chan $nick %h is not a valid entry. }
  else { msg $chan $nick rolled a ( $r(1,%h) ). }
}

This should work out for you, hope it helps!
Posted By: Majeye

Re: A simple dice roller script? - 11/02/15 09:06 PM

Originally Posted By: Feyl0rd
Back, got it to work.
Code:
on *:text:!roll*:#:{
  var %h = $right($1,-5)
  if %h < 0 { msg $chan $nick %h is not a valid entry. }
  if %h isletter { msg $chan $nick %h is not a valid entry. }
  else { msg $chan $nick rolled a ( $r(1,%h) ). }
}

This should work out for you, hope it helps!


ahhh... I see why/what/how it works now. Thank you for posting this up.
© 2022 mIRC Discussion Forums