|
Joined: Jan 2018
Posts: 7
Nutrimatic drinks dispenser
|
OP
Nutrimatic drinks dispenser
Joined: Jan 2018
Posts: 7 |
Hi, (this post has been edited) I'm running a roleplaying game using mIRC and I have a dice roller that currently rolls D10s that counts successes from 6-10. However... I need the script to be able to change the range in which the dice counts successes based on the user input.The perfect look of this would be: Input: !roll <number of dice> <difficulty> <text> example: !roll 5 6 Swing club Currently this is what I have as the output: [03:06] <@Nikki> !roll 9
[03:06] * yorich Nikki rolls 9 dice: 7, 4, 1, 4, 8, 8, 6, 7, 4
[03:06] <yorich> Nikki has 5 sucesses and needs to deduct 0 botches.
[03:06] <yorich> <---------------------------------------->
[03:06] <yorich> Nikki has a grand total of 5 sucesses.
[03:06] <yorich> <----------------------------------------> Unfortunately it's not counting the 'botches' correctly, which should be the 1s. It's also not deducting the 1s from the grand total, which I will fix as soon as it's counting the 1s. The script so far looks like this: on *:text:!roll &:#: {
if ($2 !isnum) { msg $chan Invalid number of dice. | return }
var %c = $2
if (%c > 30) {
msg # You're trying to crash me, aren't you.
halt
}
while (%c) {
var %roll = $rand(1,10)
if (%roll = 1) { var %roll = 04,01 $+ %roll }
elseif (%roll isnum 2-5) { var %roll = 01,00 $+ %roll }
elseif (%roll isnum 6-9) { var %roll = 03,00 $+ %roll }
else { var %roll = 09,01 $+ %roll }
var %dice = %dice $+ $iif(%dice, $+ $chr(44)) %roll
dec %c
}
describe $chan $nick rolls $2 dice: $replace(%dice,$chr(46), $+ $chr(44) $+ $chr(32))
var %s10 = 10
var %s9 = 9
var %s8 = 8
var %s7 = 7
var %s6 = 6
var %s5 = 5
var %s4 = 4
var %s3 = 3
var %s2 = 2
var %s1 = 1
var %c = $calc(%s1s)
var %s10s = $count(%dice,%s10)
var %s9s = $count(%dice,%s9)
var %s8s = $count(%dice,%s8)
var %s7s = $count(%dice,%s7)
var %s6s = $count(%dice,%s6)
var %s2s = $count(%dice,%s2)
var %sucs = $calc(%s9s + %s8s + %s7s + %s6s)
var %temp = %sucs
var %runtot = $calc(%runtot + %sucs)
var %sucs = %blank
msg $chan $nick has 11,01 %temp 00,01sucesses and needs to deduct11,01 %c 00,01botches.
var %temp = %blank
msg $chan <---------------------------------------->
msg $chan $nick has a grand total of 04,01 %runtot 00,01sucesses.
msg $chan <---------------------------------------->
} Any help with code would be appreciated. Priority 1: Count 1s Priority 2: Allow input of variable success parameters.
Last edited by Xini; 28/01/18 03:13 AM.
|
|
|
|
Joined: Jan 2018
Posts: 7
Nutrimatic drinks dispenser
|
OP
Nutrimatic drinks dispenser
Joined: Jan 2018
Posts: 7 |
|
|
|
|
Joined: Jan 2004
Posts: 2,127
Hoopy frood
|
Hoopy frood
Joined: Jan 2004
Posts: 2,127 |
Your example has 5 rolls, but the count of outcomes is 1+2+1=4
You can either have the $rand in the middle of your processing loop, or you can have the $rand build a tokenized list of numbers. You could do something like:
var %success = 0 var %fails = 0 var %botch = 0
%string holds the list of random numbers
var %i $numtok(%string,32)
while (%i) { var %roll $gettok(%string,%i,32) if (%roll >= %difficulty) inc %success elseif (%roll == 1) inc %botch else inc %fails dec %i }
var %success = %success - %botch
echo -a $nick rolled $2 dice at difficulty $3 and gained %success $iif(%success == 1,success,successes) $+ , %fails failures and %botch botch $+($chr(40),$replace(%string,$chr(32),$chr(44) $+ $chr(32)),$chr(41))
Be sure to not use external data within $calc() without making sure it doesn't contain dollars or percents.
|
|
|
|
Joined: Jan 2018
Posts: 7
Nutrimatic drinks dispenser
|
OP
Nutrimatic drinks dispenser
Joined: Jan 2018
Posts: 7 |
Sorry, I don't understand any of that. This is my first attempt at any of this.
So far the code is partially working. It is counting successes correctly.
For some reason so far, I can't get it to count dice that result in 1s. It either doesn't count them at all, or it counts the wrong thing. I'm thinking it might be counting 10s because there is a 1 in that number.
|
|
|
|
Joined: Jan 2004
Posts: 2,127
Hoopy frood
|
Hoopy frood
Joined: Jan 2004
Posts: 2,127 |
you have var %c = $calc(%s1s) which uses a variable not defined elsewhere else { var %roll = 09,01 $+ %roll } var %dice = %dice $+ $iif(%dice, $+ $chr(44)) %roll at this point, you can see that %dice can contain 09,01 so when you do var %s9 = 9 var %s9s = $count(%dice,%s9) you're counting color codes. You should try to avoid adding colors until you're done counting them, or use $count($count(%dice,%s9)) to reme the color numbers before counting. I don't understand what's different about 10 vs 6-9 It's simpler to do your counting inside your loop: var %success = 0
var %fails = 0
var %botch = 0
var %list_of_rolls
while (%c) {
var %roll = $rand(1,10)
if (%roll = 1) { inc %botch | var %roll = 04,01 $+ %roll }
elseif (%roll isnum 2-5) { inc %fails | var %roll = 01,00 $+ %roll }
elseif (%roll isnum 6-9) { inc %success | var %roll = 03,00 $+ %roll }
else { inc %success | var %roll = 09,01 $+ %roll }
var %dice = %dice $+ $iif(%dice, $+ $chr(44)) %roll
dec %c
var %list_of_rolls %list_of_rolls %roll
}
var %success = $calc(%success - %botch )
echo -a These are your rolls: $replace(%list_of_rolls,$chr(32),$chr(44) $+ $chr(32) )
|
|
|
|
Joined: Jan 2018
Posts: 7
Nutrimatic drinks dispenser
|
OP
Nutrimatic drinks dispenser
Joined: Jan 2018
Posts: 7 |
So I just realised the code pasted above isn't actually where I'm at right now. You're right about the %1s not being defined elsewhere there. It is actually defined in the current build as below. So far I'm storing variables (stage 1) var %s10 = 10
var %s9 = 9
var %s8 = 8
var %s7 = 7
var %s6 = 6 Then I'm counting those (stage 2) var %s10s = $count(%dice,%s10)
var %s9s = $count(%dice,%s9)
var %s8s = $count(%dice,%s8)
var %s7s = $count(%dice,%s7)
var %s6s = $count(%dice,%s6) Then I'm calculating successes and storing it in variable %temp var %sucs = $calc(%s9s + %s8s + %s7s + %s6s)
var %temp = %sucs which results in message: msg $chan $nick has11,01 %temp 00,01sucesses. That all works like a charm. As does the first part of the code before all the variables, because the first part of the code just results in the results of dice to be displayed. The part which doesn't work is counting the 1 result. Even though I've gone about this exactly the same way. stage 1 (storage) stage 2 (count & store) var %s1s = $count(%dice,%s1)
var %bot = %s1s And finally that should result in: msg $chan $nick has 04,01 %bot 00,01botches. It should be displaying the stored count of 1 results, but it seems to be counting something else.
Last edited by Xini; 28/01/18 04:57 PM.
|
|
|
|
Joined: Jan 2018
Posts: 7
Nutrimatic drinks dispenser
|
OP
Nutrimatic drinks dispenser
Joined: Jan 2018
Posts: 7 |
So the problem does seems to be that when I want it to count 1s, it counts 1s and 10s because 10 has a 1 in it.
|
|
|
|
Joined: Jan 2004
Posts: 2,127
Hoopy frood
|
Hoopy frood
Joined: Jan 2004
Posts: 2,127 |
looking at your pasted code at the top, it looks like your counting of 10 is counting 10 because i don't see any of your color codes contain a 10 in them. I don't see you counting 1's. Or 3's or 4's.
|
|
|
|
Joined: Jan 2018
Posts: 7
Nutrimatic drinks dispenser
|
OP
Nutrimatic drinks dispenser
Joined: Jan 2018
Posts: 7 |
It's not counting the colour codes. I'm not interested in counting 2s 3s or 4s because they are considered 'fail' and don't affect anything.
I've done a lot of testing (lots of rolling the dice) and what happens is If my results in 7 dice are: 1, 4, 9, 6, 10, 2 , 4 It counts the successes correctly (in this case: 3 successes) For botches (1s) it counts up all the fail dice, plus any 10s x2, plus any 1s x2.
So in the example, it will tell me I got 7 botches because it counts 10 and 1 twice, and counts the dice which don't = success once.
I have no idea why.
Last edited by Xini; 28/01/18 09:30 PM.
|
|
|
|
Joined: Jan 2004
Posts: 2,127
Hoopy frood
|
Hoopy frood
Joined: Jan 2004
Posts: 2,127 |
if you insist on adding color codes to a string after each roll, then make a parallel variable that has just the roll numbers. From that, you can count each number like: //echo -a $findtok(10 10 10 1 4 5 6 10,10,0,32)
//echo -a $findtok(10 10 10 1 4 5 6 10, 4,0,32)
|
|
|
|
Joined: Jan 2018
Posts: 7
Nutrimatic drinks dispenser
|
OP
Nutrimatic drinks dispenser
Joined: Jan 2018
Posts: 7 |
I appreciate all your help. I'm sorry that I didn't use your echo script, but I don't understand it (cause I'm not a coder/scripter). However, I made the damn thing work in the end. Final code for difficulty 6 for success: on *:text:!roll &:#: {
if ($2 !isnum) { msg $chan Invalid number of dice. | return }
var %c = $2
if (%c > 30) {
msg # $read errorbot.txt
halt
}
while (%c) {
var %roll = $rand(1,10)
if (%roll = 1) { var %roll = $+ %roll }
elseif (%roll isnum 2-5) { var %roll = $+ %roll }
elseif (%roll isnum 6-9) { var %roll = $+ %roll }
elseif (%roll = 10) { var %roll = $+ %roll }
var %dice = %dice $+ $iif(%dice, $+ $chr(44)) %roll
dec %c
}
describe $chan $nick 01,00rolls $2 dice diff 6: $replace(%dice,$chr(46), $+ $chr(44) $+ $chr(32))
var %s10 = 10
var %s9 = 9
var %s8 = 8
var %s7 = 7
var %s6 = 6
var %s1 = 1
var %tens = $count(%dice,%s10)
var %loss = $count(%dice,%s1)
var %wins = $count(%dice,%s10,%s9,%s8,%s7,%s6)
var %sucs = $calc(%wins + %s0)
var %bots = $calc(%loss - %tens)
var %temp = %sucs
var %ded = %bots
var %runtot = $calc(%sucs - %bots)
msg $chan $nick has 03,01 %temp 03,01sucesses. (Before Botches or Spec)
msg $chan ----------------------------------------
msg $chan $nick has04,01 %ded 04,01botches.
msg $chan ----------------------------------------
msg $chan $nick has a grand total of 09,01 %runtot 09,01 sucesses.
msg $chan ----------------------------------------
}
|
|
|
|
|