mIRC Homepage
Posted By: _DuDe_ Help, I've fallen and I can't get up. - 13/06/05 11:12 PM
Ok, so I made a bot recently, and I was making a !ban script. I can not get it to stop after it hits a notice. I have it set uo to message you if you try and ban an Op, but it dosn't not ban it.

Code:
 on *:TEXT:!ban*:*: {
  if ($2 == $me) { notice $nick I will not Ban my self. }
  if ($nick isop $chan) {
    if ($2 isop $chan) { notice $nick $2 is protected, sorry. | .halt }
    if ($2 !isop $chan) { mode $chan +b $address($2 ,9) }
  }
  if ($nick !isop $chan) { notice $nick You do not have permission to my commands. }
}
  


Anyhelp would be greatful. Also, I am running on 32 hours of no sleep, so don't laugh if the answer is simple.
Posted By: DaveC Re: Help, I've fallen and I can't get up. - 13/06/05 11:22 PM
Without changing any of your code (besides removing a halt) you could do this...

Code:
on *:TEXT:!ban*:*: {
  if ($2 == $me) { notice $nick I will not Ban my self. }
  elseif ($nick isop $chan) {
    if ($2 isop $chan) { notice $nick $2 is protected, sorry. }
    elseif ($2 !isop $chan) { mode $chan +b $address($2 ,9) }
  }
  elseif ($nick !isop $chan) { notice $nick You do not have permission to my commands. }
}


It can be improved alot still, but i need more coffee myself.
Posted By: _DuDe_ Re: Help, I've fallen and I can't get up. - 13/06/05 11:27 PM
I figured it out. I had forgotten my old script on there that had no restrictions to who it could ban, and it was looking for !b*. LoL
Thanks Though!
Posted By: IR_n00b Re: Help, I've fallen and I can't get up. - 13/06/05 11:57 PM
editing your code, to make it better:
Code:
 on *:TEXT:!ban *:#: {

  if ($nick isop $chan) {
  if ($address($2,2) == $address($me,2)) .notice $nick I will not ban myself.
    elseif ($2 isop $chan) notice $nick $2 is protected, sorry.
    elseif ($2 !isop $chan) ban $chan $2 9
  }
  else notice $nick You do not have permission to my commands.
}

This should work a little bit faster, the { braket is a command that searches for a } braket, then executes everything inbetween them.
also using /halt is bad. you should use /return, because /halt may cause other events after it to stop, and if its an alias it stops the script from continuing to be processed.
Posted By: DaveC Re: Help, I've fallen and I can't get up. - 14/06/05 12:17 AM
Quote:
because /halt may cause other events after it to stop


Halt doesnt have this effect. if it did what would the purpose of $halted be?
Posted By: _DuDe_ Re: Help, I've fallen and I can't get up. - 14/06/05 12:22 AM
AHHHH, now I can't get the other stuf to function.

Code:
on@ *:TEXT:!kick*:*: {
  if ($2 == $me) { notice $nick I will not kick my self. }
  elseif ($nick isop $chan) {
    if ($2 isop $chan) { notice $nick $2 is protected, sorry. }
    elseif ($2 !isop $chan) { kick $chan $2 $3- }
  }
  elseif ($nick !isop $chan) { notice $nick You do not have permission to my commands. }
}

on@ *:TEXT:!ban*:*: {
  if ($2 == $me) { notice $nick I will not Ban my self. }
  elseif ($nick isop $chan) {
    if ($2 isop $chan) { notice $nick $2 is protected, sorry. }
    elseif ($2 !isop $chan) { mode $chan +b $address($2 ,9) }
  }
  elseif ($nick !isop $chan) { notice $nick You do not have permission to my commands. }
}

on@ *:TEXT:!unban*:*: {
  if ($2 == $me) { notice $nick I am not banned. }
  elseif ($nick isop $chan) {
    if ($2 isop $chan) { mode $chan -b $address($2 ,9) }
    elseif ($2 !isop $chan) { mode $chan -b $address($2 ,9) }
  }
  elseif ($nick !isop $chan) { notice $nick You do not have permission to my commands. }
}

