All pastes #771095 Raw Edit

Anonymous

public text v1 · immutable
·published 2007-11-12 20:09 UTC
rendered paste body
03[21:05] * OpServ (OpServ@Services.GameSurge.net) has joined #scriptclass
03[21:05] * OpServ sets mode: +o OpServ
05[21:05] -OpServ:#scriptclass- This channel has been temporarily moderated due to a possible join flood attack detected in this channel; network staff have been notified and will investigate.
01[21:08] <@HellRaz0r> i will start in 2mins just giving people a chance to join
01[21:09] <@HellRaz0r> no pms at the moment please
01[21:09] <@HellRaz0r> k lets start
01[21:09] <@HellRaz0r> Hi all. Today i will be teaching you how to make an mIRC bot.
01[21:10] <@HellRaz0r> This lesson only covers the basics so anyone without script knowledge should be able to understand, if you want more advanced information I suggest you visit #scripting #script and www.scriptsurge.org or wait till the next lesson which will be announced in the topic here and on the gamesurge calendar soon.
01[21:10] <@HellRaz0r> I'll unmute the channel briefly at the end so if anyone has questions we will try to answer them.
01[21:10] <@HellRaz0r> I will begin by explaining what script types mIRC uses and how to load them.
01[21:10] <@HellRaz0r> mIRC has 4 types of script you can load they are alias, popup, remote script, variable.
01[21:10] <@HellRaz0r> The type i will be explaining today is remote script. aliases popups and variables are useful but you can put those in a remote script so you often wont need to load scripts of those type.
01[21:11] <@HellRaz0r> If you create an empty text file in notepad and save it as *.mrc in the mIRC directory or use /write -c file.mrc you can then load that file into mIRC remote using /load -rs file.mrc, the file .extension doesnt have to be .mrc but the file will be for an mIRC remote script so its good to use .mrc to make that obvious to anyone that uses your scripts.
01[21:11] <@HellRaz0r> I suggest you create a seperate copy of mIRC for your bot to use then the first thing you must do is create a script file for it like above then load that file, next you will probably want to open up mIRC script editor to begin coding you can access that by pressing Alt+R in any mIRC window.
01[21:11] <@HellRaz0r> Once you have the script editor dialog open you can access your remote script by going to the view menu and selecting it, I often find its wise to write and test most stuff via script editor because any changes you make are automaticly loaded instantly which makes debugging quicker and easier.
01[21:12] <@HellRaz0r> Now we have our empty remote script loaded into script editor we can begin coding :D
01[21:12] <@HellRaz0r> The first thing your bot remote script will need is an on start event like below to set some global variables and make it connect.
03[21:12] * ChanServ sets mode: +b *!*tracer*@*
01[21:12] <@HellRaz0r> on *:start:{
01[21:12] <@HellRaz0r>   set %bot-trig @
01[21:12] <@HellRaz0r>   set %bot-chans #chan1,#chan2
01[21:12] <@HellRaz0r>   set %bot-master *!*@YourAddres
01[21:12] <@HellRaz0r>   set %bot-auth AuthName Password
01[21:12] <@HellRaz0r>   server irc.gamesurge.net
01[21:12] <@HellRaz0r> }
01[21:12] <@HellRaz0r> Then next thing you need an on connect event to perform some commands when the bot connects.
01[21:13] <@HellRaz0r> on *:connect:{
01[21:13] <@HellRaz0r>   if ($network == GameSurge) { 
01[21:13] <@HellRaz0r>     mode $me +x
01[21:13] <@HellRaz0r>     AuthServ Auth %bot-auth
01[21:13] <@HellRaz0r>     join %bot-chans
01[21:13] <@HellRaz0r>   }
01[21:13] <@HellRaz0r> }
01[21:13] <@HellRaz0r> Now that your bot can connect join channels and perform other commands on connect its ready to start accepting commands from the channel, for that your bot will need an on text event like below.
03[21:13] * @OpServ (OpServ@Services.GameSurge.net) has left #scriptclass (Leaving.)
01[21:13] <@HellRaz0r> on *:text:*:#yourchan:{ 
01[21:13] <@HellRaz0r>   if ($1- == %bot-trig $+ Ping) { msg $chan $nick $+ : Pong! }
01[21:13] <@HellRaz0r>   elseif ($1 == %bot-trig $+ 8ball) { 
01[21:13] <@HellRaz0r>     if ($2 == $null) { notice $nick 8ball requires more parameters. }
01[21:13] <@HellRaz0r>     else {
01[21:13] <@HellRaz0r>       var %r1 = Not on your life., %r2 = Reading foggy -- try again later., %r3 = If the prophets will it., %r4 = Yes., %r5 = No.
01[21:13] <@HellRaz0r>       var %r6 = Maybe so., %r7 = Are you mad?, %r8 = What you think?, %r9 = Forever!, %r10 = Never!
01[21:13] <@HellRaz0r>       var %response = %r [ $+ [ $rand(1,10) ] ]
01[21:13] <@HellRaz0r>       msg $chan $nick $+ : %response
01[21:13] <@HellRaz0r>     }
01[21:13] <@HellRaz0r>   }
01[21:13] <@HellRaz0r>   elseif ($1 == %bot-trig $+ Slap) {
01[21:13] <@HellRaz0r>     if ($2 == $null) { notice $nick Slap requires more parameters. }
01[21:13] <@HellRaz0r>     else { describe $chan Slaps $2 around a bit with a large trout. }
01[21:13] <@HellRaz0r>   }
01[21:13] <@HellRaz0r>   elseif ($1 == %bot-trig $+ Say) {
01[21:13] <@HellRaz0r>     if ($wildsite != %botmaster) { notice $nick You are not my botmaster. } 
01[21:13] <@HellRaz0r>     elseif (!$2) { notice $nick Say requires more parameters. }
01[21:13] <@HellRaz0r>     else { say $chan $2- }
01[21:13] <@HellRaz0r>   }
01[21:13] <@HellRaz0r> }
01[21:14] <@HellRaz0r> Ok i know that may seem abit confusing but bare with me i will explain.
01[21:14] <@HellRaz0r> Firstly when that on text is triggered it tokenizes(splits) the persons text where each space is so the 1st word becomes $1 2nd $2 and so on and $1- means 1st and what ever follows $1-2 means 1st to 2nd.
01[21:14] <@HellRaz0r> Then we check if the persons text is a (trigger)Command by using if/elseif ($1 == %bot-trig $+ Command) { }, if it is we then check total number of arguments by using $0, for some things we use if ($N == $null) to give any error msg to the user if the $N parameter is empty.
01[21:15] <@HellRaz0r> To restrict access to commands we can use if ($wildsite != *!*@YourAddress) to give an error msg to user if their address doesnt match, alternatively we can use if ($nick isop $chan) { } or make our own user system which i'll explain next time.
01[21:15] <@HellRaz0r> As you can see im using the keyword var there instead of set, the reason for that is because var=local set=global, local variables are only accessible from the event there were declared in and get terminated when mIRC is done with the event, where as global variables are accessible everywhere and dont get terminated when mIRC is done parsing.
01[21:16] <@HellRaz0r> I wont explain the [ ] evaluation brackets in this lesson because you dont really need to know how to use them yet.
01[21:16] <@HellRaz0r> Now you have all that you might want an on join message for people like below.
01[21:16] <@HellRaz0r> on *!:join:#yourchan:{ msg $nick Welcome to my channel. }
01[21:16] <@HellRaz0r> With that the ! in "on *!:" makes it so the event doesnt get triggered by yourself, it isnt needed with ontext because that can only be triggered remotely.
01[21:16] <@HellRaz0r> Right.. This has been a short lesson but ive covered enough of the basics to get you started i would write more but im a little busy at the moment, i will unmute the channel now to take questions please dont all try to ask at once there should be plenty of time to answer all your questions providing they are sensible.
03[21:17] * ChanServ sets mode: -m
05[21:17] -ChanServ- Channel modes are now -m.
01[21:17] <@HellRaz0r> Fire away.
-Lots of spam here i cut, the next lesson will be better managed.-