mIRC Home    About    Download    Register    News    Help

Print Thread
A simple dice roller script? #251144 10/02/15 11:53 PM
Joined: Dec 2014
Posts: 40
Feyl0rd Offline OP
Ameglian cow
OP Offline
Ameglian cow
Joined: Dec 2014
Posts: 40
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?

Re: A simple dice roller script? [Re: Feyl0rd] #251156 11/02/15 02:33 AM
Joined: Dec 2013
Posts: 779
N
Nillen Offline
Hoopy frood
Offline
Hoopy frood
N
Joined: Dec 2013
Posts: 779
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.


Nillens @ irc.twitch.tv
Nillen @ irc.rizon.net
Re: A simple dice roller script? [Re: Nillen] #251159 11/02/15 04:35 AM
Joined: Dec 2014
Posts: 40
Feyl0rd Offline OP
Ameglian cow
OP Offline
Ameglian cow
Joined: Dec 2014
Posts: 40
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.

Re: A simple dice roller script? [Re: Nillen] #251160 11/02/15 04:39 AM
Joined: Dec 2014
Posts: 40
Feyl0rd Offline OP
Ameglian cow
OP Offline
Ameglian cow
Joined: Dec 2014
Posts: 40
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.

Last edited by Feyl0rd; 11/02/15 04:55 AM.
Re: A simple dice roller script? [Re: Feyl0rd] #251164 11/02/15 08:46 AM
Joined: Dec 2013
Posts: 779
N
Nillen Offline
Hoopy frood
Offline
Hoopy frood
N
Joined: Dec 2013
Posts: 779
Oops, my miss. I meant for it to be $right($1,-2) instead of 2-. Habit of typing I guess, sorry.


Nillens @ irc.twitch.tv
Nillen @ irc.rizon.net
Re: A simple dice roller script? [Re: Nillen] #251185 11/02/15 06:47 PM
Joined: Jan 2014
Posts: 101
M
Majeye Offline
Vogon poet
Offline
Vogon poet
M
Joined: Jan 2014
Posts: 101
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.

Re: A simple dice roller script? [Re: Majeye] #251188 11/02/15 07:16 PM
Joined: Dec 2014
Posts: 40
Feyl0rd Offline OP
Ameglian cow
OP Offline
Ameglian cow
Joined: Dec 2014
Posts: 40
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.

Re: A simple dice roller script? [Re: Feyl0rd] #251189 11/02/15 07:17 PM
Joined: Jan 2014
Posts: 101
M
Majeye Offline
Vogon poet
Offline
Vogon poet
M
Joined: Jan 2014
Posts: 101
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) ). }
}

Last edited by Majeye; 11/02/15 07:19 PM.
Re: A simple dice roller script? [Re: Nillen] #251190 11/02/15 07:41 PM
Joined: Dec 2014
Posts: 40
Feyl0rd Offline OP
Ameglian cow
OP Offline
Ameglian cow
Joined: Dec 2014
Posts: 40
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.

Re: A simple dice roller script? [Re: Feyl0rd] #251195 11/02/15 08:18 PM
Joined: Jan 2014
Posts: 101
M
Majeye Offline
Vogon poet
Offline
Vogon poet
M
Joined: Jan 2014
Posts: 101
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.

Re: A simple dice roller script? [Re: Majeye] #251203 11/02/15 09:01 PM
Joined: Dec 2014
Posts: 40
Feyl0rd Offline OP
Ameglian cow
OP Offline
Ameglian cow
Joined: Dec 2014
Posts: 40
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.

Re: A simple dice roller script? [Re: Majeye] #251205 11/02/15 09:04 PM
Joined: Dec 2014
Posts: 40
Feyl0rd Offline OP
Ameglian cow
OP Offline
Ameglian cow
Joined: Dec 2014
Posts: 40
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!

Re: A simple dice roller script? [Re: Feyl0rd] #251206 11/02/15 09:06 PM
Joined: Jan 2014
Posts: 101
M
Majeye Offline
Vogon poet
Offline
Vogon poet
M
Joined: Jan 2014
Posts: 101
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.