mIRC Homepage
Posted By: Fernin mIRC Programming Tutorial? - 25/01/09 12:17 AM
Just recently, I downloaded a bot, DreamBot 5.1, for a channel I frequent. Going through its programs, I'm starting to understand how it's programmed and the ins and outs of the language for writing new commands for it. However, studying a language can only get me so far... I still only have half a clue of what I'm doing. So far, I've been able to program a new !fortune command into it, to get it to spit out a random fortune, which was a very simple thing to do, all I basically did was take one of its back talk responses and edit it into the games commands section. My next venture has been to program a new game into it, and my thoughts were either to try a hangman game or a Mastermind kind of game. However... since I'm only kind of aware of if I'm doing the right thing, I haven't had much luck yet.

Code:
;@@@ Mastermind @@@
on 1:text:*mastermind:#: {
  if (%!mastermind == on) {
    if ($1 == %c $+ mastermind) {
      if ($me !isvoice $chan) {
      MSG $chan Sorry, I've lost the privilege to speak. Try again later when I've been reactivated.
      halt
    }    
     set %fnum $rand(1,9)
     set %snum $rand(1,9)
     set %tnum $rand(1,9)
     set %hnum $rand(1,9)
     set %mnum %fnum $+ %snum $+ %tnum $+ %hnum
bt $chan The number is %mnum
	}
on 1:text:*guess:#: {
  if ($1 == %c $+ guess) {
        if (%mnum == $null) { msg $chan I'm not thinking of a number yet. | halt }
        if ($2 !isnum 1000-9999 ) { msg $chan Enter a number between 1000 and 9999 | halt }
        if ($2 == %mnum ) { 
	msg $chan You win!
                unset %mnum | halt
	}
        if ($2 != %mnum { msg $chan Guess again! | halt }
           }
}
}
}
}
}


Hmm, I think I grabbed some extra }'s at the end there...

Anyways, I know that code is hideously mangled and nowhere near right, but I think I'm doing alright, considering I just started learning this about three days ago. I'd like to continue learning this and get this crap working, so I'll finally get to my point...

Can anyone link me to a place where I can learn this programming language for mIRC?
Posted By: RusselB Re: mIRC Programming Tutorial? - 25/01/09 01:17 AM
I don't think I'd hear any arguements or even serious discussion on the matter, by stating that the mIRC scripter's bible is the help file.
/help

There are several sites that also have tutorials, but for the beginner, even these tutorials can be confusing.

