mIRC Homepage
Posted By: drc4 Suggestions/help on small script. - 12/02/06 01:02 AM
I'm currently attempting to create a script that will keep track of how many users a certain nick invites into a channel. I haven't tested the following code, but pretty confident it will work as planned. I currently have:
Code:
on *:TEXT:!invited *:#:{
  if ($$2 == $nick) { notice $nick What are you trying to do cheat?! You can't "invite" yourself. | halt }
  elseif ($$2 != $null) { inc %td 1 | set %joined. $+ $nick Invited by: $2 on $date | inc %invited. $+ $remove($2,<,>) 1 | write events.txt $nick (New Chatter) $nick indicates $$2 invites him to join $chan $+ . }
  else { notice $nick Please provide the nick of the user who invited you into the channel. }
}

on *:JOIN:#:{
  if (%joined. $+ $nick != $null)
  write events.txt $nick (Join) $nick Joined $chan on $fulldate
  else { 
  notice $nick I can't find you in my database. If you were invited to join this channel by someone | notice $nick type !invited <User who invited you> to help them win this amazing competition! }
}
on *:PART:#:{
  if (%joined. $+ $nick != $null)
  write events.txt $nick (Part) $nick Parted $chan on $fulldate
}
on *:QUIT:{
  if ($chan == #TheChannel) && (%joined. $+ $nick != $null) {
  write events.txt $nick (Quit) $nick QUIT on $fulldate }
}
on @*:TEXT:!cstats *:#:{
  if ($$2 == $chr(42)) { dcc send $nick events.txt | halt }
  elseif (%joined. $+ $2 != $null) {
    set %cs 1
    set %cs $lines(events.txt)
    while (%cs <= %cs) {
      notice $nick $read(events.txt, w, $2, %cs)
      inc %c
    }
    unset %c
    unset %cs
    notice $nick End of matches.
  }
  else { notice $nick No matches found. }
}
on @*:TEXT:!total *:#:{
  if ($$2 == $chr(42)) { notice $nick I have %td nicks in my database. | halt }
  elseif (%invited. $+ $2 != $null) { notice $nick $2 has invited a total of %invited. $+ $2 people into the channel! }
  else { notice $nick No records for $2 found. }
}
on *:TEXT:!mytotal:#:{
  if (%invited. $+ $nick != $null) { notice $nick There are currently %invited. $+ $nick users that claim you invited them. }
  else { notice $nick I have no records of anyone claiming you invited them to this channel. }
}

I'm just wondering if there's anyting any of you see missing, or if you have any suggestions on how I could make this code a bit more effecient. I'm pretty certain that using hash tables would be a bit better, but I'm not experienced on using them, and feel comfortable using something I know. Any advice/help would be much appreciated. The data will be kept for approx. a month, and then cleared. I've attempted to add all the error checking I could think of, but know it's far from flawless. Again, thanks in advanced for all the advice/help offered.
Posted By: DaveC Re: Suggestions/help on small script. - 12/02/06 02:03 AM
Code:
on *:TEXT:!invited*:#:{
  if ($1 == !invited) {
    if ($2 == $nick) { notice $nick What are you trying to do cheat?! You can't "invite" yourself. }
    elseif ($2 != $null) { inc %td 1 | set %joined. $+ $nick Invited by: $2 on $date | inc %invited. $+ $remove($2,<,>) 1 | write events.txt $nick (New Chatter) $nick indicates $2 invites him to join $chan $+ . }
    else { notice $nick Please provide the nick of the user who invited you into the channel. }
  }
}
;
on *:JOIN:#:{
  if ($($+(%,joined. $+ $nick),2) != $null) { write events.txt $nick (Join) $nick Joined $chan on $fulldate 
  else { notice $nick I can't find you in my database. If you were invited to join this channel by someone | notice $nick type !invited <User who invited you> to help them win this amazing competition! }
}
;
on *:PART:#:{
  if ($($+(%,joined. $+ $nick),2) != $null) { write events.txt $nick (Part) $nick Parted $chan on $fulldate }
}
;
on ^*:QUIT:{
  if (($($+(%,joined. $+ $nick),2) != $null) && ($nick(#TheChannel,$nick) > 0) { write events.txt $nick (Quit) $nick QUIT on $fulldate }
}
;
on @*:TEXT:!cstats *:#:{
  if ($2 == $chr(42)) { dcc send $nick events.txt }
  elseif ($($+(%,joined. $+ $2),2) != $null) {
    var %cs = 1, %cm = $lines(events.txt)
    while ((%cs <= %cm) && ($read(events.txt,w,$2 *,%cs) != $null)) {
      notice $nick $v1
      var %cs = $readn | inc %cs
    }
    notice $nick End of matches.
  }
  else { notice $nick No matches found. }
}
;
on @*:TEXT:!total *:#:{
  if ($2 == $chr(42)) { notice $nick I have %td nicks in my database. }
  elseif ($($+(%,joined. $+ $2),2) != $null) { notice $nick $2 has invited a total of $v1 people into the channel! }
  else { notice $nick No records for $2 found. }
}
;
on *:TEXT:!mytotal:#:{
  if ($($+(%,joined. $+ $nick),2) != $null) { notice $nick There are currently $v1 users that claim you invited them. }
  else { notice $nick I have no records of anyone claiming you invited them to this channel. }
}


