mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Oct 2003
Posts: 34
S
spling Offline OP
Ameglian cow
OP Offline
Ameglian cow
S
Joined: Oct 2003
Posts: 34
Original post by me on another forum.

---------------------------------------------------------------------

This is my new !peak script. It really takes advantage of my latest "style", I guess you could say, with using aliases rather that remotes so that I can make the script available to me and everyone else. It's really interesting (to me) how the custom $send-to indetifier works, and the way that I used "echopeaksyntax" to save lines.Not to mention, it uses hash tables too smile
Code:
on *:start { hmake peak 200 | hload peak peak.hsh }
on *:exit { hsave peak peak.hsh | hfree peak }
on *:unload { hsave peak peak.hsh | hfree peak }
on *:join:* { if (($nick($chan,0) >= $+($chan,.,$asctime(dd),.,$asctime(mm))) || (!$+($chan,.,$asctime(dd),.,$asctime(mm)))) { hadd peak $+($chan,.,$asctime(dd),.,$asctime(mm)) The peak number of users for $chan is $nick($chan,0) on $asctime(mmmm doo $+ $chr(44) yyyy) $+ . } }
alias peak {
  if (!$2) { var %m = $asctime(mm) } | else { var %m = $2 }
  if (!$3) { var %d = $asctime(dd) } | else { var %d = $3 }
  if ($left($1,1) != $chr(35)) { echopeaksyntax $4 $5 | halt }
  if ($1) {
    if ($hget(peak,$+($1,.,%d,.,%m))) { $send-to($4,$5) $hget(peak,$+($1,.,%d,.,%m)) }
    else { $send-to($4,$5) There are no records for this channel. }
  }
  else { echopeaksyntax $4 $5 }
}
alias echopeaksyntax { $send-to($1,$2) Syntax: !peak [#channel] [DD] [MM] }
ALIAS send-to {
  if ($1) { return msg $1 }
  elseif ($2) { return msg $2 }
  else { return echo 4 -at }
}
on *:TEXT:!peak*:* {
  if (!$2) { var %c = $chan } | else { var %c = $2 }
  if (!$3) { var %m = $asctime(mm) } | else { var %m = $3 }
  if (!$4) { var %d = $asctime(dd) } | else { var %d = $4 }
  peak %c %m %d $chan $nick
}


Now, I'll explain it a bit better.

Code:
on *:start { hmake peak 200 | hload peak peak.hsh }
on *:exit { hsave peak peak.hsh | hfree peak }
on *:unload { hsave peak peak.hsh | hfree peak }
^ make/load/save/free hash tables
Code:
on *:join:* { if (($nick($chan,0) >= $+($chan,.,$asctime(dd),.,$asctime(mm))) || (!$+($chan,.,$asctime(dd),.,$asctime(mm)))) { hadd peak $+($chan,.,$asctime(dd),.,$asctime(mm)) The peak number of users for $chan is $nick($chan,0) on $asctime(mmmm doo $+ $chr(44) yyyy) $+ . } }
^check hash table to see if the current users is large or equal to the peak. I use >= because I want it to use the latest time when the command or alias is used.
Code:
alias peak {
  if (!$2) { var %m = $asctime(mm) } | else { var %m = $2 }
  if (!$3) { var %d = $asctime(dd) } | else { var %d = $3 }
  if ($left($1,1) != $chr(35)) { echopeaksyntax $4 $5 | halt }
  if ($1) {
    if ($hget(peak,$+($1,.,%d,.,%m))) { $send-to($4,$5) $hget(peak,$+($1,.,%d,.,%m)) }
    else { $send-to($4,$5) There are no records for this channel. }
  }
  else { echopeaksyntax $4 $5 }
}
The parameters $2 $3 are optional, if they're not used, they're automatically set by the first two lines to the current day/month. I made sure to have the day specified first so that you didn't need the month. $4 and $5 are only set if the remote is used, $4 being the channel, and $5 being the nickname. This way the following identifier can tell where the script is coming from. Channel > Pm > echo. It's pretty handy for scripts that can be used in chanel or PM.
Code:
alias echopeaksyntax { $send-to($1,$2) Syntax: !peak [#channel] [DD] [MM] }
A quick alias to save lines
Code:
ALIAS send-to {
  if ($1) { return msg $1 }
  elseif ($2) { return msg $2 }
  else { return echo 4 -at }
}
The crown jewel of the whole script ^. $1 == $chan, $2 == $nick. If $1 is set, it automatically returns it, with the prefix of "msg" for use. If $1 is not set, and $2 is, it returns $2 with the same prefix. If neither are set, it assumes that the remote is being used via the alias itself (user), and uses echo! Genious!
Code:
on *:TEXT:!peak*:* {
  if (!$2) { var %c = $chan } | else { var %c = $2 }
  if (!$3) { var %m = $asctime(mm) } | else { var %m = $3 }
  if (!$4) { var %d = $asctime(dd) } | else { var %d = $4 }
  peak %c %m %d $chan $nick
}
^the actual remote part, notice how it uses "| else" ( the | makes sure it treats the else as if it was on a new line) to set %c, %m, or %d only if the user specifies it, or else it uses the default. Of course, there are a few bugs, but they can easily be fixed with isnum.

----------------------------------------------------

What do you think. How could I improve? What do you like? What do you dislike?
FYI, syntax:
remote: !peak #channel [DD] [MM]
alias: /peak #channel [DD] [MM]
[..] - optional

Joined: Mar 2004
Posts: 175
Vogon poet
Offline
Vogon poet
Joined: Mar 2004
Posts: 175
This is a "Scripts Help" forum, not an advertising forum. It does not look like you need any help on it, as to wanting suggestions for your bug free script. If you wish to advertise a script, go to www.mircscripts.org or www.mirc.net


- Relinsquish
Joined: Oct 2003
Posts: 34
S
spling Offline OP
Ameglian cow
OP Offline
Ameglian cow
S
Joined: Oct 2003
Posts: 34
Well, I am looking for help. I want to know how I can improve. I thought this would be the best place to ask, with all the knowledgable people here, I had no idea that talking about improving something when there isn't a specific problem was against the rules. :\

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
People normally don't go to a Help forum/channel to ask for ideas. That is what script forums/channels are for, as well as the sites like mentioned above.


Invision Support
#Invision on irc.irchighway.net
Joined: Aug 2004
Posts: 423
C
Fjord artisan
Offline
Fjord artisan
C
Joined: Aug 2004
Posts: 423
Riamus2 and Relinsquish are right this isn't the correct place for your post. however it does appear that you have put a lot of thought and effort into this script.. i have to ask tho, why use hash tables for this when it could be kept a bit simpler by using variables?? none the less, good job on putting an interesting twist on it...

Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
This is indeed not the place to be posting your personal scripts, especially not when there was no request for it.

I haven't looked into the code, but a quick glance showed me you might be interested in learning about $iif.

Example:

if (!$2) { var %m = $asctime(mm) } | else { var %m = $2 }

becomes

var %m = $iif($2,$2,$asctime(mm))

Cleaner?

Btw, if !$2 is not the same as if $2 == $null, I don't know if you are aware of it.

--> if (!$2) means match if $2 is either: $null, $false, or 0
--> if ($2 == $null) means match if $2 is: $null (empty)


Greets


Gone.

Link Copied to Clipboard