You can check tutorials (if you think you're up to them, or just want to give them a try) at Hawkee, mIRC Scripts, and mIRC.net
Posted By: Fernin Re: mIRC Programming Tutorial? - 25/01/09 01:38 AM
While I may be a beginner at programming in mIRC, I'm hardly a beginner at programming in general. I've gone through Java, Javascript, C++, C#, VB, and a couple others, so I'm not really anticipating any trouble with this stuff. Thanks for the links, though, they'll definitely come in handy. laugh
Posted By: Fernin Re: mIRC Programming Tutorial? - 25/01/09 08:59 AM
There doesn't seem to be any kind of edit button, so I'm forced into double posting...

I've been working my way through the tutorials, and haven't yet found specifically what I'm looking for yet, the thing that'll let me move on with my program testing, so I figure it's easier to just ask... In the code there, you can see that I'm trying to get it to recognize the !guess command. When I do the !mastermind command, the bot's mIRC section tells me "ON Unknown Command." I'm assuming this is referring to the !guess command, as that gets absolutely no response from the bot, while the first section, setting the random number and telling me what it is, works just fine. What am I missing that will, for lack of a better word, activate the command?
Posted By: Horstl Re: mIRC Programming Tutorial? - 25/01/09 09:20 AM
Most likely your code has a "bracket mismatch" resulting in a nested event (one event inside another event, not allowed). e.g.:
Code:
on <EVENT1> {
  if (something) {
    - do something - 
  }
  - do something -

  on <EVENT2> {
    - do something -
  }
}
...note that there's an "even" number of opening and closing brackets, but the second event definition is in fact interpreted like a command "on", because it's inside the command part of the first event.

It has to be like:
Code:
on <EVENT1> {
  if (something) {
    - do something - 
  }
  - do something -
}

on <EVENT2> {
  - do something -
}


mIRC will reallign (indent acc. to brackets) the code if you switch tabs in the scripts editor, or close and reopen the editor, or click the "check brackets" button (upper right corner). You'll soon get used to this method of detecting bracket problems smile
Posted By: RusselB Re: mIRC Programming Tutorial? - 25/01/09 10:31 AM
These forums do allow editing, but it is time sensitive.
If I recall correctly, you can edit your posts for up to 1 hour after posting.
Posted By: Fernin Re: mIRC Programming Tutorial? - 25/01/09 06:40 PM
Code:
;@@@ Mastermind @@@
on 1:text:*mastermind:#: {
  if (%!mastermind == on) {
    if ($1 == %c $+ mastermind) {
      if ($me !isvoice $chan) {
        MSG $chan Sorry, I've lost the privilege to speak. Try again later when I've been reactivated.
        halt
      }    
      set %fnum $rand(1,9)
      set %snum $rand(1,9)
      set %tnum $rand(1,9)
      set %hnum $rand(1,9)
      set %mnum %fnum $+ %snum $+ %tnum $+ %hnum
      bt $chan The number is %mnum
      	}
    }
  }
  on 1:text:*guess:#: {
    if ($1 == %c $+ guess) {
      if (%mnum == $null) { msg $chan I'm not thinking of a number yet. | halt }
      if ($2 !isnum 1000-9999) { msg $chan Enter a number between 1000 and 9999 | halt }
      if ($2 == %mnum) { 
        	msg $chan You win!
        unset %mnum | halt
        	}
        if ($2 != %mnum) { msg $chan Guess again! | halt }
      }
    }