* $$2 well halt a script is there is no $2 supplied, however in each of your original cases the matchtext was "something *" the space * means there must be two words sent so $2 well always have a value, thus invalidating the need for $$2. Note in the first ON TEXT you checked for $null and responded if they failed to enter it, I adjusted the match text to "!invited*" (no space) so it would pick up trhe first word alone, then checked if the first word was "!invited" or something else as u might not like it working on "!invitedmybuttIwasInvited"

* %joined. $+ $nick while this works for setting values into the variable named %joined.$nick, it does not work when accessing them, to access the variable you must first join the parts %, joined., & $nick (% & joined. cant be already together else mirc well use the contents fo that variable %joined.. So $+(%,joined.,$nick) joins all the parts together then $(XXX,2) tells mirc to evaluate XXX twice, the first time is when it joins it all together, the 2nd one well then look into that variable and get its value.

* in ON QUIT there is no $chan value, you must check if the nick is listed in the channel "#thechannel" using $nick(#TheChannel,$nick) its result is the position in the nicklist any value 1 or greater would mean its there.
(also) I changed ON *:QUIT to ON ^*:QUIT becuase you want to do this before mirc removes the nick from that list itself, and to do it before you need that ^, [ actually im not sure if i need that, but doing it cant hurt ]

* i redid your while loop (a filter would be even better but i thought that might be a bit hard to follow), for it u dont need SET use VAR as then the variables only last for the length of the event. The %cs value u had u were comparing to itself not %c. Where %cs is in the $read means read from that line onwards, so i made a %cm to mean last line. Also becuase the line read might be line 438 you must then set %cs to 438 ($readn) and increment that one, to make the next read from the line after the last one. in the condition of the while loop is where i read the file, becuase i only want to display a line if i find one ( != $null ), and instead of repeating the $read i use $v1 (mirc 6.16) which is the left side of the last condition evaluateion, namely the $read in the while. I do this becuase doing a $read on a file is time consuming so why do it twice for the same thing.
(i didnt add any anit-flood into the script as you can set that in mirc somewhere)

* I also realigned some code a bit, its biot of a bad practice to end a line with a closing } if u didnt put one on the start, becuase then that line moves 2 spaces left out of line with the code it block it should be in.

* my code is untested, i just adjusted yours in the thread editor so its possable there are errors in there *
Posted By: drc4 Re: Suggestions/help on small script. - 12/02/06 03:15 AM
Thanks for your input/idea's. It's much appreciated.
© mIRC Discussion Forums