mIRC Home    About    Download    Register    News    Help

Print Thread
Page 1 of 3 1 2 3
#108020 16/01/05 08:43 AM
Joined: Nov 2004
Posts: 332
R
Fjord artisan
OP Offline
Fjord artisan
R
Joined: Nov 2004
Posts: 332
i recently went ahead and made a help system for my bot
while it isnt very complex its pretty long i was looking for suggestions to shorten it
sigh deep breath
-----------------------------code----------------------------------------
#help on
on *:text:!help:*:{
if (%i = on) { halt }
else { msg $nick $read(help.txt,n,1) }
{ msg $nick $read(help.txt,n,2) }
{ msg $nick $read(help.txt,n,3) }
{ msg $nick $read(help.txt,n,4) }
{ msg $nick $read(help.txt,n,5) }
{ msg $nick $read(help.txt,n,6) }
{ msg $nick $read(help.txt,n,7) }
{ msg $nick $read(help.txt,n,8) }
{ msg $nick $read(help.txt,n,9) }
{ msg $nick $read(help.txt,n,10) }
{ msg $nick $read(help.txt,n,11) }
{ set -s %i on }
{ timer 1 20 unset -s %i }
}
on *:text:!help !qme:*:{
if (%j = on) { halt }
else { msg $nick $read(help.txt,n,12) }
{ set -s %j on }
{ timer 1 20 unset -s %j }
}
on *:text:!help !say:*:{
if (%k = on) { halt }
else { msg $nick $read(help.txt,n,13) }
{ set -s %k on }
{ timer 1 20 unset -s %k }
}
on *:text:!help !die:*:{
if (%l = on) { halt }
else { msg $nick $read(help.txt,n,14) }
{ set -s %l on }
{ timer 1 20 unset -s %l }
}
on *:text:!help !join:*:{
if (%m = on) { halt }
else { msg $nick $read(help.txt,n,15) }
{ set -s %m on }
{ timer 1 20 unset -s %m }
}
on *:text:!help !part:*:{
if (%n = on) { halt }
else { msg $nick $read(help.txt,n,16) }
{ msg $nick $read(help.txt,n,17) }
{ set -s %n on }
{ timer 1 20 unset -s %n }
}
on *:text:!help !cycle:*:{
if (%o = on) { halt }
else { msg $nick $read(help.txt,n,18) }
{ set -s %o on }
{ timer 1 20 unset -s %o }
}
on *:text:!help !enable:*:{
if (%p = on) { halt }
else { msg $nick $read(help.txt,n,19) }
{ msg $nick $read(help.txt,n,20) }
{ set -s %p on }
{ timer 1 20 unset -s %p }
}
on *:text:!help !disable:*:{
if (%q = on) { halt }
else { msg $nick $read(help.txt,n,21) }
{ set -s %q on }
{ timer 1 20 unset -s %q }
}
on *:text:!help !ruser:*:{
if (%r = on) { halt }
else { msg $nick $read(help.txt,n,22) }
{ msg $nick $read(help.txt,n,23) }
{ set -s %r on }
{ timer 1 20 unset -s %r }
}
on *:text:!help !pass:*:{
if (%s = on) { halt }
else { msg $nick $read(help.txt,n,21) }
{ set -s %s on }
{ timer 1 20 unset -s %s }
}
#help end
----------------------------------code----------------------------------