I did what you suggested and put it into the scripts editor in mIRC (up until now I've been working in notepad, in the folders where the bot actually reads these from...)
Near as I can tell, I have an even number of brackets now and they all line up correctly, but it's telling me I have a bracket mismatch in line 18, the on 1:text:*guess:#: line. It also stops recognizing anything below this in the file with it written like this. When I add another bracket to the bottom, giving me an uneven number, it recognizes everything below this section again, but the editor tells me I have a bracket mismatch in line 4. What do I have screwed up here?
Posted By: 5618 Re: mIRC Programming Tutorial? - 25/01/09 06:58 PM
The problem is that, in the first on TEXT event, there is a "Tab" character in front of your third closing bracket, counted from the bottom.

EDIT: the same goes for the third closing bracket from the bottom up in the second on TEXT event.
Posted By: Fernin Re: mIRC Programming Tutorial? - 25/01/09 09:58 PM
Huh, first language I've worked in where proper formatting and spacing is actually important... At least it works now, thanks.

Moving on to my next bit, I'm trying to get it to recognize each of the individual digits that are input with the !guess command. I couldn't find any normal substring function in the Text and Numbers section of the help, only things such as $left, $right, and $mid. I'm trying to be able to separate the digits out to be able to compare and use them. Say I enter !guess 5998, I'm looking for a function that will I can use to set 4 variables, which would end up with the numbers 5, 9, 9, and 8. Using $mid, I'm able to pick out the 5 and the 8, but I can't get it to grab just the 9 and the 9, it keeps grabbing 99 or 98, or in one case, 3, I still have no clue how that one happened. Which function should I be using for this task?
Posted By: Wims Re: mIRC Programming Tutorial? - 25/01/09 10:16 PM
You should be able to get this working with $mid :
Code:
on *:text:*:#:{
tokenize 32 $strip($1-)
;strip all control code
if ($1 == !guess) {
var %a = 1, %b = $len($$2)
while (%a <= %b) {
set -l $+(%,%a) $mid($2,%a,1)
;/set -l is the same as /var but it let you make dynamic variable (here %N where N is a number between 1- %b)
inc %a
}
echo -a > %1 - %2 - %3 - %4 ... <
} 
}
Posted By: Fernin Re: mIRC Programming Tutorial? - 26/01/09 11:46 PM
Getting further along now, ran into a new snag. (While I didn't end up using any of your code, Wims, you did lead me into realizing how to get the individual numbers out using $mid, so thanks for that).

I have it so that it's almost playable, save for the snag... Telling them how many numbers they have that aren't correct, but are out of place. I've been testing with the number 4678 for about the past hour or so, and every combination I've tried has ended screwy in some way. I tried using the $count function to check each guessed number against the original, as well as each original number against the guessed number, but if I entered the number 4444 as the guess, it'd come up with 1 correct and 3 out of place. I tried comparing each guessed number to each original number, but that also resulted in it telling me I had 1 correct and 3 out of place. After that, I set it up to compare each of the four guessed numbers to each other, to see if any of those were the same, and if they were, subtracting the number that was the same from the total I got in the previous attempt. (I know, flawed logic, but it got me the right answer in the one situation). On submitting 4444, it did give me the right answer of 1 correct and 0 out of place, but on trying 4111, it told me I had 1 correct and -1 out of place. Is there something obvious I'm missing as a way to compare each number and get an accurate "# out of place" total, or is this going to be far lengthier than I first thought?
Posted By: RusselB Re: mIRC Programming Tutorial? - 27/01/09 12:11 AM
There is absolutely nothing wrong with using a lengthy code, if it works.
Once you have a working, although, lengthy code, there are several helpers on this forum, which will be more than happy to review your code, and make suggestions as to how you can make it shorter and/or faster (note: one does not necessarily mean the other)

Regarding checking if the numbers are in the correct location or not, using a loop and comparing to instances of $mid is a good way of doing this.

You might want to take a look at my Scrambled Word Game snippet, as it appears to be similar to what you're trying to do.
Posted By: Fernin Re: mIRC Programming Tutorial? - 27/01/09 01:02 AM
Well, it's a good thing there's nothing wrong with lengthy code, this thing's getting up there already...

Code:
;@@@ Mastermind @@@
on 1:text:*mastermind:#: {
  if (%!mastermind == on) {
    if ($1 == %c $+ mastermind) {
      if ($me !isvoice $chan) {
        MSG $chan Sorry, I've lost the privilege to speak. Try again later when I've been reactivated.
        halt
      }    
      set %fnum $rand(1,9)
      set %snum $rand(1,9)
      set %tnum $rand(1,9)
      set %hnum $rand(1,9)
      set %counter 0
      set %mnum %fnum $+ %snum $+ %tnum $+ %hnum
      bt $chan I'm thinking of a number... It's a four digit number, between 1000 and 9999. Try and guess it with !guess (####)
    }
  }
}
on 1:text:*guess*:#: {
  if ($1 == %c $+ guess) {
    if (%mnum == $null) { msg $chan I'm not thinking of a number yet. | halt }
    if ($2 !isnum 1000-9999) { msg $chan Enter a number between 1000 and 9999 | halt }
    if ($2 == %mnum) { 
      msg $chan That's right! %mnum $+ ! You win, $nick $+ ! And it only took %counter guesses. Type !mastermind to start a new guessing game.
      unset %mnum | halt
    }
    if ($2 != %mnum) { 
      inc %counter
      set %gfnum $mid($2, 1, 1)
      set %gsnum $mid($2, 2, 1)
      set %gtnum $mid($2, 3, 1)
      set %ghnum $mid($2, 4, 1)
      set %correct 0
      set %close1 0
      set %closef 0
      set %closes 0
      set %closet 0
      set %closeh 0
      if (%gfnum == %fnum) { inc %closef }
      if (%gfnum == %snum) { inc %closef }
      if (%gfnum == %tnum) { inc %closef }
      if (%gfnum == %hnum) { inc %closef }
      if (%gsnum == %snum) { inc %closes }
      if (%gsnum == %tnum) { inc %closes }
      if (%gsnum == %hnum) { inc %closes }
      if (%gsnum == %fnum) { inc %closes }
      if (%gtnum == %tnum) { inc %closet }
      if (%gtnum == %hnum) { inc %closet }
      if (%gtnum == %fnum) { inc %closet }
      if (%gtnum == %snum) { inc %closet }
      if (%ghnum == %hnum) { inc %closeh }
      if (%ghnum == %fnum) { inc %closeh }
      if (%ghnum == %snum) { inc %closeh }
      if (%ghnum == %tnum) { inc %closeh }
      if (%gfnum == %fnum) { inc %correct }
      if (%gsnum == %snum) { inc %correct }
      if (%gtnum == %tnum) { inc %correct }
      if (%ghnum == %hnum) { inc %correct }
      if (%closef >= 1) { inc %close1 }
      if (%closes >= 1) { inc %close1 }
      if (%closet >= 1) { inc %close1 }
      if (%closeh >= 1) { inc %close1 }
      set %close %close1 - %correct 
      msg $chan You have %correct correct.
      msg $chan You have %close out of place.
    }
  }
}


Sorry for the lack of comments, I almost never comment my own work... Should be fairly easy to follow, though. The code works fine, it just has logical errors in it leading to it being screwy, depending what number is set and what numbers are guessed. (Which obviously isn't a good thing). And if you're still unsure of what it is I'm trying to do, take a look at the wiki page for the game: http://en.wikipedia.org/wiki/Mastermind_(board_game) ...Yeah, that was supposed to be linked way back up in the first post, I dunno how the other page ended up getting linked. Must've had the wrong thing copied at the time.
Posted By: 5618 Re: mIRC Programming Tutorial? - 27/01/09 04:50 PM
I haven't tested it, but try this...
Code:
on 1:text:*guess*:#: {
  if ($1 == %c $+ guess) {
    if (%mnum == $null) { msg $chan I'm not thinking of a number yet. | halt }
    if ($2 !isnum 1000-9999) { msg $chan Enter a number between 1000 and 9999 | halt }
    if ($2 == %mnum) { 
      msg $chan That's right! %mnum $+ ! You win, $nick $+ ! And it only took %counter guesses. Type !mastermind to start a new guessing game.
      unset %mnum | halt
    }
    if ($2 != %mnum) { 
      inc %counter
      var %gfnum = $mid($2, 1, 1), %gsnum = $mid($2, 2, 1), %gtnum = $mid($2, 3, 1), %ghnum = $mid($2, 4, 1)
      var %correct = 0, %close = 0
      var %numbers = $+(%fnum,.,%snum,.,%tnum,.,%hnum)
      if (%gfnum == %fnum)      { inc %correct | var %numbers = $remtok(%numbers,%gfnum,1,46) }
      if (%gsnum == %snum)      { inc %correct | var %numbers = $remtok(%numbers,%gsnum,1,46) }
      if (%gtnum == %tnum)      { inc %correct | var %numbers = $remtok(%numbers,%gtnum,1,46) }
      if (%ghnum == %hnum)      { inc %correct | var %numbers = $remtok(%numbers,%ghnum,1,46) }
      if (%gfnum isin %numbers) { inc %close | var %numbers = $remtok(%numbers,%gfnum,1,46) }
      if (%gsnum isin %numbers) { inc %close | var %numbers = $remtok(%numbers,%gsnum,1,46) }
      if (%gtnum isin %numbers) { inc %close | var %numbers = $remtok(%numbers,%gtnum,1,46) }
      if (%ghnum isin %numbers) { inc %close | var %numbers = $remtok(%numbers,%ghnum,1,46) }
      msg $chan You have %correct correct.
      msg $chan You have %close out of place.
    }
  }
}


P.S. You may want to use $rand(1000,9999) to set %mnum, since now your number will never contain zeros, unless that is you intention. If that is indeed your intention, then you should probably change your statement where you check if the input isnum 1000-9999 to also check for "if (0 !isin $$2)" or people may be trying with zeros for ages.
Posted By: Fernin Re: mIRC Programming Tutorial? - 27/01/09 05:59 PM
Hmm, that's a lot better than what I had, but there's still some tinkering to be done... I noticed that the $remtok block always removed %gfnum from %numbers, I'm assuming it's supposed to be two %gfnums, two %gsnums, so on down the line. Even after making that switch, however, there's still some logical errors somewhere in it. Testing out 1223 right now, when I guess 1111, it tells me I have one correct and one out of place. Same number, guessing 2222, it tells me I have two correct and one out of place, guessing 3333, it tells me 1 correct and 0 out of place. The 3 seems to be the only one working, though I haven't figured out why yet. Progress is definitely good, though, and I do appreciate all your help. smile
Posted By: 5618 Re: mIRC Programming Tutorial? - 27/01/09 06:28 PM
I did mess up those vars, yes. Maybe you changed it incorrectly? Try with my (now) edited code. I see no reason why you'd get '1 out of place'.
Posted By: Fernin Re: mIRC Programming Tutorial? - 27/01/09 07:39 PM
I didn't change them incorrectly, they were spot on. You're absolutely right that it should work, but for whatever reason, it isn't. I have exactly what you have down, but it's still not working. I'm trying to figure out, logically, how 2222 could end up with 1 correct and 2 out of place, and I'm ending up confused... It'd check the first 2, find that it is in %numbers, add 1 to %close, then remove a 2 from %numbers. But then, how would there still be a pair of 2's for it to tell me that there are 2 correct?
Posted By: 5618 Re: mIRC Programming Tutorial? - 27/01/09 07:45 PM
Note that my code may have changed since you last looked at it. wink
Posted By: Fernin Re: mIRC Programming Tutorial? - 29/01/09 01:47 AM
Well, that new code has definitely come the closest to being right, but there's still some errors when the actual number has 2 or more digits the same... I logged this earlier today.

[14:13] <not_sure> !guess 2359
[14:13] <+LexiaBot9000> You have 2 correct and 2 out of place.
[14:14] <not_sure> !guess 2953
[14:14] <+LexiaBot9000> You have 0 correct and 3 out of place.
[14:14] <not_sure> uh oh
[14:14] <Fernin> ohhh bother...
[14:14] <not_sure> !guess 5329
[14:14] <+LexiaBot9000> You have 3 correct and 1 out of place.
[14:15] <not_sure> well, umm
[14:15] <not_sure> !guess 2222
[14:15] <+LexiaBot9000> You have 0 correct and 0 out of place.
[14:15] <not_sure> !guess 3333
[14:15] <+LexiaBot9000> You have 2 correct and 0 out of place.
[14:15] <not_sure> !guess 5339
[14:15] <+LexiaBot9000> That's right! 5339! You win, not_sure!

And unrelated to that is another problem I'm having, setting up a score file for it to keep track of everyone's scores.

Code:
on 1:text:*score:#: {
  if ($1 == %c $+ score) {
    set %sname $2
    if (%sname != $null) && ($readini(ini\mastermind.rank,Rank,%sname) != $null) {
      msg $chan %sname $+ 's current record is $readini(ini\mastermind.rank,Rank,%sname) guesses.
    }
    if (%sname != $null) && ($readini(ini\mastermind.rank,Rank,%sname) == $null) {
      msg $chan I don't have any records for nick %sname $+ .
    }
    if (%sname == $null) && ($readini(ini\mastermind.rank,Rank,$nick) != $null) {
      msg $chan $nick $+ , your current record is $readini(ini\mastermind.rank,Rank,$nick) guesses.
    }
    else {
      msg $chan ...Who the hell are you again? I don't have any records for $nick $+ .
    }    
  }
}


As of now, the else works, and the third if, with %sname null and their record not null also works. However, when you try to look up either a name it does or doesn't have, it does nothing. What'd I screw up this time?

Edit: Before you ask, and I know you will since it's the obvious thing to ask, the file does exist, in that location, and I know it's being written to correctly when they get an answer right.
Posted By: 5618 Re: mIRC Programming Tutorial? - 29/01/09 04:01 PM
Ok, quick (dirty) fix:
Code:
    if ($2 != %mnum) { 
      inc %counter
      var %gfnum = $mid($2, 1, 1), %gsnum = $mid($2, 2, 1), %gtnum = $mid($2, 3, 1), %ghnum = $mid($2, 4, 1)
      var %correct = 0, %close = 0
      var %numbers = $+(%fnum,.,%snum,.,%tnum,.,%hnum)
      if (%gfnum == %fnum)      { inc %correct | var %gfnum = x | var %numbers = $remtok(%numbers,%gfnum,1,46) }
      if (%gsnum == %snum)      { inc %correct | var %gsnum = x | var %numbers = $remtok(%numbers,%gsnum,1,46) }
      if (%gtnum == %tnum)      { inc %correct | var %gtnum = x | var %numbers = $remtok(%numbers,%gtnum,1,46) }
      if (%ghnum == %hnum)      { inc %correct | var %ghnum = x | var %numbers = $remtok(%numbers,%ghnum,1,46) }
      if (%gfnum isin %numbers) { inc %close | var %numbers = $remtok(%numbers,%gfnum,1,46) }
      if (%gsnum isin %numbers) { inc %close | var %numbers = $remtok(%numbers,%gsnum,1,46) }
      if (%gtnum isin %numbers) { inc %close | var %numbers = $remtok(%numbers,%gtnum,1,46) }
      if (%ghnum isin %numbers) { inc %close | var %numbers = $remtok(%numbers,%ghnum,1,46) }
      msg $chan You have %correct correct.
      msg $chan You have %close out of place.
    }

And...
Code:
on 1:text:*score:#: {
  if ($1 == %c $+ score) {
    if ($2) {
      set %sname $2
      if ($readini(ini\mastermind.rank,Rank,%sname)) { msg $chan %sname $+ 's current record is $v1 guesses. }
      else { msg $chan I don't have any records for nick %sname $+ . }
    }
    elseif ($readini(ini\mastermind.rank,Rank,$nick)) { msg $chan $nick $+ , your current record is $v1 guesses. }
    else { msg $chan ...Who the hell are you again? I don't have any records for $nick $+ . }    
  }
}

Your initial code wasn't exactly wrong, I just made it look nicer/more efficient. Your problem was the matchtext section of the on TEXT event:
Code:
on 1:text:*score:#: {

You're matching *score so any sentence ending in score, like !score, flooblescore, highscore, but not score Fernin or scoresofwomen.
Posted By: Fernin Re: mIRC Programming Tutorial? - 29/01/09 05:30 PM
I'm starting to wonder if this thing is even possible... It always seems to get wonky if there's double numbers involved. It works perfectly fine if each number is different, though. Here's a new log just taken...

[12:13] <Fernin> !guess 1111
[12:13] <+LexiaBot9000> You have 0 correct.
[12:13] <+LexiaBot9000> You have 0 out of place.
[12:13] <Fernin> !guess 2345
[12:13] <+LexiaBot9000> You have 1 correct.
[12:13] <+LexiaBot9000> You have 0 out of place.
[12:13] <Fernin> !guess 6789
[12:13] <+LexiaBot9000> You have 1 correct.
[12:13] <+LexiaBot9000> You have 1 out of place.
[12:13] <Fernin> ...
[12:14] <Fernin> !guess 0000
[12:14] <+LexiaBot9000> Enter a four digit number between 1111 and 9999
[12:14] <Fernin> !guess 2222
[12:14] <+LexiaBot9000> You have 1 correct.
[12:14] <+LexiaBot9000> You have 1 out of place.
[12:14] <Fernin> !guess 3333
[12:14] <+LexiaBot9000> You have 0 correct.
[12:14] <+LexiaBot9000> You have 0 out of place.
[12:14] <Fernin> !guess 6666
[12:14] <+LexiaBot9000> You have 0 correct.
[12:14] <+LexiaBot9000> You have 0 out of place.
[12:14] <Fernin> !guess 7777
[12:14] <+LexiaBot9000> You have 2 correct.
[12:14] <+LexiaBot9000> You have 2 out of place.
[12:14] <not_sure> broken still
[12:14] <Fernin> !guess 8888
[12:14] <+LexiaBot9000> You have 1 correct.
[12:14] <+LexiaBot9000> You have 1 out of place.
[12:14] <Fernin> very much so
[12:14] <Fernin> !guess 2778
[12:14] <+LexiaBot9000> That's right! 2778! You win, Fernin! And it only took 9 guesses. Type !mastermind to start a new guessing game.
Posted By: qwerty Re: mIRC Programming Tutorial? - 29/01/09 08:24 PM
The score-calculating code isn't quite correct. One error is the fact that %g*num vars are set to "x" before they are used in $remtok, whereas this should happen afterwards. But that's not the only problem (eg it fails with number = 8888, guess = 1118).

Here's an alternative that works with numbers of any length (not just 4).
Code:
; $mmscore(actual, guess)
; eg $mmscore(2778,7777)
; returns <correct> <close>
; ("2 0" for the above example)
alias mmscore {
  var %i = 1, %correct = 0, %close = 0
  while $mid($2,%i,1) != $null {
    if $v1 == $mid($1,%i,1) {
      inc %correct
      tokenize 32 $left($1,$calc(%i - 1)) $+ $right($1,- $+ %i) $&
        $left($2,$calc(%i - 1)) $+ $right($2,- $+ %i)
    }
    else inc %i
  }
  %i = 1
  while $mid($2,%i,1) != $null {
    if $pos($1,$v1) {
      inc %close
      tokenize 32 $left($1,$calc($v1 - 1)) $+ $right($1,- $+ $v1) $2
    }
    inc %i
  }
  return %correct %close
}
Posted By: Fernin Re: mIRC Programming Tutorial? - 01/02/09 07:48 AM
Back once again, the mastermind code you suggested worked perfectly, qwerty, that game is running smoothly now. I also finished up a craps game, which was far easier to program. I've gotten a better handle on the language over the past few weeks, and started to tinker around with the programs that came with the bot. One of them is a timebomb program, in which it kicks a person unless they're able to !snip a randomly selected wire from a randomly selected number of wires. I inserted the if statement to reset the code to 32 if it happens to come up 1, screwing them over instead of giving them a free pass, but it's not quite working yet. There's a lot more involved in this program, but this is the only part that could be going wrong...

Code:
  else {
    set %timeBombDuration $rand(%permTimebombMinimumDuration,%permTimebombMaximumDuration)
    set %TimebombTargetNick %timeBombNick
    set %TimebombTargetChan %timeBombChan
    set %timeBombnumberOfWires $rand(1,%permTimebombMaxWireCount)
    if (%timeBombnumberOfWires == 1) { set %timeBombnumberOfWires 32 }
    var %TimebombTempWireChoices %permTimebombWireChoices
    var %TimebombINC 1
    while (%TimebombINC <= %timeBombnumberOfWires) {
      var %TimebombCurrentWire = $gettok(%TimebombTempWireChoices,$rand(1,%timeBombnumberOfWires),32)
      var %TimebombTempWireChoices = $remtok(%TimebombTempWireChoices,%TimebombCurrentWire,1,32)
      var %TimebombSelectedWires = $addtok(%TimebombSelectedWires,%TimebombCurrentWire,32)
      inc %TimebombINC
    }
    set %TimeBombCorrectWire $gettok(%TimebombSelectedWires,$rand(1,$numtok(%TimebombSelectedWires,32)),32)
    set %timeBomblistOfWires They are %TimebombSelectedWires $+ .
  }


permTimebombWireChoices is a list of 34 different colors, space deliminated. When I was testing it, I had it rigged to always come up as 1 to be reset to 32, and that was working, it was telling me I had 32 wires. However, when it displayed the colors, I'd get anywhere from 6 to 14 colors, never the full 32. The only thing I can think of is that it's somehow choosing nothing as the color and adding nothing to the list, but that shouldn't be possible due to the $remtok in the loop. I feel like I've come here too often for help already, but... What's gone wrong this time?
Posted By: Fernin Re: mIRC Programming Tutorial? - 07/02/09 08:07 AM
Isn't there anyone that can help me with that timebomb code?

...Please?
Posted By: Horstl Re: mIRC Programming Tutorial? - 07/02/09 01:05 PM
Instead of:
var %TimebombCurrentWire = $gettok(%TimebombTempWireChoices,$rand(1,%timeBombnumberOfWires),32)
try:
var %TimebombCurrentWire = $gettok(%TimebombTempWireChoices,$rand(1,$numtok(%TimebombTempWireChoices,32)),32)

(You want to pick a random wire out if all the remaining possible wires, not out of the first N of the possible wires, where N is the number of wires-to-pick)
© mIRC Discussion Forums