Jump to content

Tutorial

Administration
  • Posts

    12
  • Joined

  • Last visited

Recent Profile Visitors

3,985 profile views

Tutorial's Achievements

Newbie

Newbie (1/14)

0

Reputation

  1. &Binvars Description: Binary valuables are variables that have binary contents, which means not just plain text. Advantages: Doesn’t have an inbuilt size limitation like %vars do. Isn’t limited to a certain range of characters, and contain end of line characters. Perfect to handle socket events. Disadvantages: No trivial sort command. Hard to work with. Access to the data is made by character position. Storage: The data is stored in the memory. Initializing a &Binvar: /bset &binvar N data Creates a &Binvar the size of N and inserts intial value. Adding data: /bcopy –c &bin1 N &bin2 S M Adds the data between position S and M (S-M) in &bin2 to place N in &bin1 . M can be set to –1 which means “position S onwards”. The –c switch cuts the &Binvar to size N+M. Deleting data: /bunset &binvar1 &binvar 2 ... Unsets the list of &binvars. Retrieving data: Set %ascii $bvar(&binvar,N) Returns the ascii value of the character in position N. Set %ascii $bvar(&binvar,N,M) Returns the ascii values of the character in the range N-M . Set %ascii $bvar(&binvar,N,M).text Returns the contents of the &binvar in the range N-M in plain text. Searching for data: Set %position $bfind(&binvar,N, cc cc cc ) Searches the &binvar for a characters that match the ascii value cc cc starting from position N. Set %position $bfind(&binvar,N,Match Text).text Searched the &binvar for the matching text starting at position N /breplce &binvar oldvalue newvalue Searches the &binvar for a matching “oldvalue” and replaces it with “newvalue” Converting to files : /bread filename S N &binvar Reads N bytes from filename’s position S and copies them to &binvar. /bwrite filename S N &binvar Writes N bytes from &binvar to position S in the file. If S is –1. it will append to the end of the file. If N is –1, it will copy the entire &binvar. Retrieving size: Set %size $bvar(&binvar,0) Returns the size of the &binvar. Example: Load the example to the remotes, and right click on a channel. All the code until the sockread is just the basic syntax to open a connection to a website. I’m gonna show you a site that sends a long line of text which can’t be saved into a %var (you can try to sockread it into a %var and see). menu channel,status { examplesock: { sockopen binvars www.urbandictionary.com 80 } } on *:sockopen:binvars: { if ($sockerr > 0) { echo -a xdccb 211,711 Timed Out return } sockwrite -n $sockname GET /define.php?term=crack HTTP/1.1 sockwrite -n $sockname Host: www.urbandictionary.com sockwrite -n $sockname Connection: Close sockwrite -n $sockname User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1) sockwrite -n $sockname $crlf } on *:sockread:binvars:{ if ($sockerr > 0) return while (online) { if (!$sock(binvars)) return sockread &mybinvar if ($sockbr == 0) return if ($get-tag(mybinvar,1).P) { var %begin = $gettok($v1,1,32) var %end = $gettok($v1,2,32) window @mybinvar while ($bfind(&mybinvar,%begin,.)) { aline @mybinvar $replace($gettok($bvar(&mybinvar,%begin,$v1).text,1,60),$+($chr(38),quot;),") var %begin = $calc($v1 +1) } sockclose binvars } } } ;This alias will gets a property (P in our case) finds the position of the beginning of the tag, and its end. ;I’m looking for the tag <P> here, because the long text I want is inside a paragraph. alias -l get-tag { if ( !$2 ) { return 0 } var %startingbyte = $bfind($+(&,$1),$2,$+(<,$prop)) if ( %startingbyte == 0 ) { return 0 } var %endstart = $bfind($+(&,$1,),%startingbyte,>) var %len = $calc(%endstart - %startingbyte + 1) var %tag = $bvar($+(&,$1,),%startingbyte,%len).text inc %startingbyte %len if ( !$regex(%tag,/^<[^<]+>/) ) { return 0 } var %endbyte = $bfind($+(&,$1),%startingbyte,$+(</,$prop,>)) return %startingbyte %endbyte }
  2. Custom @windows Description: We’ll use a custom @window to store a list of text lines. Advantages: Has powerful sorting and search options using /filter and other premade $identifiers . Can be saved easily into .txt files for permanent storage. When using dialog lists you should have a copy of the data in a @window and do all the sorting and searching work in the @window because it’s much more efficient. Disadvantages: Not as organized as hash tables. Inefficient access to data (only direct access is by line number). Storage: The data is stored in as list in a custom @window, which we’ll usually prefer to hide. Initializing a custom @window: /window –h @name This will activate a new window with the specified name. (-h means hidden) Adding data: /aline @name data Adds data to the end of the @window. ( can use /aline –n to prevent adding lines that exist ). Deleting data: /dline @name N file.txt Deletes the Nth line of data in the @window. /window –c @name Will close the specified @window. Inserting data: /iline @name N data Inserts the line of data in the Nth line. ( can use /iline –n to prevent adding lines that exist ) . /rline @name N data Inserts the line of data to the Nth line, and overwrites it. Retrieving data: Set %line $line(@name,N) Gets the Nth line in the @window. Searching for data: Set %lineNum $fline(@name,*wild*match*,N,T) Gets the position of the Nth matching line that matches the *wild*match*. The T is optional, if it’s set to 2 it means the match expression is a regex expression . Set %line $fline(@name,*wild*match*,N,T).text Gets the Nth matching line that matches the *wild*match*. Sorting and filtering: /window –s @name This will make the @window sort itself automatically. /filter –ww @name @name This simple format is an example to show that you can use /filter’s powerful options to sort the @window, and change it. Please read more about it in the mirc’s help file, to take advantage of this ability. Converting to .txt files: /loadbuf @window file.txt Will load all lines in the text file to the custom @window . /savebuf @window file.txt Will save the custom @window’s contents to the text file. Retrieving size: Set %lineNum $line(@name,0) Will return the number of lines in the file. Example: Load the example to the remotes, and right click on a channel. menu channel { @window Store data: { window -h @mychanneldata filter -cww $chan @mychanneldata iline @mychanneldata 1 $chan($chan).topic } @window Show data: { if ($window(@mychanneldata)) { echo -a Recorded channel topic: $line(@mychanneldata,1) filter -cwwg @mychanneldata @mychanneldata /^\* $/ echo -a Number of channel events recorded: $line(@mychanneldata,0) echo -a Here's the last event in the channel: $line(@mychanneldata,$line(@mychanneldata,0)) var %lineNum = $fline(@mychanneldata,$+(*,joined,*),1) echo -a Here's the first join event: $line(@mychanneldata,%lineNum) echo -a That appeared in line: %lineNum } } @window Remove data :{ if ($window(@mychanneldata)) window -c @mychanneldata } }
  3. Txt files Description: We’ll use a .txt file to store information in sort of list. Can use to permanently store custom @windows data. Advantages: Unlimited storage space (well, you won’t fill your HDD with this). Has powerful sorting and search options using /filter and other premade $identifiers . Can be loaded easily into @windows for quicker management. Has an inbuilt $identifier to retrieve random data. Disadvantages: Takes a lot of cpu power to access the file and use it regularly. Not as organized as .ini files. Inefficient access to data (only direct access is by line number). Storage: The data is stored in a file on the HDD, in a plain text format. Adding data: /write file.txt data Adds data to the end of the .txt file. Deleting data: /Write –dlN file.txt Deletes the Nth line of data in the file. /Write –dsText file.txt Deletes the line that starts with “Text” . Works with –w for wild cards, and –r for regex expressions as well. /remove file.txt Will permanently remove the file. Inserting data: /write –ilN file.txt data Inserts the line of data in the Nth line. /write –lN file.txt data Inserts the line of data to the Nth line, and overwrites it. Retrieving data: Set %random $read(file.txt) Gets a random line of data from the file. Set %line $read(file.txt,N) Gets the Nth line in the text file. Searching for data: Set %line $read(file.txt,s,Text,N) Gets the first matching line that starts with “Text”, starting the search from line N. Set %line $read(file.txt,w,*wild*match*,N) Gets the first matching line that matches the *wild*match*, starting the search from line N. Can replace the w with r to get matches with regex expressions. Set %lineNum $readn Gets the number of the line last matched by a $read search. Sorting and filtering: /filter –fw file.txt @window This simple format is an example to show that you can use /filter’s powerful options to sort the text file, and change it. Please read more about it in the mirc’s help file, to take advantage of this ability. Converting to @windows: /loadbuf @window file.txt Will load all lines in the text file to the custom @window . /savebuf @window file.txt Will save the custom @window’s contents to the text file. Retrieving size: Set %lineNum $lines(file.txt) Will return the number of lines in the file. Example: Load the example to the remotes, and right click on a channel. menu channel { TXT Store data: { savebuf $chan mychanneldata.txt write -il1 mychanneldata.txt $chan($chan).topic } TXT Show data: { if ($isfile(mychanneldata.txt)) { echo -a Recorded channel topic: $read(mychanneldata.txt,1) filter -cffg mychanneldata.txt mychanneldata.txt /^\* $/ echo -a Number of channel events recorded: $lines(mychanneldata.txt) echo -a Here's the last event in the channel: $read(mychanneldata.txt,$lines(mychanneldata.txt)) echo -a Here's the first join event: $read(mychanneldata.txt,w,$+(*,joined,*)) echo -a That appeared in line: $readn } } TXT Remove data :{ if ($isfile(mychanneldata.txt)) remove mychanneldata.txt } }
  4. Hash Tables Description: Hash tables allow you to efficiently store large amounts of information which can be quickly referenced and retrieved later on. Advantages: Ability to store items by 2 parameters : name and item name. Easy access to data through the topic and item names. Ability to save to .ini files, and load .ini files to them. Can set an item to have binary value and work like a &binvar. Disadvantages: No trivial sort command. Storage: The data is stored in the memory. Initializing a hash table: /hmake name N Creates a new hash table with that name, and N items. (N is optional) Adding data: /had name item data Adds data to the specified hash tables’ item. /had name item &binvar Copies the contents of a &binvar to the hash tables’ item. Deleting data: /hdel name item Deletes the specified hash table’s item. /hfree name Destroys the hash table. Retrieving data: Set %data $hget(name,item) Returns the data associated with the item in the specified hash table. $hget(name,item,&binvar) Puts the binary data in the item into the &binvar. Searching for data: Set %hash $hget(N) Gets the name of the Nth hash table. Set %item $hget(name,N).item Gets the name of the Nth item in the hash table. Set %item $hfind(name/N, *wild*match*, N, w) Searches for the Nth item that matches the wild match expression. (There are more options besides w to set the type of the match text). Set %item $hfind(name/N, *wild*match*, N, w).data Searches the data of the hash tables’ items and returns the Nth item which has matching data. Converting to files : /hsave –i name file.ini section Will save the hash table to an .ini file under the specified section. (note that .ini files can’t contain [ ] characters in the item names or section name). /hload –i name file.ini section Will load an .ini files’ section into the specified hash table. This way you can save many hash tables to the same file. (hload does not create hash tables, so you’ll have to make sure it’s already created). /hsave name file.txt Will save the hash table to a regular text file. You lose the ability to save multiple hash tables, but lose the limitation of not using the [ ] characters as well. (items will be followed by their data, separated by an end of line character). /hload name file.txt Will load a .txt file to the hash table. (hload does not create hash tables, so you’ll have to make sure it’s already created). Retrieving size: Set %size $hget(name).size Returns the size of the hash table (number of items). Example: Load the example to the remotes, and right click on a channel. menu channel { Hash tables Store: { var %hashname = $+(mychanneldata,$chan) hadd -m %hashname topic $chan($chan).topic hadd %hashname mode $chan($chan).mode if ($chan($chan).key) hadd %hashname $chan key $v1 } Hash tables Show: { var %hashname = $+(mychanneldata,$chan) if ($hget(%hashname)) { echo -a Recorded channel topic: $hget(%hashname,topic) if ($hget(%hashname).size = 3) echo -a I've stored 3 items, so there must be a key: $hget(%hashname,key) echo -a Last stored modes were: $hget(%hashname,mode) } } Hash tables Remove :{ var %hashname = $+(mychanneldata,$chan) if ($hget(%hashname)) hfree %hashname } Hash tables Remove all:{ hfree -w mychanneldata* } }
  5. INI Files Description: We’ll use an .ini file to store information in an organized order. It’s useful to use as a permanent storage for hash tables. Advantages: Ability to store items by 2 parameters : section and item name. Unlimited storage space (well, you won’t fill your HDD with this). Easy access to data through the topic and item names. Ability to load to hash tables, and save hash tables to them. Disadvantages: Takes a lot of cpu power to access the file and use it regularly. No trivial sort command. Difficult to search the data. Storage: The data is stored in a file on the HDD, using the .ini file format: File.ini { [section] Item1=data Item2=data [section2] Item1= data Item2 = data } Adding data: /writeini –n file.ini section item data This will add the data to the specified item under the specified section. The –n switch will allow access to “large” .ini files. Deleting data: /remini file.ini section This will remove an entire section from the file. /remini file.ini section item This will remove an item from the specified section. /remove file.ini Will permanently remove the file. Retrieving data: Set %data $readini(file.ini,section.item) Searching data: Set %section $ini(file.ini,N) This will return the Nth section in the file. Set %item $ini(file.ini,section,N) This will return the Nth item in the section. Converting to Hash: /hsave –I Hash_Name file.ini section This will save the Hash table to the specified section. /hload –I Hash_Name file.ini section This will load the specified section into the Hash table. Loading to @windows: /loadbuf –tSection @window file.ini This will load all the items in the section to the custom @window . Retrieving size: Set %num_sec $ini(file.ini,0) This will return the number of sections in the .ini file. Set %num_items $ini(file.ini,section,0) This will return the number of items in the section. Example: Load the example to the remotes, and right click on a channel. menu channel { INI Store data: { writeini -n mychanneldata.ini $chan topic $chan($chan).topic writeini -n mychanneldata.ini $chan mode $chan($chan).mode if ($chan($chan).key) writeini -n mychanneldata.ini $chan key $v1 } INI Show data: { if ($ini(mychanneldata.ini,$chan)) { echo -a The chan's stored topic is: $readini(mychanneldata.ini,$chan,topic) if ($ini(mychanneldata.ini,$chan,0) = 3) echo -a I've stored 3 items, so there must be a key: $readini(mychanneldata.ini,$chan,key) echo -a Last stored modes were: $readini(mychanneldata.ini,$chan,mode) } else echo -a The channel has no stored data } INI Remove data :{ if ($ini(mychanneldata.ini,$chan)) remini mychanneldata.ini $chan if ($ini(mychanneldata.ini,0) == 0) && ($isfile(mychanneldata.ini)) remove mychanneldata.ini } }
  6. Tokenized lists Description: Tokenized lists are simple lists that can be used for a limited number of items. We’ll use a %variable that will contain a list of items separated by a character—C. I’ll show as an example a list separated with spaces (character 32). Advantages: Easy to use, direct access to the items, simple sorting, use of simple %variables, uses built in sort and search functions. The list can be sent as a parameter to an alias, and can be easily accesses with $1,$2,$N after using the /tokenize command. Disadvantages: Limited number of items due to the use of the %variables and their limits. (about 900 characters). Storage: If the %variable is a global variable, it is stored in mIRC’s variables list. %variable = list of items Initializing a list: /set %list Adding an Item: /set %list $+(%list,$chr©,New_Item) Or /set %list $addtok(%list,New_Item,C) C is the value of the separating character, 32 (space) in our case. Deleting an Item: /set %list $deltok(%list,N-N2,C) N-N2 is the range of items to be deleted, or the position of the item. /set %list $remtok(%list,Item,N,C) Removes the Nth matching item. Inserting items: /set %list $instok(%list,New_Item,N,C) Will insert a token to the position N, without overwriting the Nth item. /set %list $puttok(%list,New_Item,N,C) Will replace the Nth token/item with the new item. /set %list $reptok(%list,Item,New_Item,N,C) Replaces the Nth matching item with the new item. (You can use $reptokcs for case sensitive) Searching for items: /set %bool $istok(%list,Item,C) Returns $true if the item exists, or $false if it doesn’t (useful in IF sentences). (You can use $istokcs for case sensitive) /set %position $findtok(%list,item,C) Returns the position of the item in the list. (You can use $findtokcs for case sensitive) /set %item $matchtok(%list,SubString,N,C) Returns the Nth match of an item containing the Sub String. (You can use $matchtokcs for case sensitive) /set %item $wildtok(%list,*match*text*,N,C) Returns the Nth item that matches the match text. (You can use $wildtokcs for case sensitive) Sorting the list: /set %list $sorttok(%list,C,[ncra]) This will sort the list, depending on the specification: n = numeric sort, c = channel nick prefix sort, r = reverse sort, a = alphanumeric sort You can use $sorttokcs for case sensitive. Retrieving size: /set %num $numtok(%list,C) This will give you the number of items in the list. Example: Load this in your remotes, and select a few nicks in a channel. menu nicklist { Tokenized list: { var %nicks = $1- echo -a I've selected $numtok(%nicks,32) nicks in the nick list: %nicks echo -a First nick: $gettok(%nicks,1,32) ... Last nick: $gettok(%nicks,-1,32) tokenize 32 %nick if ($2) echo -a Second nick: $2 if ($wildtok(%nicks,$me,1,32)) echo -a I've chosen myself else { var %nicks = $addtok(%nicks,$me,32) } var %nicks = $sorttok(%nicks,32,r) echo -a Reversed list of nicks: %nicks } }
  7. What is IRC? IRC stands for Internet Relay Chat. The global chat. The idea is just like any other chat... webchat, javachat and so on... You choose a nickname and joins a channel (room). But IRC is far more advanced then any other chat. First of all you need a client (program) so you can connect to an IRC-network, an IRC-network is built up by many IRC-servers that are linked together. Often it can be up to 800 users on one server and 30 000 on one network. You can find several clients to connect to an IRC network but my suggestion would be mIRC. Nickname First, you need an identity. Depending on the server you can choose any name. Some servers allow special characters in your nickname but in most cases they do not. Same goes for spaces. Many chats also include a way to register your nickname so only you can use it. It's always best to read up on any documentation of the server you are wanting to chat on to check on their rules governing nicknames. Channels What is a channel? A channel is a place (room) on IRC where conversations between a group of people occurs. People can join the same channel and chat with each other. Depending on what the channel topic is and the time of day, it can be very crowded. A channel can be very calm or very chaotic depending on the number of active chatters. A channel can be open to anyone. It can also be closed or private to only friends. On most servers channels are dynamic in that anyone can create a channel but the room disappears once the last person leaves. Many servers offer registered rooms which never close. Using the /list command you can view a list of rooms on the server. Channel names usually start with #. Once you have picked a channel to enter, you need to know how to join. From the /list menu you can simple click on the room to enter. Otherwise you need to type the command /join #roomname. Once you have entered the room you will probably see people chatting. You should see something like this: I think you are wrong no you are wrong you are both wrong and stupid i just closed another topic muahahahaha that reminds me everyone needs to visit killanet they have everything TG007 sux i don't know why ppl go there. When you enter you will probably enter during a conversation. If you are new to the room, you may want to watch for a couple of minutes to see what people are talking about. Many times the room name gives you a hint of the topic but topics change like the wind in most channels. To start chatting just type in your message and click the [Return] key. Starting off with a simple hello is a good way to start. You may notice that some nicknames have a character in front of their nicknames. Symbols such as @, &, and . are used to identify users as Channel Ops/Owners. A channel operator is a user that has control or access to modes and functions of the room, that a normal user does not. When you decide to leave the room you can use the /part #roomname command. Ready to make your own channel now? A channel is automatically created when a person joins it. If you join a room and you are the only one there, you have just created a room. Usually room creators have Op status in that room. Remember though, channels on IRC are usually dynamic and as soon as the last person leaves, the room disappears. Modes You have your own channel, now what? What are channel and user modes? Channels have additional settings, which can be set by the MODE command. Chanops and ops can set modes. Depending on the server, modes can vary, so I won't bother trying to list all of them here. Instead I will stick to the basics. Use the following to change a mode: /MODE {channel|nickname} [{+|-}{modechars} [{parameters}]] A + or - sign determines whether the mode should be added or deleted. Channels can be moderated, secret, private, with a limited number of users, anonymous, invite-only, topic-limited, with a list of banned users... /mode {channel} +b {nick|address} ban somebody by nickname or address mask (nick!account@host) /mode {channel} +i channel is invite-only /mode {channel} +l {number} channel is limited, with {number} users allowed maximal /mode {channel} +m channel is moderated, only chanops and others with 'voice' can talk /mode {channel} +n external /MSGs to channel are not allowed /mode {channel} +p channel is private /mode {channel} +s channel is secret /mode {channel} +t topic limited, only chanops may change it /mode {channel} +o {nick} makes {nick} a channel operator /mode {channel} +v {nick} gives {nick} a voice You can also use the MODE command to change personal settings. These are called User Modes. Check your usermode with the /MODE {yournickname} command. Here are some of the basic User Modes /mode {yournickname} +i makes yourself invisible to anybody that does not know your nickname /mode {yournickname} +o gives IRC-Operator status, can only be set by IRC-ops with OPER /mode {yournickname} +s lets you receive server notices /mode {yournickname} +w makes you receive wallops; messages to IRC-Ops (abused and deprecated) What do these Channel and User Modes mean? A channel is PUBLIC by default. Anyone can notice a public channel, see its users and join the conversation. In a list of channels you can see a public channel's topic. When someone is on a public channel, he can be easily found by all other users as long as his personal user mode is not set to invisible (see below). An INVITE-ONLY channel can only be joined if you are invited by one of its channel operators. PRIVATE channels turn up normally in the channels list. People can see you are on a private channel somewhere, but they can never find out on -which- private channel you are unless they search all (private) channels by brute force. With the names command your nickname will not show up, but it will with the /who {channel_name} command unless you hide by setting your personal user mode to 'invisible'. SECRET channels do not show up in a channels list and you cannot find out its topic unless you join it. If you are on a secret channel, someone who is not on the same channel can't see that you are there, regardless what your personal user mode is set to. Your name does not show up in a names list of people on IRC if you are on secret channels only. Your user mode can be set to INVISIBLE meaning that other people cannot find you by searching on IRC unless they know your exact nickname. No (wildcarded) search on you by the /who command on your IP Address or real name will deliver your current nickname or other likewise info to others. Operators What is a channel operator and what is an IRC operator? A channel operator (ChanOp or Op) is someone with a "@" by their nickname in a channel's names list, or a "@" before the channel name in a /whois or /uwho output. Channel operators are the 'rulers' of a particluar channel. This means they can kick you out of their channel for any reason. If you don't like this, you complain to them or start your own channel and become a channel operator there yourself. An IRC operator (IRCop) is someone who maintains a server or part of the IRC network. They cannot fix channel problems. They cannot kick someone out of a channel for you. They also cannot /kill (disconnect a user from their IRC server temporarily) someone just because you gave the offender channel operator privileges and said offender kicked *you* off. IRCops have better things to do than interfere in channel affairs. Behaviour So what language should you speak and how do you behave on IRC? The most widely understood and spoken language on IRC is English. However, as IRC is used in many different countries, English is by no means the only language. If you want to speak some language other than English, (for example with your friends), go to a separate channel and set the topic to indicate that. Similarly, you should check the topic when you join a channel to see if there are any restrictions about language. On a non-restricted channel, please speak a language everybody can understand. If you want to do otherwise, change channels and set the topic accordingly. It is not necessary to greet everybody on a channel personally. Usually one "Hello!" or equivalent is enough. Also, don't expect everybody to greet you back. On a channel with 20 people that would mean one screenful of hellos. It makes sense not to greet everyone, in order not to be rude to the rest of the channel. If you must say hello to somebody you know, do it with a private message. The same applies to goodbyes. Also note that using your client's facilities to automatically say hello or goodbye to people is extremely poor etiquette. Nobody wants to receive autogreets. They are not only obviously automatic, but while you may think you are being polite, you are actually conveying yourself as insincere. If somebody wants to be autogreeted when they join a channel, they will autogreet themselves. Remember, people on IRC form their opinions about you only by your actions, writings and comments, so think before you type. If you use offensive words, you'll be frowned upon. Do not "dump" (send large amounts of unwanted information) to a channel or user. This is likely to get you kicked off the channel or killed off from IRC. Dumping causes network "burps", causing connections to go down because servers cannot handle the large amount of traffic. Other prohibited actions include: * Harassing another user. Harassment is defined as behavior with the purpose of annoying. * Annoying a channel with constant beeping. (Therefore most clients cannot beep at all) * Any behavior reducing the functionality of IRC as a CHAT medium. Now what are the most basic commands? Basic IRC-Commands With most windows IRC clients an extensive help file is included. Dont hesitate to try the /help command. IMPORTANT NOTE : ALL IRC COMMANDS START WITH A "/". The forward slash is the default command character. Commands on IRC are not case sensitive, and can be abbreviated to their first letters. Anything that does not begin with "/" is assumed to be a message to someone and will be sent to your current channel, or to a person you are chatting with in a private chat (see below). HELP shows general help or help on the given command. LIST lists all current channels. JOIN to join a channel PART to leave a channel (same as LEAVE) QUIT exits your IRC session, (same as BYE and EXIT) NICK changes your nickname AWAY leaves a message saying you're away or not paying attention WHOIS displays information about someone INVITE sends an invitation to another user KICK gets rid of someone on a channel TOPIC changes the topic of the channel ME sends anything about you to a channel or QUERY /HELP [command] Shows general help or help on the given command. /LIST [[{flags}] {channel mask}] Lists all current channels. In the list you will see all channels (see below), except for those that are secret, with their number of users and the topic. The displayed list may be quite long, so you can limit it using flags. "/LIST -MIN n" for instance removes channels with less than 'n' users from the output. /JOIN {#channel} Sets your current channel to the supplied channel. Upon entering a channel, you are given useful details about it: a list of users talking in that channel, channel mode settings and the topic... Joining a channel does not cause you to leave your previous channel and you can normally join as many channels as your connection can handle or that the IRC server allows. /JOIN #windows *** Now talking in #windows /PART [#channel] Makes you leave a channel. (same as LEAVE) /PART #windows *** You have left #windows /QUIT [reason] Exits your IRC session. (Also BYE and EXIT.) If a reason is supplied, it is displayed to other people on your channels. /QUIT Lunch Time! /NICK {nickname} Changes your nickname to whatever you like. Everyone who wants to talk to you sees this name. Nicknames are limited to 9 characters max. If your intended nickname clashes with someone else's as you enter IRC, you will not be able to enter until you change it to something else. Duplicate nicknames are not allowed; this is enforced by the IRC servers. Under some circumstances, two individuals may temporarily have the same nick but once discovered, both of them will be killed; a nick collision kill. /NICK Guru *** Newbie is now known as Guru /AWAY [away message] Sets your status as away with some info. Sets a message explaining that you are not currently paying attention to IRC. Whenever someone sends you a MSG or does a WHOIS on you, they automatically see whatever message you have set. Using AWAY with no parameters marks you as no longer being away. /AWAY Gone to get a cup of coffee. *** You have been marked as being away /AWAY *** You are no longer marked as being away /WHOIS {nickname} Shows information about someone. /WHOIS Guru *** Guru is [email protected] (Nuclear free) *** on channels: @#Windows @#Windows95 #mIRC *** on via server irc.server.net (The best server) *** Guru is away (making dinner) /WHOIS Newbie *** Newbie: No such nickname /INVITE {nickname} {#channel} Invites another user to a channel you are on. If you want a friend to join your channel you can invite him. He will see a message such as ***Guru invites you to #channel. This is required if your channel is 'invite only'. /INVITE Friend #windows *** Inviting Friend to #windows If you receive an INVITE message, you can type "/JOIN {#channel}". /KICK {#channel} {nickname} Kicks a user off a given channel. Well, you guessed it, if there is a way to invite someone on a channel, there is also the ablility to KICK someone out of it. For example ,if a person is behaving in an offensive manner by annoying people or flooding the channel with unwanted information, they can be forced out of the channel. Only 'channel operators' are privileged to use this command. /KICK #windows Lamer *** Lamer has been kicked off channel #windows by Guru /TOPIC {#channel} {topic for channel} Changes the channel's topic. Channels have topics, that indicate the current topic of conversation. You can change this topic on a channel with the TOPIC command. /TOPIC #windows Lets discuss OS/2 *** Guru has changed topic to "Lets discuss OS/2" /ME {action description} Tells people about what you are doing. At times, you may want to send a description of what you are doing or how you are feeling or just anything concerning you on the current channel or in a query. /ME slaps Newbie with a large trout. * Guru slaps newbie with a large trout. The same goal can be achieved towards a specific nickname or channel using: /DESCRIBE {nickname|#channel} {action description} MSG sends a private message QUERY starts a private conversation NOTICE sends a private message NOTIFY informs you when people logging in or out IRC IGNORE removes output from specific people /MSG {nickname|channel} {text} Sends a (private) message to specified nickname or channel. Besides chatting on IRC Channels you can also have private conversations or queries with other people on IRC. On most clients these conversations will be handled by separate window. You can use the /MSG command to send someone a message that only that person can read. If somebody else sends you a message or that person replies to your message a query window icon will pop up informing you somebody wants to talk to you personally. /MSG Desperado This message can be read by you only. *Desperado* This message can be read by you only. In Desperado's screen an icon will pop up with the message you typed; "This message can be read by you only." If you cannot wait for a reply for someone to message you to open a private window you can use the query command to force your client to open a private conversation window. /QUERY {nickname} [test] Starts a private conversation with {nickname} and forces a separate window to open. This command differs from the MSG command only by the fact that it is used to start a private conversation. All text you type that would normally be sent to your chat partner if you used MSG now displays in an immediately opened private window 'to your chat partner' on your screen and is sent to the other person as well. /NOTICE {nickname|#channel} {text} Sends a private message to the specified {nickname}or {#channel}. The NOTICE command is just another way to send messages to other people. But, unlike MSG's, NOTICEs will never open a separate window 'to' the other person. It should be seen as a sort of whispering. It is recommended that robots or other automatons on IRC use notices (contrary to messages) to send information to people. You should never automatically (as by remote events or commands) send a message or notice in response to a notice sent to you. /NOTIFY [nickname|on|off] Toggles the notify function or adds or removes {nickname} to the notify list. As you start to meet people on IRC, you will want to add certain nicknames to your notify list such that you will be warned when they sign on or off IRC. /NOTIFY wug marl *** Added wug to Notify list *** Added marl to Notify list /NOTIFY *** Maladjusted is on IRC *** HawK is on IRC *** Steve is not on IRC *** Desperado is on IRC /IGNORE [nickname|user@host] Ignore all contact from the specified people. The day will come when you decide not (never?) to see or hear a specific person on your screen. This can be achieved using the ignore command. If people are flooding channels with useless text or they are otherwise harassing you, a wise response is to ignore those person. Ignore can be set to a nickname or by specifying a user@host format. You can use all kind of wildcards. /IGNORE looser *** Added looser to Ignore list /IGNORE *** Ignore is ON *** Ignoring: *.*@*.unicomp.net *!*[email protected] *!*fishy@*.interaccess.com looser /IGNORE looser *** Removed looser from Ignore list Scripts An IRC script is essentially a collection of IRC commands compiled to server specific commands and do specific tasks. These can be used to alias exsisting commands to shorter commands or to bundle a whole set of commands that carry out a specific procedure under just a single command. Most of all clients uses scripts written in TCL. The mIRC client has its own language. Bots A BOT (short for ROBOT) is basically a script that is written to respond to commands and events. Mainly BOTs are used to do some channel functions that you think are a lot cooler because a BOT is doing them. There are a couple of different types of BOTs: war BOTs, bar BOTs, and channel BOTs. War BOTs are written to cause havoc and trouble on most IRC users. Many people think war BOTs are the greatest thing around, but they are not. A channel BOT is basically what most BOTs are. It will do most channel commands, like op, deop, kick, and ban. A channel BOT is the best type of BOT to have. It doesn't have some of the annoying features that the next BOT, a bar BOT, has. A bar BOT does basically things like serve drinks, food, play games, etc. Some people like bar BOTs; some people don't. If you are in a technical channel like #mirc, #windows, #winsock, etc., a bar BOT would not be used for that type of channel. However, a bar BOT is great for channels like #mirccafe, #irccafe, #startrek, and role-playing games channels. Note* This is a collection of a few tutorials i've seen. Many thanks to Cotse.net
  8. Common Pitfalls A Tutorial by myggan Table of Contents: * 1. The Art of Debuging * 2. The Importance of Error Checking * 3. Spotting Ambiguous Conditions * 4. Brackets and Braces * 5. Double Events * 6. Timers * 7. Input Events * 8. Matchtext * 9. Using $$ * 10. The $address() Bug * 11. Flood Protection * 12. Echoing Numerical Strings and Colors * 13. Not Reading the Helpfile * 14. Getting Helped This tutorial will take you through some of the known problems in mIRC, and how to solve them. Most experienced scripters are probably already aware of these, but this tutorial aims at the average newbie who isn't enlightened in these matters. I really hope you will learn something by reading this, and thus becoming a better scripter, or more important, developing your logical skills. If you have any questions regarding this tutorial or anything else related to scripting, check the contact information at the bottom of the page. Enjoy! 1. The Art of Debuging _______________________________________________________________________ What is debuging? How do I debug my code? Why should I debug? People new to programming are very ignorant to the importance of debuging, but what exactly is debuging? Let's look up the word 'debug' in a dictionary: To search for and eliminate malfunctioning elements or errors.Locate and correct errors in a computer program code; "debug this program" So, basically it means "finding the error". Fair enough. But how? Consider this ambiguous code: alias readfile { var %file = $1 var %line = $2 var %read = $read($1,$2) echo %read } /readfile myfile.doc Nothing happens when we execute the command above. Why? We do not know the cause of this unintended behaviour. Yet. Lets debug it: alias readfile { var %file = $1 var %line = $2 var %read = $read($1,$2) echo Value of % $+ file? %file echo Does %file exists? $isfile(%file) echo Does the line exist? $iif(%line <= $lines(%file),yes,no) echo Did you even provide me with a line number? $iif($2 == $null,no,yes) echo %read } We execute the command once again and get the following output: Value of %file? myfile.doc[/left][left] Does myfile.doc exists? $false [/color]Does the line exist? no Did you even provide me with a line number? no Bingo! Lets go through the results. Checking the value of your variables is an essential part of debuging, you need to know where they are set, where they are altered, or if they are set at all. In this example the variable %file was set correctly as we passed the parameter myfile.doc. But the fact is that myfile.doc does not exist! Only this is an error which causes the code to not work as intended, but lets continue. The line does not exist, and that's very logical considering we didn't pass a second parameter, which in this case should be the line number. That wasn't too hard to understand, right? But to make the code even more verbose, you should unsilence all your silenced commands to access some more information and possible errors. Consider this: alias readfile { .fopen handle mir.ini var %read = $fread(handle) .fclose handle echo %read } /readfile Same problem as the previous code, nothing happens when we execute it (this one requires no parameters). Lets debug shall we? alias readfile { fopen handle mir.ini var -s %read = $fread(handle) fclose handle echo %read } Now the command produces the following output: * fopen unable to open 'handle' (C:ProgrammIRCmir.ini) - * Set %read to - * fclose closed 'handle' (C:ProgrammIRCmir.ini) Ding-ding-ding! Problem spotted. mir.ini does not exist and can therefor not be opened nor read from. What I did here was to remove the leading dots (.), which silences commands (well some errors can't be silenced). I also added the -s switch to /var which makes it echo the variable and the value it's being assigned to (in this case nothing). That's it! Debuging isn't hard at all, once you know the actual meaning of the word. So the next time you decide to ask someone for help, make sure you have debuged your code BEFORE you ask, since this may piss some people off. Well this concludes this chapter. Chapter Two 2. The Importance of Error Checking _______________________________________________________________________ Making the proper error checkings prevents a code from being used in the wrong way, and tells the program what terms is in play. Let you control the program, and do not let it run freely without any indication on where to stop. See at it like a teenager. If you do not set limits and boundraries, he or she will eventually end up being a cracker. We do not want a cracker program. So what can we do? Examine the code below. alias readfile { echo $read(mirc.ini,$1)}/readfile 5 Everything looks fine, and it will work as long as we supply it with an appropriate parameter. But what if the parameter isn't of the desired type? In this example we are the one who's choosing the parameter, and we know it has to be a number higher than 0. But the program does not know this. Yet. If we pass a parameter that's not a number higher than 0, mIRC will ignore that parameter (because $read works in that way) and a RANDOM line is returned instead. This is not intented and could be hard do spot during the debuging process. alias readfile { if $1 isnum 1- { echo $read(mirc.ini,$1) }} Now it requires a number higher than 0 to work. By making our code more strict we are eliminating some potential problems and misintrepretations by the program itself. Next example. on *:SOCKOPEN:mysocket:{ sockwrite -nt $sockname Hello World echo We want this to echo, but it never will.}/sockopen mysocket localhost 666Produces:* /sockwrite: 'mysocket' not connected (line XX, scriptfile.ext) This is generating an error which CANNOT be muted with the dot prefix. The error is also halting further processing, which we may not want. Luckily for us, socket events in mIRC has $sockerr, which will be set to a value higher than 0 when an error has occured. So to correct the previous code we do this: on *:SOCKOPEN:mysocket:{ if $sockerr { echo An error occured! } else { sockwrite -nt $sockname Hello World } echo Now this part will echo.}/sockopen mysocket localhost 666Produces:An error occured!Now this part will echo. Even though the socket is never opened, we allow the script to continue processing even if there's an error. This is not the only reason to check for errors, you wont have to see your status window filling up with unmutable error messages, which can be very annoying if they are recurring. I hope you realize the point of errorchecking, it is an important part of making your program do what you want, and nothing else. In some occasions it prevents the pain of debuging the code. Anyway, enough of this. Chapter 3 3. Spotting Ambiguous Conditions _______________________________________________________________________ The if structure is a fundamental building stone of any langauge, and faulty conditions can and will generate unintended results when mixing operators. I assume you already know the two logical operators && and ||, so I'm not going to explain them to you. alias marriage { if $2 == Lisa && $1 == John || $1 == Mike { echo $1 will marry $2 } else { echo $1 will NOT marry $2 }} The point of this script is to decide to whom Lisa will marry (yes, mIRC can also solve love problems). $2 must be Lisa, no argument there. But the intention is that $1 must be either John or Mike. The following inputs will generate some odd results.. /marriage John Lisa/marriage Mike Lisa/marriage Mike John/marriage Mike MikeProduces:John will marry LisaMike will marry LisaMike will marry JohnMike will marry Mike Two ordinary weddings, one gay wedding, and one single person wedding (poor schizophreniac Mike). To elaborate the processing of this condition, we can illustrate it like this: Condition: if $2 == Lisa && $1 == John || $1 == Mike Intention: The condition should evaluate to true if a) $2 is Lisa, and $1 is John. $2 is Lisa, and $1 is Mike. Reality: This condition will evaluate to true if a) $2 is Lisa and $1 is John $1 is Mike.Mike will marry anyone, and this is obviously not what we want. But what do we change? We use () parenthises to tell mIRC how to parse the condition. alias marriage { if $2 == Lisa && ($1 == John || $1 == Mike) { echo $1 will marry $2 } else { echo $1 will NOT marry $2 }} And when we try the same inputs again.. /marriage John Lisa/marriage Mike Lisa/marriage Mike John/marriage Mike MikeProduces:John will marry LisaMike will marry LisaMike will NOT marry JohnMike will NOT marry Mike Mike is both straight and sane! Remember, you do not have to use () parenthises in mirc scripting, but there are certain times like these when you need to enclose partial conditions to ensure the proper parsing and result. 4. Brackets and Braces _______________________________________________________________________ This is a neverending discussion whether or not to use brackets/braces when scripting for mIRC. This is of course, each individuals opinion and preference, and it is really up to you if you want to use them or not. I will go through the combinations (including abscence) of brackets and braces. if (($me == John) && ($nick == Mike)) { echo whatever }on *:TEXT:hello:#:{ if ($nick isop $chan) { msg $chan Hi $nick } } This is standard for most people, it will parse every piece correctly but at the expense of readability. Of course, if you are used to this type of structure it wont be fugly to you. This is also the method of choice for beginners in mIRC scripting. if ($me == John) && ($nick == Mike) echo whateveron *:TEXT:hello:#:if ($nick isop $chan) msg $chan Hi $nick This method is also fine and will be parsed correctly, if you use () parenthises you do not need {} braces unless you want to execute several commands in the same if/while branch. if $me == John && $nick == Mike echo whateveron *:TEXT:hello:#:if $nick isop $chan msg $chan Hi $nick This MIGHT work, but it can also generate errors because mIRC cannot tell where the start of the command is. This method is NOT recommended. if $me == John && $nick == Mike { echo whatever }on *:TEXT:hello:#:if $nick isop $chan { msg $chan Hi $nick } This is my personal preference, it will always be parsed correctly since we are using {} braces to seperate the condition portion from the command(s). But to provide more readability, use several lines. if $me == John && $nick == Mike { echo whatever}on *:TEXT:hello:#:{ if $nick isop $chan { msg $chan Hi $nick }} The reason why I dislike ()parenthises is that it's extra pain when having $identifiers in the condition that has a () scope. This is a common error for both beginners and pro's, altering a condition and fail to spot the imbalance in the () parenthises. In conclusion, you do NOT need BOTH () parenthises and {} brackets. The helpfile claims that using both speeds up processing, which is NOT true, tests have proven that (feel free to try for yourself). 5. Double Events _______________________________________________________________________ The most common error/bug in mIRC scripting. Could sometimes be tricky to spot but let me explain it to you. When mIRC processes a scriptfile, it checks for events and will only trigger the FIRST of the events in question. To illustrate this behaviour, have a look at this: on *:START:echo This will echo.on *:START:echo This will NOT echo (above event was triggered). Fair enough, they are indeed identical. But what if a matchtext field was involved? on *:TEXT:*:#:echo This will echo.on *:TEXT:!boo:#:echo This will NOT echo (above event was triggered). Now THIS is where most people scratch their head and wonder why that second event isn't triggering. There are three solutions to this problem. a) Put the events in seperate scriptfiles and make sure that event is the only one of its kind. Change the order of the events, put the !boo event above the * one. c) Integrate them into one single event using if branches to seperate the tasks. on *:TEXT:!boo:#:echo This will echo.on *:TEXT:*:#:echo This will also echo.or...on *:TEXT:*:#:{ if $1- == !boo { echo First task. } else { echo Second task. }} Note that if the events have seperate target fields (#,?,@) this problem will not occur. on *:TEXT:*:?:echo This will echo.on *:TEXT:*:#:echo This will also echo. Of course, the most appropriate measures of avoiding this problem is to use different scriptfiles for each script/snippet, and to integrate the tasks in one single event (which will improve performance as well). 6. Timers _______________________________________________________________________ Timers can cause some problems when using $identifiers/%variables Consider this: alias time.in.titlebar { .timer $+ time 10 1 titlebar $time}/time.in.titlebar This will set the time to the same value over and over again. Why? Because $time was evaluated to a static value when the script was called. This can be proven by this: //time.in.titlebar | echo -a $timer(time).comProduces:titlebar 17:41:19 Luckily timers re-evaluate the $identifiers/%variables passed to it, so to make this script dynamic, we must prevent the variable from being evaluated immediately. alias time.in.titlebar { .timer $+ time 10 1 titlebar $!time}alias time.in.titlebar { .timer $+ time 10 1 titlebar $ $+ time}alias time.in.titlebar { .timer $+ time 10 1 titlebar $eval($time,0)} Any of these will work, and $time will only be evaluated when /titlebar is called. This rule also applies to | command seperators. alias timer.test { .timer 1 1 echo -t First line. | echo -t Second line.}/timer.testProduces:17:58:24 Second line.17:58:25 First line. This will not work as intended, watch. Commands: .timer 1 1 echo First line. | echo Second line. Intention: Set a timer with two commands: a) echo First line. echo Second line. Reality: Sets a timer with one command, and performs the next command a) .timer 1 1 echo First line. echo Second line.You cannot use {} braces to prevent this either, but there are solutions. a) Prevent | command seperator from being evaluated. $chr(124) and $(|) are two examples. Put the commands in an alias and make the timer call the alias instead. Example: alias timer.test { .timer 1 1 echo -t First line. $chr(124) echo -t Second line.}/timer.testProduces:18:00:29 First line.18:00:29 Second line. Be aware of this, if something looks like it has been evaluated twice, check your timers. Note that this re-evaluating behaviour also applies to /scid and /scon. 7. Input Events _______________________________________________________________________ I can't count the number of times I've seen a user who has more than one input event (which sends data to the server). This can be quite tricky if you create or get a script with such input event, while you already have on in another scriptfile. If both events executes /msg for example, you will be messaging the same message twice to the target. on *:INPUT:#:{ if /* !iswm $1 { msg $chan ( $1- ) haltdef }}at the same time in another scriptfile..on *:INPUT:#:{ if /* !iswm $1 { msg $chan [ $1- ] haltdef }} Now you will /msg the channel twice, once for each of these scripts (if we'd forget /haltdef we would have four outputs!). There is only one fix to this problem, integrate them into one single event. Another thing you should notice with input events is that they do not use the ^ prefix when you want to halt the default text. If you use it, the event wont work. This is the only event that behaves in this manner. 8. Matchtext _______________________________________________________________________ The purpose of a matchtext is to filter out unwanted lines, but this has some hidden issues which some aren't really aware of. on *:TEXT:!my*:#:{ msg $chan My $2 is big.} This is a poor matchtext for this kind of script. Watch. !mymomisafilthyhoeProduces:My is big. First of all, it only checks for a line starting with !my, whatever comes after is irrelevant for the program. We want this to be a space and thus, making a second parameter required (you can't end a line with a space since mIRC strips leading/trailing/repeative spaces). on *:TEXT:!my *:#:{ msg $chan My $2 is big.} But what if we do not want that second parameter required? We want to be able to write !my as well as !my string. This cannot be achieved with wildcards, we need to bring in the heavy artillery (regexp). Since this isn't a regexp tutorial, I am not going to explain the fundamentals of regular expressions, I assume you already know them (I will explain what my expression means though). on $*:TEXT:/^!my($| )/i:#:{ msg $chan My $iif($2 != $null,$2,car) is big.} Ok, so what does this do? Instead of a wildcard match we are using a regexp which will match !my at the start of the line, followed by either a space or the end of line. This eliminates the possible match on !mymymy but allows !my without anything behind it as well as a parameter (or several). Regular expressions also comes in handy when having several triggers in one event. Inefficient code:on *:TEXT:*:#:{ if $1 == !on { msg $chan Script is on. } elseif $1 == !off { msg $chan Script is off. }}Better code:on $*:TEXT:/^!(on|off)$/i:#:{ if $regml(1) == on { msg $chan Script is on. } else { msg $chan Script is off. }} This also eliminates the problem of double events in most cases. Moving on.. 9. Using $$ _______________________________________________________________________ The extra $ in front of an $identifier means that it MUST return a non $null value to continue. I first thought it just performed a /return if it failed to fill in the parameter, but that assumption was incorrect. $$ will HALT the processing if it cannot return a value. This can lead to problems if you are not aware of this. on ^*:TEXT:*:#:{ haltdef echo $chan $1-3 $bold($4)}alias bold { return $chr(2) $+ $$1 $+ $chr(2)} What's wrong with this code you ask? Basically, if $4 does not exist, the default text will be halted, but no custom message will be echoed, because $bold() requires a parameter. Anyway, if your code simply "doesn't do anything", check your $$'s. 10. The $address() Bug _______________________________________________________________________ This is a bug rare known to beginners (and many experienced scripters as well). As far as I know the bug only appears in the on JOIN event, like the following example: on *:JOIN:#:{ echo Address of $nick : $address($nick,5)} Sometimes $address() returns $null, which is a consequense of the IAL not being update properly. Therefor you should avoid this use of $address(). Note that $address() and $address is not the same, $address() refers to the IAL while $address do not (it's taken from the RAW string). So to prevent this odd bug, use $fulladdress/$address in conjuction with $mask(). 11. Flood Protection _______________________________________________________________________ When making scripts that sends data to the server and allowing other users to trigger it, you will need to protect yourself from the infamous excess flood. As you probably know, you cannot send too much information to the server, or it will disconnect you. This is something people love to exploit, but it is easily fixed. There are many types of flood protections, here's some examples: on *:TEXT:!trigger:#:{ msg $chan You have triggered me!} Bad code. Lets fix it. on *:TEXT:!trigger:#:{ .timerflood. $+ $nick 1 1 msg $chan You have triggered me!} This will limit the triggering to once per second per nick. Another example: on *:TEXT:!trigger:#:{ if %count <= 3 { msg $chan You have triggered me! inc -u3 %count }} This will limit triggerings from everyone. The variable increases by one every triggering, and is unset 3 seconds after it's increased (unless another triggering increases it again). As long as the variable is below 3 it will perform the task given, otherwise it will just ignore the trigger until the variable has been unset. If you do not want a custom flood protection, take a look at: /help /flood 12. Echoing Numerical Strings and Colors _______________________________________________________________________ Ever had the problem with an * /echo: insufficient parameters error? Can't figure out why it is not echoing? Check if the first parameter is a numerical value, and if so, add a non-numerical string in front of it OR add a switch/target to it. Note that this only applies to /echo WITHOUT switches. //echo $count(myggan,g) Should echo 2, right? Actually no. If you take a look at the /echo syntax: /echo [-cdeghiNtsaqlbfnmr] [#channel|[=]nick] Notice the parameter. If you do not supply a switch to /echo, and the string starts with a space delimited numerical, mIRC will treat that parameter as a color and not a part of the string to echo. The previous example will be evaluated to: /echo 2 This will try to echo a $null string with the color 2 (dark blue by default). When echoing a string with color ctrl codes, make it a habit to PAD your color index number with a leading 0, if the color index is below 10. Consider this: //var %string = foobar | echo -a $chr(3) $+ 4 $+ %string Works quite fine. But what if %string started with a number? //var %string = 0foobar | echo -a $chr(3) $+ 4 $+ %string No longer working. Why? Because that 0 in %string will be treated as a color index along with the 4, in other words 40, which isn't a valid color index. The fix is easy: //var %string = 0foobar | echo -a $chr(3) $+ 04 $+ %string This applies to the background color index as well (,). Always make sure your color indexes contain two numbers, an easy way to do this is: alias fixcolor { var %index = 1, %result while $eval($ $+ %index,2) != $null { %result = $addtok(%result,$base($ifmatch,10,10,2),44) inc %index } return %result}//echo -a $fixcolor(2)//echo -a $fixcolor(5,7)Produces:0205,07 13. Not Reading the Helpfile _______________________________________________________________________ This is the deadliest of sins. The help file contains the information you need in 95-100% of the cases. And just because you do not understand what is said in the helpfile, doesn't mean it's not wellwritten, it only means you didn't put enough effort in reading and understanding the text. The /help command is extremly easy to use (can be a bit tiresome to scroll though). But the point is, people get pissed off at people who asks question without reading the manual first. I know this from years of experience in helping people, the longer you have volunteered to help out, the bigger gets the suppressed need of telling people to "stfu and go read the manual". So please do. However, if you (like me) find me helpfile somewhat tiresome to find stuff in, or if you feel something missing, take a look at these tools: /rtfm - instant /help by myggan Updated mIRC Helpfile by Teazle mIRC Chm Help 6.16 Anchored by AdrenalinTop 14. Getting Helped _______________________________________________________________________ Everyone needs help sometimes, and that's fine. Alot of IRC networks and Web forums have volunteering helpers, which will offer you help 100% for free, without anything to gain. If you marsch into a channel or into a forum with a thingyy attitude, you will have one or more of these scenarios ahead of you: a) People will get pissed off. People will laugh at you. c) People will ignore your need of aid. d) People will think you have a small thingy.If you have a question, do not hesitate to ask. You should not ask for permission to ask a question, which is quite paradoxal if you think about it. Classical questions like these will only annoy people: a) Can anyone help me? I need help! c) My script does not work, what is wrong? d) This is a help channel, help me!Remember, demanding help from a non-profit organization is retarded. Here are three key elements in getting helped quickly and easy: a) Being straightforward, and provide the helpers with sufficient information (debug/error messages) Being humble, respect the helpers aiding you without any personal gain. c) Speak english if the channel/forum is international. Also, follow these steps BEFORE asking questions: 1) a) If you are searching for a particular script, search google and the popular mirc scripting sites. If you have a piece of code, test it by yourself and examine the results. c) If you have a question on how to do something, just ask. 2) View debug/error messages and try to correct your code. 3) Read the manual for command syntaxes, use of switches, other notes, etc.. 4) a) Collect debug information and error messages and paste them along with the code in a pastebin. Paste the URL in the channel/forum along with a basic briefing on your problem. c) Wait for someone to answer, and try to solve it on your own while waiting. Pastebins: www.pastebin.com www.nomorepasting.com www.google.com/search?q=pastebin Scripting Sites: www.google.com/search?q=mirc+scripting This tutorial was written by myggan (11/12-2005) If you have any questions, feel free to contact me: IRC: irc.quakenet.org -> #Scripting irc.dal.net -> #Scripting MSN: [email protected] (mail as well) WEB: http://www.mircscripts.org/users/mygganThanks for reading! *Special thanks to myggan for allowing us to use this tutorial.
  9. on*:dialog:nicklist:init:*:{ ^when the nicklist opens dll $mdx SetMircVersion $version ^using mdx.dll set mircversion o the version dll $mdx MarkDialog $dname ^with mdx.dll Markdialog dll $mdx SetMircVersion $version dll $mdx MarkDialog $dname dll $mdx SetFont $dname ^set font to the dialog's name (nicklist) dll $mdx SetFont $dname 1 14 50 verdana ^set font to what you want, 1 represents the listbox id number, 14 50 represent the size of the text and verdana represents the font chosen. dll $mdx SetColor $dname ^set the colour of the font dll $mdx SetColor 1,3 text $rgb(0,0,139) ^set the colour type on the text, in id's 1 and three dll $mdx SetControlMDX $dname 1 ListView noheader smallicon hottrack single > dlls\views.mdx ^ set the control on the listbox as noheader, with smallicons, hottrack and single, use the following paths dlls/views.mdx. did -i $dname 1 1 iconsize normal small ^add to the dialog in the list box ( 1 1 being the id - mdx works differently like that) set the normal iconsize to small did -i $dname 1 1 seticon normal 0, $+ Pics\owner.ico ^add to the list normal icon in the path pics\owner.ico did -i $dname 1 1 seticon normal 0, $+ Pics\host.ico ^same explanation as the owner did -i $dname 1 1 seticon normal 0, $+ Pics\Spec.ico did -i $dname 1 1 seticon normal 0, $+ Pics\voice.ico did -i $dname 1 1 settxt color $rgb(0,0,139) ^this actually adds the colour in, without this you will not get colour in there nickinlist ^ alias to get nicks in the list That was simple, now im hoping that you now how to get names into the nicklist if not here is how we do it: alias nickinlist { did -r nicklist 1 ^Remove all the text and stuff in the list var %n 1 ^set %n to 1 while (%n <= $nick($active,0)) { ^while %n (1) is less then nicks in the active channel did -a nicklist 1 0 + $nicklisticon($nick($active,%n)) $nick($active,%n) ^add to the nicklist in id 1 $nicklisticon is the alias for the icons which we set earlier, add nicks in avtive channel inc %n ^including %n } } Ok now we have all this, we need to set the icons in the nicklist: alias nicklisticon { if ($1 isowner $active) return 1 ^if nick is owner in the channel return the icon to be one elseif ($1 isop $active) return 2 ^else if the nick is op in the channel return the icon to be two elseif (*+*m* iswm $chan($active).mode) && ($1 !isvoice $active) return 4 ^if +m is in the room modes and nick is less than voice return to be four elseif (*+*m* !iswm $chan($active).mode) && ($1 isvoice $active) return 3 ^if +m is not in room modes and nick is voiced return to be three elseif (*+*m* iswm $chan($active).mode) && ($1 isvoice $active) return 3 ^if +m is in room modes and nick is voice return to be three elseif (*+*m* !iswm $chan($active).mode) && ($1 !isvoice $active) return 3 ^if +m is not in modes and nick is not voiced return to be three. Hope this helps - Binime Thanks also to Seph for posting it on the forum.
  10. INTRODUCTION Hash Tables is something that you find within mIRC itself. Theres a few commands that allow you to store data into a file that you can then retreive and use in whatever way you wish. In my personal opionion , hash tables is the best thing Khaled added to mIRC. They have an unlimited potential and the process of your data is usually very fast.....in most cases i find the process time to be instant. Hense why I would always strongly recommand people to use Hash Tables to store data. But of course this is just my opionion, it's totally up to you on how you code and store data. In the commands section, you will basically find all the commands related to hash tables. Now this is taken straight from mIRC's own help file but since not all scripts are released with the help file in them. I've added them here for your conveniance The "How I Use" section is simply as it says. How I use them. I don't explain how i would use every hash table command, most of them I do use. This section just explains how i use the commands that I do use and what I general do with them. snippets section is just a few pieces of code that you can play around with or change to suit your own needs. Basically do whatever you want to do with them. Lastly learning hash tables has helped me alot and I got KiX to thank for that. He spent a good half hour or longer teaching me how best to use them. Much appreciated KiX COMMANDS /hmake -s <name> <N> Creates a new hash table with N slots. A hash table can store an unlimited number of items regardless of the N you choose, however the bigger N is, the faster it will work, depending on the number of items stored. eg. if you expect that you'll be storing 1000 items in the table, a table of N set to 100 is quite sufficient. The -s switch makes the command display the result. /hfree -sw <name> Frees an existing hash table. The -w switch indicates that name is a wildcard, all matching tables are freed. /hadd -smbczuN <name> <item> [data | &binvar] Adds an item to an existing hash table. If the item you're adding already exists, the old item is replaced. The -m switch makes /hadd create the hash table if it doesn't already exist. The -uN switch unsets the item after N seconds. The -b indicates that you're adding a &binvar item to the hash table. The -c switch chops the &binvar up to the first null value and treats it as plain text. The -z switch decreases hash item once per second until it reaches zero and then unsets it. The /hinc and /hdec commands use the same parameters as /hadd and increase or decrease the number value of an item. When used with /hinc or /hdec, the -c switch increases or decreases the value once per second. /hdel -sw <name> <item> Deletes an item from a hash table. The -w switch indicates that item is a wildcard, all matching items are freed. /hload -sbni <name> <filename> [section] /hsave -sbnioau <name> <filename> [section] Load or save a table to/from a file. These load/save plain text to a text file, with item and data on separate lines. $cr and $lf characters are stripped from text when saving as plain text. The -b switch loads or saves binary files. $cr and $lf are preserved when saving as binary files. You can use -n to load or save files as data only, with no items. When loading with -n each line of data is assigned an N item value, starting at N = 1. /hsave also supports -o to overwite an existing file, and -a to append to an existing file. By default /hsave excludes items that are in the /hadd -uN unset list, the -u switch forces it to include the unset items. The -i switch treats the file as an ini file. You can specify an optional section name after the filename. Note: /hload does not create the table, it must already have been created by /hmake. $hget(name/N) Returns name of a hash table if it exists, or returns the name of the Nth hash table. Properties: size $hget(moo).size returns the N size of table, as specified in /hmake $hget(name/N, item) Returns the data associated with an item in the specified hash table. Properties: unset The unset property returns the time remaining before an item is unset. $hget(name/N, item, &binvar) Assigns the contents of an item to a &binvar. $hget(name/N, N).item This allows you to reference the table as an index from 0 to N, in order to look up the Nth item in the table. If N is zero, returns the total number of items in the table. You can also reference the Nth data value directly with $hget().data. Note: This method is provided as a convenience, it is not an efficient way to use the hash table. $hfind(name/N, text, N, M) Searches table for the Nth item name which matches text. Returns item name. Properties: data If you specify the .data property, searches for a matching data value. M is optional, and can be: n normal text comparison (default if M isn't specified) w text is wildcard text W hash table item/data is wildcard text r text is regular expression R hash table item/data is regular expression HOW I MAKE AND LOAD If you have looked at the commands, you will see before you add anything to a hash table, you need to "make" the hash table to begin with. This is acheived threw the command "hmake" Since with hash tables you have to make the table and then load the previous table that you saved before. I use a alias like the one below to acheive this. alias fserv.main.make { hmake fserv.main | hload fserv.main $+(",$scriptdirhashtables\fservmain.hsh,") } As you can see, this makes a hash table called fserv.main and loads into that table, the contents found in fservmain.hsh . To explain the $+(",$scriptdirhashtables\fservmain.hsh,") part . The remote that you are codeing into, is obviouslly stored in a specfic folder within your main mirc directory. The $scriptdir command takes you straight to that folder. Hense I have everything in a folder marked System. Within that folder is the remote .mrc file that im codeing on. Also within the System folder is another folder marked hashtables. The codeing above for $scriptdir, will go straight to the folder system which contains my .mrc file and then go into the hashtable folder and will look for the fservmain.hsh file in there. The $+(",,") part makes this work when there spaces in the path as well. Now here I'll get you to run a test here In your mirc type /hmake -s testing You should see * Made hash table 'testing' (100) The (100) part is what im interested in here. When you make a hash table, you can define a number which dictates how many items you can add to the table. But with what you just typed. i didn't define a number there, so mirc used the default number of 100 which equals 1000 items that can be added. I never bother with adding a number in as the default number is always going be more than sufficent. To define a number of items, You would do this /hmake -s testing 50 This means you can add 500 items then Last thing, in your codeing, i would advise not having the -s switch, as this shows the hash table being made and loaded, which users of the addon or script your making, won't wish to see this all the time HOW I ADD I'll explain how your data is added and what format it is like. If you have read the commands section, you will have seen that the command /hadd is what you use to add items and data to table Now for a test, In your mirc type the following in order 1) /hmake -s testing 2) /hadd -s testing nicks nick1 nick2 nick3 On your active window, you should see the same as below * Made hash table 'testing' (100) * Added item 'nicks' to hash table 'testing' As you can see, you made the hash table testing and added to the main item name "nicks" to it. Now you don't see the nick1 nick2 nick3 part but is in the hash table. To see the full information type the folowing //echo -a $hget(testing,1).item $hget(testing,1).data In your active window, you should now see the same as below nicks nick1 nick2 nick3 Now I'll explain what you typed. The command $hget is what you use to retreive information stored. $hget(testing,1).item . This returns the main item name for line 1 in the hash table named testing. $hget(testing,1).data . This returns the data associated with the item name on line 1 in the hash table. As you will see item can only ever be one word and have no spaces, where the data can be added in way you wish and does have a large scale of data that can be adding in there. If i remember correctly in a test i did awhile ago. I managed to fit roughly about 17 full paths and filenames in one line. You will see that should be more than enough room for you to work with. Now when you returning information, you don't need to add .item or .data onto the end of the $hget. You can just use the following $hget(testing,nicks) The above will return the data associated with nicks Well just decided to split this up into two sections. so click on the link to the left, How i use hash tables to see what i do with them. HOW I USE Theres two types of way i use hash tables to store data. Now I'll use an example to explain both ways. The example I'll use is codeing from my own channel protection. FIRST WAY The first way is , a single data word that defines something in the feature in my script. Meaning for example in my own channel protection, the edit field where someone would define how many texts before the feature kicks/bans user for flooding. I store this in the main hash table i use. Kinda like the variables section of mirc Example: on *:dialog:jacp:edit:*:{ if ( $did == 21 ) { hadd system cp.t.count $did(21).text | system.update } When someone types in the edit field. this auto writes to the hash table named system. And it adds the item name "cp.t.count" and the data associated with the item, which is whatever is in that edit field. The system.update is my alias to save the hash table. Read the section related to saving to see more information on that. To return this information , on my init event for the channel protection, i have the line below in this event to add the information into the edit field again. did -a jacp 21 $hget(system,cp.t.count) You should already know about $hget, if not go back and read the previous section. If i wished to delete this item from the hash table all together, I would just type the following or have this line on a button event in a dialog. /hdel system cp.t.count You don't need to type the data associated with the item to delete, just the item you wish to delete. SECOND WAY The second way i use hash tables is, say in my channel protection, i have a channels list that this feature will protect. So i have a line in my main hash table for this and it reads like below ITEM: cp.chans DATA: chan1 chan2 chan3 As you can see, i have more than one field in my data information here. Hense it's not as simple to adjust this item line as it is with the above way. I use 3 aliases to do the following , one allows me to add channel, one allows me to delete channel and one allows me to input information into a listbox alias cp.add.chan { var %cur = $hget(system,cp.chans) var %new.chans = %cur $did(79).text hadd system cp.chans %new.chans did -r jacp 79 system.update cp.get.chans } This alias above as you can see, sets a temp variable called %cur , with the data stored in the item marked cp.chans Then i set another temp variable called %new.chans . This contains the current listed channels stored in the variable %cur and also the new channel that has been inputed in the edit field within the dialog. Then i add the new information to the hash table named system You will notice i don't delete previous information, thats cause i rarely have to delete a line from a hash table. As when you readd, it just auto removes previous information stored in cp.chans item line and adds the new information into there the cp.get.chans is the alias i use to return the information associated with the cp.chans item line and that is shown below alias cp.get.chans { did -r jacp 82 var %cur = $hget(system,cp.chans) var %i = 1 while ( $gettok(%cur,%i,32) ) { var %chan = $ifmatch did -a jacp 82 %chan inc %i } } Now you see that %cur temp variable is set with the channel list again. Then i use a while loop along with $gettok to return the information. You can read about while loops and $gettok in mircs own help file. But you do have the above alias you can copy and paste into your remote and change to suit your needs. When I wish to delete a channel from my list , I use the alias below to do so alias cp.del.chan { var %cur = $hget(system,cp.chans) var %rem = $did(jacp,82).seltext var %new.chans = $remove(%cur,%rem) hadd system cp.chans %new.chans system.update cp.get.chans } Yet again, i set the temp variable %cur but this time i also set another variable %rem . This is the line that I have selected in the listbox which gets set here Then i use $remove command to remove the information stored in %rem from the channel list stored in %cur . Then obviouslly i readd to hash table and return the new information threw my cp.get.chans alias HOW I SAVE/FREE When you have added to a hash table, you would more and likely wish to save that information. Well the /hsave command is what you want to use. I use a alias to save to hash table and an example is below alias system.update { hsave -o system $+(",$scriptdirhashtables\system.hsh,") } You would have seen the system.update alias listed in previous pieces of code i showed in other sections. This is it above and something i generally advise, is everytime you add something new to a hash table, always have a alias that saves the hash table as well. The above code obviouslly saves the new information to the system.hsh table found in the hashtables folder. I'm sure you have already read the make/load hash table section and will already know about the use of $scriptdir and $+(",,") The -o switch is needed everytime you save to a hash table, well in my opionion it is. As this switch overwrites the previous information stored in the hash table. Now you may wish to free the information from mIRC's memory after you have used the data for whatever, this really depends on what your using the hash table for. With the above table in my example in mind here. This is basically my variables hash table, so i have this loaded all the time in my own script as its used alot threwout my script. Hense i only free the hash table when you shutdown the script. But in other areas of my script, where i have hash tables that aren't used as much, i do use the /hfree command to free the information from memory. In the example below ive added the hfree line to the above example and shown how i would free the table if i wished to . alias system.update { hsave -o system $+(",$scriptdirhashtables\system.hsh,") | hfree system } Not much to it really, just a simple command to free the system hash table. SNIPPET ;Instructions if the hash table is needed to be made and loaded first You will see a dialog appearing asking you to locate directory containing hash table you want to make and load if you want to make and load hash table first, then add "-z" to end if you don't want to free hash table at end, then add a "-x" after the z space in between the -z and -x , see usage below if you previouslly saved the hash table as a binary file, data only or ini format you will need to apply the respective switches for this, hense what the is for -b = binary file , -n = data read only , -i = hash table treated like a ini file USAGE: /get.hash -z -x Now its very important you have 3 items after the hash table name, even if you don't want to use a certain part. so any part you don't want to use, replace with a "no", see below USAGE; /get.hash no no -x alias get.hash { window -ak(0) @hash aline @hash Item $chr(9) $chr(9) Data aline @hash ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var %hash.name = $1 var %switches = $2 if ( $3 == -z ) { var %hashtable = $+(",$sfile($mircdir),") hmake %hash.name if ( %switches == no ) { hload %hash.name %hashtable } else { hload %switches %hash.name %hashtable } } var %i = 1 while ( $hget(%hash.name,%i).item ) { var %item = $ifmatch , %data = $hget(%hash.name,%i).data aline @hash %item $chr(9) $chr(9) %data inc %i } if ( $4 == -x ) { hfree %hash.name } }
  11. Ok in this tutorial I will be covering:- Combos, List views Start: What you need: 1. Mdx 2. mIRC 3. Time Mdx aliases needed: alias mdx { return path-to-mdx/mdx.dll } alias ctl { return path-to-ctl/ctl_gen.mdx } alias bars { return path-to-bars/bars.mdx } alias views { return path-to-views/views.mdx } alias icon { return path-to-icons/ $+ $1- } 1. Combos Ok well I'm going to explain how to use combos with mdx. I will be using an example dialog to show you how it works. Start by making your start of your dialog now what I'm going to tell you is very important you must not set the combo box to drop the SetControlMDX will do that for you ok. dialog example { title "combo example" size -1 -1 63 67 option dbu combo 1, 1 1 60 50, size button "Button", 2, 1 52 37 12, ok } ok now you have done the start of you dialog we are going to move onto the init this is where you need to know a bit about mdx to understand on *:dialog:example:init:* { ;1) Sets mIRC Version onto mdx ;2) Marks the dialog for MDX dll $mdx SetMircVersion $version dll $mdx MarkDialog $dname dll $mdx SetDialog $dname ;This is the part that sets the combo to drop down dll $mdx SetControlMDX $dname 1 ComboBoxEx drop > $views ;This sets the icon size on the combo did -i $dname 1 1 iconsize small ;ok this is the important part when setting the icons and the text for your comb ;This first bit sets the icon. I Made shore that I add the two icon part because enables you ;to set a different icon for each line of text. ;This is where You place you combos id Example: did -i $dname (here) 1 seticon 0 $icon(icon/path) did -i $dname 1 1 seticon 0 $icon(icon/path) did -i $dname 1 1 seticon 0 $icon(icon/path) ;Now on to the text part you have to make shore you get the icons to display right for each text ;the id is the same as the icons id but then you have to set it so each text has it's own icon ;to set the icon for Text1 you need to do this Example: did -a $dname (id) (icon number) (icon overlay) 0 0 Combo Text :Well if you wanted icon one to be on text one you put 1 and the overlay 1 ;the overlay is just the icon that appears when you click it did -a $dname 1 1 1 0 0 Combo Text1 did -a $dname 1 2 2 0 0 Combo Text2 } Your finished Product should look like this: 2. List Views Moving on list views are used by many people but I think the question on many peoples mind is how the hell do I add icons ok well then I'll tell you first you make a you starting part of your dialog like so dialog example2 { title "List View example" size -1 -1 89 91 option dbu list 1, 1 3 87 73, size button "Button", 2, 49 78 37 12, ok } ok that the starting part out of the way moving on to the init on *:dialog:example2:init:0: { ;1) Sets mIRC Version onto mdx ;2) Marks the dialog for MDX dll $mdx SetMircVersion $version dll $mdx MarkDialog $dname ;this sets the List View i add grid cos i think grids look better with icons dll $mdx SetControlMDX $dname 1 ListView report single grid > $views ;Sets List view header did -i $dname 1 1 headerdims 200 did -i $dname 1 1 headertext Example ;This icon command sets the icons for each test or you could just use one if you just ;want to use 1 icon for the whole list view ok did -i $dname 1 1 seticon list $icon(icon\path) did -i $dname 1 1 seticon list $icon(icon\path) ;Now on to setting the text in the list view you should know how to ;set the id because it's the same as on the combo this +b means the ;icon will be displayed on the right and the second number is witch icon you want to be displayed don that text ;Example: did -a example2 1 +b (icon number) Text1 did -a example2 1 +b 1 Text1 did -a example2 1 +b 2 Text2 } You finishing list view should look soothing like this: Well dudes that's all I got for you in the first Part stay tuned for the second part Mike Bailey ************************************ Contact Info IRC: irc.chatchannel.org #scriptaz,#schat Thanks to: pr0n^king - For getting me into Tutorial writing
  12. Tutorial by KingTomato What is a hash table? A dictionary in which keys are mapped to array positions by a hash function. Having more than one key map to the same position is called a collision. There are many ways to resolve collisions, but they may be divided into open addressing, in which all elements are kept within the table, and chaining, in which additional data structures are used. Well, what's that all mean? Well to put it bluntly, it means a set of data stored in RAM (Random Access Memory) allowing for quick and easy access (quick being the opperative term). With a hash table, you can store hundreds (if not thousands) of data entries and retreive it in a matter of seconds (or less). How do I make a hash table? Well, to make a hash table you first must have some idea of how much data you will be storing in it. The average size of the hash table is the square root of the number of entries you expect to hold. So if you plan on 100 entries, a size of 10 should be sufficient. Here is the syntax (or basic layout) of how the /hmake command works. /hmake <name> <size> As we move along, I will try to apply the different commands used with hash tables in a demonstration script. This is both to show what we are talking about, and to show how you would apply it in a script. For my example, I will choose the all-too-popular acronym script. Thus far, we have seen how we make a hash table, so now lets apply. A good assumption for our acronym scripts would be we want to create the hash table every time we load mIRC. To do this we will add the /hmake command in an on Start event. on *:START: { ; create the hash table of 100 items (size of 10) /hmake acronym 10 } I know how to make a hash table, now how do I put information in it? Storing information is just as easy as creating the table to store it in. For this, we turn to the /hadd command. The syntax for this command is as follows: /hadd <table> <data_name> <value> So in our example, when we want to add the acronyms and their values to the table. For this, lets create an alias that is only used for the first initialization of the acronym hash table. Our code will be as follows: alias acronym.init { ; add the values to our table /hadd acronym afk Away From Keyboard /hadd acronym brb Be Right Back /hadd acronym gtg Got To Go /hadd acronym lol Laughing Out Loud /hadd acronym ttyl Talk To You Later } Okay, so now we have the table created, and the initializing alias made. Before we get to intializing it, lets look at loading and saving the hash table. You'll see why I feel this is next in the order of operations in just a second. How do I save or load a hash table? Saving and loading hash tables is very straight forward. The load/save commands are as follows: /hload <table> <filename> /hsave <table> <filename> Okay, well lets talk about loading first. Say we want to take a hash table file, and load it into our table. Now, for us to do this we first need to know which file. For our example we have been following, lets use the filename "acronyms.hsh" (.hsh for hash extention). Now, to load this file we will be using the command /hload acronym acronyms.hsh. Saving the hash table is just as easy. For this tutorial, we will save it in plain text format and not in binary. So do this we will use /hsave -o acronym acronyms.hsh. Now you may be wondering why the -o is there. The -o is simply to tell mirc to overwrite the prexisitng hash table file (if any) with our new data. Simple, right? There is one more very important command that I dont want to exclude while we are on the topic, but we will get to it later. This command is /hfree. /hfree will free the memory of a hash table after you kill it, so that the memory now being used itsn't taking up space. This is very useful if you only need a hash table for a short while, for example some people chose to use them for clone scanners for very large channels. Again, we will get to this a command soon, but for now here is the syntax: /hfree <table> Now, lets apply the load and save commands to our example while it is fresh in our mind. So far in our example we know how to make the hash table when mirc starts up, and how to add things to our table with an alias thats not being called--yet. Now to apply all the things we've learned we use the on start event again. First we will make the hash table. Next, we will check if a hash table has been saved as acronyms.hsh. If it has, we load it, otherwise we will call our alias and save our new table (hopefully my order of operations was appropriate). on *:START: { ; create the hash table of 100 items (size of 10) /hmake acronym 10 ; Load our hash file if it's there, other wise initialize the hash table if ($isFile(acronyms.hsh)) { ; file exists, now we load it /hload acronym acronyms.hsh } else { ; the file does not exist. Now we initialize, and save /acronym.init /hsave -o acronym acronyms.hsh } } Now we have the create, add, load and save done. Now you will notice I saved after adding the new entried to the hash table, but what if we add more? Well, now we move on to on Exit event. While we are adding this, lets also apply the /hfree command to after we save our table, so we can free up the memory the table is using before exiting mirc. Here is what it would look like: on *:EXIT: { ; save our table on exit /hsave -o acronym acronyms.hsh ; clear the used memory /hfree acronym } Okay, I have my table with the information--now how do I access it? Accessing the information is the hash table is as simple as pi (yes, i mean pi). This is where the $hget and $hfind identifiers come in. Lets begin with the former, shall we? $hget is a simple identifyer, and a very useful one at that. With this identifier you can deturmine if a hash table exists, find if a hash entry exists, and get the value associated with the entry. The first, deturmining if a hash table exists, is the simplest task. Simply use $hget( ) to find this out. Ex: if ($hget(acronym)) /echo -a Acronym Table Exists! Now, to get an entry, just use $hget(<table>, <entry>). Ex: if ($hget(acronym, lol)) /echo -a lol is in the table! And finally getting the value. var %meaning = $hget(acronym, lol) But wait, we just used that last one for checking if an entry exists, whats the difference? Simply put, when you use $hget to check if an entry exists, all your checking for is if the value associated with the entry exists, and thats what the if statement did. When passed a value, if the value is not null or 0, it will return true. What you do have to watch out for is if an entry containg the number 0, because that will trigger a false. Ex: /hadd myTable a 0 if ($hget(myTable, a)) /echo -a a exists! else /echo -a a doesn't exist! Watch out, the above code will produce "a doesn't exist!". This is simply because the value of a is a 0, which is also considered a false for mIRC. For a more failsafe way, you may choose to use: /hadd myTable a 0 if ($hget(myTable, a) != $null) /echo -a a exists! else /echo -a a doesn't exist! With the != $null addition, you can now be sure it will return true if anything is in the a value. Moving on with retrieving data, we have $hfind. $hfind is a more advanced version of $hget in thtat is also accepts wildcard matches, and has the ability to search not only entries, but values in entries. This means that you can search for not only "lol", but also "Laughing Out Loud" and it will return "lol". In order to search tthrough data though, you must specifty the .data property. So as I just mentioned, looking for the entry "lol" would look something like this: var %entry = $hfind(acronym, Laughing Out Loud, 1).data The above code would assign %entry the value of "lol". Now, how to apply this in our example. For this, we will be using the on Input event to "Catch" the acronyms as they are typed and sent to the server. We will do a search through the text for the acronyms we wish to replace, replace them, then send the message. on *:INPUT:#: { ; first make sure the text entered isn't a command if ($left($1, 1) !isin $+(/,$readini($mircini, text, commandchar))) { ; search for words to replace var %w = 1 |; current word we're comparing var %text |; current message var %acro = [<acronym>] |; the design you want your acronym to take ; loop through each word looking through a match while ($gettok($1-, %w, 32) != $null) { |; we include != $null incase the user types a 0 var %word = $ifmatch ; find the word in our table if ($hget(acronym, %word) != $null) var %text = %text $replace(%acro, <acronym>, $ifmatch) else var %text = %text %word ; Increase Counter Variable /inc %w } ; send the message to the channel /msg $chan %text ; stop the "double talk" /halt } } The complete code Now we have the events to create and add to the table, save the table, and use the table. With this information, lets piece it all together. The following is all the different parts of the code grouped together into one addon. Everything is still fully commented to that you can look at it and not have to second guess what's going on. ; initialize the first few acronyms alias acronym.init { ; add the values to our table /hadd acronym afk Away From Keyboard /hadd acronym brb Be Right Back /hadd acronym gtg Got To Go /hadd acronym lol Laughing Out Loud /hadd acronym ttyl Talk To You Later } ; Intiilize the table on *:START: { ; create the hash table of 100 items (size of 10) /hmake acronym 10 ; Load our hash file if it's there, other wise initialize the hash table if ($isFile(acronyms.hsh)) { ; file exists, now we load it /hload acronym acronyms.hsh } else { ; the file does not exist. Now we initialize, and save /acronym.init /hsave -o acronym acronyms.hsh } } ; Save the table on *:EXIT: { ; save our table on exit /hsave -o acronym acronyms.hsh ; clear the used memory /hfree acronym } ; replace acronyms with their proper meaning on *:INPUT:#: { ; first make sure the text entered isn't a command if ($left($1, 1) !isin $+(/,$readini($mircini, text, commandchar))) { ; search for words to replace var %w = 1 |; current word we're comparing var %text |; current message var %acro = [<acronym>] |; the design you want your acronym to take ; loop through each word looking through a match while ($gettok($1-, %w, 32) != $null) { |; we include != $null incase the user types a 0 var %word = $ifmatch ; find the word in our table if ($hget(acronym, %word) != $null) var %text = %text $replace(%acro, <acronym>, $ifmatch) else var %text = %text %word ; Increase Counter Variable /inc %w } ; send the message to the channel /msg $chan %text ; stop the "double talk" /halt } } And there we go. Now we have a hash table that is used to replace acronyms. Its a simple script, but is a nice little beginner's starting point. Hope this helps!
×
×
  • Create New...