The Kodokan will move you, one way or another.
#108021 16/01/05 09:22 AM
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Code:
#help on
on *:text:!help:*:     { if (%i != on) { sendhelp $nick 1 11  | set -su20 %i on }
on *:text:!help !qme:*:{ if (%j != on) { sendhelp $nick 12 12 | set -su20 %j on }
on *:text:!help !say:*:{ if (%k != on) { sendhelp $nick 13 13 | set -su20 %k on }
on *:text:!help !die:*:{ etc etc etc
...
on *:text:!help !pass:*:{ if (%s != on) { sendhelp $nick 21 21 | set -su20 %s on }

alias -l sendhelp { 
  var %i = $2
  while (%i <= $3) {
    msg $1 $read(help.txt,n,%i)
    inc %i
  }
}


if u wanted to reformat your help.txt file to like this
[help]
old line1
old line2
old line3
...
old line11
[!qme]
old line12
[!say]
old line13

etc etc
you could now use this
Code:
#help on
on *:text:!help:*:     { if (%i != on) { play -thelp $nick 0  | set -su20 %i on }
on *:text:!help !qme:*:{ if (%j != on) { play -t!qme $nick 0  | set -su20 %j on }
on *:text:!help !say:*:{ if (%k != on) { play -t!say $nick 0  | set -su20 %k on }
on *:text:!help !die:*:{ etc etc etc
...
on *:text:!help !pass:*:{ if (%s != on) { play -t!pass $nick 0  | set -su20 %s on }


This is heaps better as it allows you to add lines with out the code needing adjustment.

#108022 16/01/05 09:27 AM
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Oh my... I'm amazed the parser allows { as the first character in a line!
  • Who told you that you have to put every command between braces { } ? like

    { msg $nick $read(help.txt,n,1) }
    { msg $nick $read(help.txt,n,2) }

    The way to use if-then-else is like this:

    if (condition) {
    commands
    }
    elseif (another condition) {
    other commands
    }
    else {
    commands to do when no conditions have been met
    }

    And of course the if-then-else can be nested in other if then else constructs.

    You see how each condition starts with an opening brace { and ends that part of the code with a closing brace } ?

    Note that the else part isn't mandatory, if you don't have default commands, then you just leave it, instead of what some people do, which is totally obsolete: else { halt }


  • Note that braces are only needed to group multiple commands together.

    In the case of single commands, you don't need them, but you can use them. Always use either brackets ( ), or braces { }, or preferably both of them together ( ) { }, unless if you really know what you are doing.

    Example:

    Code:
    alias myalias {
    [color:red]  [/color] 
      if ($1 == !test) echo -a only brackets 
    [color:red]  [/color] 
      elseif $1 == !help { echo -a only braces }
    [color:red]  [/color] 
      elseif ($1 == !add) { echo -a both brackets and braces }
    [color:red]  [/color] 
      elseif $1 == !info {
    [color:red]  [/color] 
        echo -a first command
        echo -a second command
        echo -a third command
    [color:red]  [/color] 
      }
    
      else { echo -a Unknown command: $1 }
    
    }


  • The if, elseif, else construct has as benefit that if one condition matches, mirc will discard the following "elseifs" and "else" and goes to the end of the elseif/else conditions. This speeds up processing, as otherwise mIRC would go through each of those "if" lines to look if $1 matches, but that is completely obsolete, since it already matched exclusively.

    For example, in that alias I just provided, if you do: /myalias !test, mirc will do the following:

    1. it matches: if ($1 == !test)
    2. it performs the commands that go with that match: echo -a only brackets
    3. it sees that the rest of the if conditions are elseif's and an else, so the alias is finished.


    In some cases, it's needed to do multiple if's without making mIRC stop the script after having 1 match.

    Example:
    Code:
    alias alphabet {
    [color:red]  [/color] 
      if (*a* iswm $1) { echo -a found an "a" }
      if (*b* iswm $1) { echo -a found a "b" }
      ...
      if (*z* iswm $1) { echo -a found a "z" }
    [color:red]  [/color] 
    }
    
    


    Now if we do: /alphabet azerty

    What does mIRC do?

    1. it matches: if (*a* iswm $1)
    2. it performs the command associated with the match: echo -a found an "a"
    3. it matches: if (*e* iswm $1)
    4. it performs the command associated with the match: echo -a found an "e"
    ...

    In this case, we don't want to use elseif's, because after finding 1 match, mirc would skip all the elseif's and else, while we want to actually check each condition.
  • The examples provided are solely for educational purposes, and to get a point accross.

  • I didn't look at the rest, because I would have ended up rewriting your whole script. There is a lot of room to improve ricky, good luck!

Greeits

Last edited by FiberOPtics; 16/01/05 10:26 AM.

Gone.
#108023 16/01/05 10:04 AM
Joined: Nov 2004
Posts: 332
R
Fjord artisan
OP Offline
Fjord artisan
R
Joined: Nov 2004
Posts: 332
it works fine actually
i was just looking to shorten it


The Kodokan will move you, one way or another.
#108024 16/01/05 10:20 AM
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Well, if you remove all those excessive braces, it will already be half as long :tongue:


Gone.
#108025 16/01/05 10:41 PM
Joined: Nov 2004
Posts: 332
R
Fjord artisan
OP Offline
Fjord artisan
R
Joined: Nov 2004
Posts: 332
i actuallydid that
ill still need a modular alias for that global antiflood thing

and if dave could swoop in and clarify that bit of code he provided after the alias section
i couldnt quite follow it


The Kodokan will move you, one way or another.
#108026 16/01/05 10:52 PM
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
A note before I do anything else, for some reason a closing } are missing off all my lines for some reason, i thought it was the cut and paste but now i think i might have deleted them by accident, oh well hope it didnt cuase confusion.

lines such as
on *:text:!help:*: { if (%i != on) { sendhelp $nick 1 11 | set -su20 %i on }
should have been
on *:text:!help:*: { if (%i != on) { sendhelp $nick 1 11 | set -su20 %i on } }

but anyway.... what bit didnt uou understand?
was it the alias -l sendhelp or the suff about the reformating and using /play ?


Oh PS: this was formated baddly
Code:
on *:text:!help:*:{
  if (%i = on) { halt }  
  else { msg $nick $read(help.txt,n,1) }
  { msg $nick $read(help.txt,n,2) }
  ...
  { msg $nick $read(help.txt,n,11) }
  { set -s %i on }
  { timer 1 20 unset -s %i }
}

it just happened to do what u wanted, only line 1 was part of the ELSE construct, the rest were always going to be executed by the event, its just that you had used HALT to stop the other condition from procedding to the line following the IF's construct, being this line ... { msg $nick $read(help.txt,n,2) }

[edit]

EEEEEEK omg i stuffed up the /play commands as well
they all should be like this play -thelp $nick help.txt 0 with the help.txt file specified after the $nick

Last edited by DaveC; 16/01/05 10:56 PM.
#108027 16/01/05 11:24 PM
Joined: Nov 2004
Posts: 332
R
Fjord artisan
OP Offline
Fjord artisan
R
Joined: Nov 2004
Posts: 332
the alias
and im unclear of the suggested reformat
do you want me to make each section its own txt
or what
thats alot of switches on play you might want to include what they do if we are to learn anything

Last edited by ricky_knuckles; 16/01/05 11:26 PM.

The Kodokan will move you, one way or another.
#108028 17/01/05 12:00 AM
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
ok the alias, but first...

on *:text:!help !pass:*:{ if (%s != on) { sendhelp $nick 21 21 | set -su20 %s on } }
When someone says "!help !pass" u want to msg them line 21 of the file IF %s is not "on", so i check %s not = to "on" and if so, then i call my alias passing it who to send to in $1, starting line to send in $2, ending line in $3, aka "$nick 21 21", then i set %s to "on" with the auto unset option in 20 seconds.
So now u know what the event does, but more specificly what my alias is ment to do.

Code:
alias -l sendhelp { 
  var %i = $2
  while (%i <= $3) {
    msg $1 $read(help.txt,n,%i)
    inc %i
  }
}

The -l stops something else calling sendhelp besides your events, liekly not needed but who knows.
ok I set %i to the starting line to send
i then start a while loop that keeps going whilel %i is less or = to the ending line, in that loop, i send $1 (the $nick) said %i line from the file, then add one to %i, it then repeats untill %i is greater than the ending line (which happens to be the starting line also in !pass)

The second option i gave you, you must reformat the help.txt file, its still text, but u need section headers in [ ], then u can use the /play command to just play (msg) all the lines in that section to the $nick
the file might look like this...
[help]
this is my help on my bot there are a buch of commands it can do.
you can get help on each of them by doing
!help !qme
!help !say
!help !die
[!qme]
The !qme command well it doesnt work on tuesdays
Unless your blonde and good looking and interested in me.
[!die]
The !die command makes you drop dead right there at your pc.
[!say]
The !say command well it doesnt say much right now
[!bobthemagicdragon]
The command makes bob the dragon appear, ps hes magic


doing a " /play -t!qme $nick help.txt 0 " well play (msg) $nick the following 2 lines.....
The !qme command well it doesnt work on tuesdays
Unless your blonde and good looking and interested in me.

becuase they were under the heading !qme the bit follwoing the -t

For more help on /play, just type /HELP /PLAY in mirc.

#108029 17/01/05 12:07 AM
Joined: Nov 2004
Posts: 332
R
Fjord artisan
OP Offline
Fjord artisan
R
Joined: Nov 2004
Posts: 332
ok well i understand the play formatted one now i dont think ill ever be able to follow the first one
thanks,


The Kodokan will move you, one way or another.
#108030 17/01/05 12:19 AM
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
i just read the that u said soemthing about a modualr alias to stop it flooding? was that it.

Well the /play command is your option of choice, I set 0 (zero) on the end, becuase i thought u wanted it that fast, but if u set that to another number it delays by that long in 1/1000ths of a second, so 500 is 1/2 second, its defualt is 1000 if u leave it out.

#108031 17/01/05 12:20 AM
Joined: Aug 2003
Posts: 1,831
I
Hoopy frood
Offline
Hoopy frood
I
Joined: Aug 2003
Posts: 1,831
Jusr a note about the /play model. I would not use it with a delay of 0 unless you like being flooded off. try 1000 or 1500. smile

#108032 17/01/05 12:39 AM
Joined: Nov 2004
Posts: 332
R
Fjord artisan
OP Offline
Fjord artisan
R
Joined: Nov 2004
Posts: 332
aliases
/flooda {
set -s %i on
timer 1 5 unset -s %i
}
aliases
remotes
#help on
on *:text:!help:*:{
if (%i != on) { play -t!help $nick help.txt 2000
flooda
}
}
on *:text:!help !qme:*:{
if (%i != on) { play -t!qme $nick help.txt 2000
flooda
}
}
on *:text:!help !say:*:{
if (%i != on) { play -t!say $nick help.txt 2000
flooda
}
}
on *:text:!help !die:*:{
if (%i != on) { play -t!die $nick help.txt 2000
flooda
}
}
on *:text:!help !join:*:{
if (%i != on) { play -t!join $nick help.txt 2000
flooda
}
}
on *:text:!help !part:*:{
if (%i != on) { play -t!part $nick help.txt 2000
flooda
}
}
on *:text:!help !cycle:*:{
if (%i != on) { play -t!cycle $nick help.txt 2000
flooda
}
}
on *:text:!help !enable:*:{
if (%i != on) { play -t!enable $nick help.txt 2000
flooda
}
}
on *:text:!help !disable:*:{
if (%i != on) { play -t!disable $nick help.txt 2000
flooda
}
}
on *:text:!help !ruser:*:{
if (%i != on) { play -t!ruser $nick help.txt 2000
flooda
}
}
on *:text:!help !pass:*:{
if (%i != on) { play -t!pass $nick help.txt 2000
flooda
}
}
#help end

Last edited by ricky_knuckles; 17/01/05 01:17 AM.
#108033 17/01/05 12:43 AM
Joined: Nov 2003
Posts: 2,327
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Nov 2003
Posts: 2,327
Every single one of those if (%i = on) { halt }'s are pointless.


New username: hixxy
#108034 17/01/05 12:49 AM
Joined: Nov 2004
Posts: 332
R
Fjord artisan
OP Offline
Fjord artisan
R
Joined: Nov 2004
Posts: 332
thats true
i put them in because i originally didnt have the != line
but thnks for pointing that out
you failed to mention all the other error that i caught but thanks
like after the 3rd line down play became plat and != became =


The Kodokan will move you, one way or another.
#108035 17/01/05 12:49 AM
Joined: Aug 2003
Posts: 1,831
I
Hoopy frood
Offline
Hoopy frood
I
Joined: Aug 2003
Posts: 1,831
Also half of the time play is mispelt plat
and many of these
  • f (%i = on) { halt }
    if (%i = on) { plat -t!pass $nick help.txt 2000


Code:
  if (%i [color:red]![/color]= on) { pla[color:red]y[/color] -t!pass $nick help.txt 2000 

#108036 17/01/05 12:52 AM
Joined: Nov 2004
Posts: 332
R
Fjord artisan
OP Offline
Fjord artisan
R
Joined: Nov 2004
Posts: 332
already fixed both of those
but good eye


The Kodokan will move you, one way or another.
#108037 17/01/05 12:56 AM
Joined: Nov 2003
Posts: 2,327
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Nov 2003
Posts: 2,327
I noticed, I just presumed you'd left all of the !'s out because you got bored of typing them. wink


New username: hixxy
#108038 17/01/05 12:58 AM
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
None of these events can work properly, because you are not using an opening and closing brace, to group multiple code constructs, as I've told you in that long post.

on *:text:!help !pass:*: {
if (%i != on) {
play -t!pass $nick help.txt 2000
flood
}
}

I don't know what "flood" is, i suppose it's an alias you are triggerin, so I grouped it like that.

Greets


Gone.
#108039 17/01/05 01:00 AM
Joined: Nov 2003
Posts: 2,327
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Nov 2003
Posts: 2,327
/flood:
Quote:
-
* Flood protection is off
* Ctcp protection is on
-


New username: hixxy
Page 1 of 3 1 2 3

Link Copied to Clipboard