on@ *:TEXT:!op*:*: {
  if ($2 == $me) { notice $nick I am already op'ed. }
  elseif ($nick isop $chan) {
    if ($2 isop $chan) { notice $nick $2 is already op'ed }
    elseif ($2 !isop $chan) { mode $chan +o $2 }
  }
  elseif ($nick !isop $chan) { notice $nick You do not have permission to my commands. }
}

on@ *:TEXT:!deop*:*: {
  if ($2 == $me) { notice $nick I will not deop my self. }
  elseif ($nick isop $chan) {
    if ($2 isop $chan) { mode $chan -o $2 }
    elseif ($2 !isop $chan) { notice $nick $2 is not even op'ed. }
  }
  elseif ($nick !isop $chan) { notice $nick You do not have permission to my commands. }
}
  
Posted By: DaveC Re: Help, I've fallen and I can't get up. - 14/06/05 12:50 AM
might be

on@ *:

replace with

on @*:
Posted By: _DuDe_ Re: Help, I've fallen and I can't get up. - 14/06/05 12:54 AM
Thanks a bunch, it fixed it. You guys rock!

B.T.W.: If you ever wanna join my server, I would be glad to give you NetAdmin. Either of you. You can find my server in my profile.
Quote:
This should work a little bit faster, the { braket is a command that searches for a } braket, then executes everything inbetween them.

It's advisable to never advise against using both brackets + braces, as that's a very good scripting habit to use.

You're wrong in that it's going to save time or work faster in this case of a simple on text event. It would only save time if you'd issue the code several thousands of iterations in a row, and even then it would still maybe differ just a few milliseconds. Completely neglectible, and not worth it to not use braces when coding.

Let me guess, you've read Yochai's scripting tips... If that's the case you should remember that those tips were written for special occasions like in case of 10k+ iterations. Not a simple on text event.

Additionally, using braces to group multiple commands actually works faster than for example piping the commands on one line. (not the case with this code but I mention it anyway)

Btw I'm not criticizing the way you code, as that's a personal choice, but I do feel no one should ever advise against using braces for nearly unexistant speed gains.
Posted By: IR_n00b Re: Help, I've fallen and I can't get up. - 14/06/05 01:17 AM
i made a script like this for someone, it goes:
Code:
on *:text:!*:#: {
  if ($nick isop $chan) {
    if ($1 == !op) {
      if ($2 == $null) .notice $nick Syntax: !op <nickname>
      elseif ($2 !ison $chan) .notice $nick $2 is not in $+($chan,.)
      elseif ($2 isop $chan) .notice $nick $2 is already an op in $+($chan,.)
      else { cs op $chan $2 }
    }
    elseif ($1 == !deop) {
      if ($2 == $null) .notice $nick Syntax: !deop <nickname>
      elseif ($2 !ison $chan) .notice $nick $2 is not in $+($chan,.)
      elseif ($2 !isop $chan) .notice $nick $2 is not an op in $+($chan,.)
      else { cs deop $chan $2 }
    }
    elseif ($1 == !halfop) {
      if ($2 == $null) .notice $nick Syntax: !halfop <nickname>
      elseif ($2 !ison $chan) .notice $nick $2 is not in $+($chan,.)
      elseif ($2 ishop $chan) .notice $nick $2 is already an halfop in $+($chan,.)
      else { cs halfop $chan $2 }
    }
    elseif ($1 == !dehalfop) {
      if ($2 == $null) .notice $nick Syntax: !halfop <nickname>
      elseif ($2 !ison $chan) .notice $nick $2 is not in $+($chan,.)
      elseif ($2 !ishop $chan) .notice $nick $2 is not an halfop in $+($chan,.)
    else  {cs dehalfop $chan $2 }
  }
  if (($nick isop $chan) || ($nick ishop $chan)) { 
    if ($1 == !voice) {
      if ($2 == $null) .notice $nick Syntax: !voice <nickname>
      elseif ($2 !ison $chan) .notice $nick $2 is not in $+($chan,.)
      elseif ($2 isvoice $chan) .notice $nick $2 is already an voice in $+($chan,.)
      else { cs voice $chan $2  }
    }
    elseif ($1 == !devoice) {
      if ($2 == $null) .notice $nick Syntax: !devoice <nickname>
      elseif ($2 !ison $chan) .notice $nick $2 is not in $+($chan,.)
      elseif ($2 !isvoice $chan) .notice $nick $2 is not an voice in $+($chan,.)
      else { cs devoice $chan $2 }
    }
    elseif ($1 == !kick) {
      if ($2 == $null) .notice $nick Syntax: !kick <nickname> [reason]
      elseif ($2 !ison $chan) .notice $nick $2 is not in $+($chan,.)
      elseif ($nick($chan,$nick,~)) kick $chan $2 Requested: $nick $iif($3 == $null,,$+([,$3-,]))
      elseif ($nick($chan,$nick,&)) {
        if (($nick($chan,$2,&)) || ($nick($chan,$2,~))) .notice $nick You may not kick $2 $+ .
        else { kick $chan $2 Requested: $nick $iif($3 == $null,,$+([,$3-,])) }
      }
      elseif ($nick isop $chan) {
        if (($nick($chan,$2,&)) || ($nick($chan,$2,~))) .notice $nick You may not kick $2 $+ .
        else { kick $chan $2 Requested: $nick $iif($3 == $null,,$+([,$3-,])) }
      }
      elseif ($nick ishop $chan) {
        if (($nick($chan,$2,&)) || ($nick($chan,$2,~)) || ($nick isop $chan)) .notice $nick You may not kick $2 $+ .
        else { kick $chan $2 Requested: $nick $iif($3 == $null,,$+([,$3-,])) }
      }
    }
    elseif ($1 == !help) {
      if (($nick($chan,$2,&)) || ($nick($chan,$2,~)) || ($nick isop $chan)) .notice $nick Commands avaliable to you: !op,!deop,!voice,!devoice,!halfop, !dehalfop, !kick, !ban, !unban, !help, !kickban, !kb. Say !command for more help.
      else { .notice $nick Commands avaliable to you: !voice, !devoice, !kick, !ban, !unban, !help, !kickban, !kb. Say !command for more help. }
    }
    elseif ($1 == !ban) {
      if ($2 == $null) .notice $nick Syntax: !ban <nickname>
      elseif ($2 !ison $chan) .notice $nick $2 is not in $+($chan,.)
      elseif ($nick($chan,$nick,~)) {
        mode $chan +b $address($2,12)
        writeini ban.ini bans $2 $address($2,5)
      }
      elseif ($nick($chan,$nick,&)) {
        if (($nick($chan,$2,&)) || ($nick($chan,$2,~))) .notice $nick You may not ban $2 $+ .
        else {
          mode $chan +b $address($2,12)
          writeini ban.ini bans $2 $address($2,5)
        }
      }
      elseif ($nick isop $chan) {
        if (($nick($chan,$2,&)) || ($nick($chan,$2,~))) .notice $nick You may not ban $2 $+ .
        else {
          mode $chan +b $address($2,12)
          writeini ban.ini bans $2 $address($2,5)
        }  
      }
      elseif ($nick ishop $chan) {
        if (($nick($chan,$2,&)) || ($nick($chan,$2,~)) || ($nick isop $chan)) .notice $nick You may not kick $2 $+ .
        else {
          mode $chan +b $address($2,12)
          writeini ban.ini bans $2 $address($2,5)
        }    
      }
    }
    elseif ($1 == !unban) {
      if ($readini(ban.ini,bans,$2) == $null) .notice $nick I dont remember $+($2,'s) address.
      else {
        var %address = $readini(ban.ini,bans,$2)
        var %n = $ibl($chan,0)
        while (%n > 0) {
          if ($ibl($chan,%n) iswm %address) { 
            mode $chan -b $ibl($chan,%n)
            var %try = true
          }
          dec %n
        }
        var %n = $ibl($chan,0)
        var %address = $replace(%address,1,?,2,?,3,?,4,?,5,?,6,?,7,?,8,?,9,?,0,?)
        while (%n > 0) {
          if ($ibl($chan,%n) iswm %address) { 
            mode $chan -b $ibl($chan,%n)
            var %try = true
          }
          dec %n
        }
        if (%try != true) .notice $nick $2 is not banned. It may be a ~c:#channel ban.
        else msg $chan $2 has been unbaned.
      }
    }
    elseif (($1 == !kb) || ($1 == !kickban)) {
      if ($2 == $null) .notice $nick Syntax: <!kb|!kickban> <nickname> [reason]
      elseif ($2 !ison $chan) .notice $nick $2 is not in $+($chan,.)
      elseif ($nick($chan,$nick,~)) {
        mode $chan +b $address($2,12)
        writeini ban.ini bans $2 $address($2,5)
      }
      elseif ($nick($chan,$nick,&)) {
        if (($nick($chan,$2,&)) || ($nick($chan,$2,~))) .notice $nick You may not ban $2 $+ .
        else {
          mode $chan +b $address($2,12)
          writeini ban.ini bans $2 $address($2,5)
          kick $chan $2 Requested: $nick $iif($3 == $null,,$+([,$3-,]))
        }
      }
      elseif ($nick isop $chan) {
        if (($nick($chan,$2,&)) || ($nick($chan,$2,~))) .notice $nick You may not ban $2 $+ .
        else {
          mode $chan +b $address($2,12)
          writeini ban.ini bans $2 $address($2,5)
          kick $chan $2 Requested: $nick $iif($3 == $null,,$+([,$3-,]))
      }      }
      elseif ($nick ishop $chan) {
        if (($nick($chan,$2,&)) || ($nick($chan,$2,~)) || ($nick isop $chan)) .notice $nick You may not kick $2 $+ .
        else {
          mode $chan +b $address($2,12)
          writeini ban.ini bans $2 $address($2,5)
          kick $chan $2 Requested: $nick $iif($3 == $null,,$+([,$3-,]))
        }    
      }
    }
  }
}
on *:join:#:/writeini ban.ini bans $nick $address($nick,5)

say !help in a channel and it should PM you all the commands it has also you can use !unban in channel to unban someone that has joined while the bot was runnning this script, i made it for unreadircd servers, but comment out the commands you dont need and remove them from !help smile
Posted By: _DuDe_ Re: Help, I've fallen and I can't get up. - 23/06/05 05:45 PM
Help again!!!!

I made an attack section, and when someone with a Strike of say 100,000,000 attacks someone with a defense of 1,000, the attacker makes an unbelievable ammount of gold, example 3,000,000,000, and the defender only has around 20,000 gold. It gives the attacker all 3,000,000,000 gold, and only takes away 3/4's of the defenders gold. I am so lost.

Code:
on *:TEXT:!attack*:*: {
  if ($2 == $null) { /msg $nick Please type !attack <nick> to attack someone | .halt
  }
  if ($2 != $null) && ( $readini( $2 $+ .ini, THINGS, gold) == $null) { /msg $nick Please attack someone that has gold. | .halt
  }
  if ($2 != $null) && ( $readini( $2 $+ .ini, THINGS, gold) != $null) {
    /msg $nick Attacking $2
    var %attack = $readini( $nick $+ .ini, THINGS, strike)
    var %defense = $readini( $2 $+ .ini, THINGS, defense)
    var %result = $calc( %attack - %defense )
  }
  if ( %result > 0 ) {
    var %loot = $round( $calc( $readini( $nick $+ .ini, THINGS, gold) + $calc( $readini( $2 $+ .ini, THINGS, gold) * .75 )) , 0)
    writeini $nick $+ .ini THINGS gold %loot
    writeini $2 $+ .ini THINGS gold $round( $calc( $readini( $2 $+ .ini, THINGS, gold) - $calc( $readini( $2 $+ .ini, THINGS, gold) * .75 )) , 0)
    msg $nick You Won  $bytes( %loot , b )  !
  }
  elseif ( %result <= 0 ) { msg $nick You Lost. }
}
 
© mIRC Discussion Forums