mIRC Home    About    Download    Register    News    Help

Print Thread
#150715 07/06/06 06:11 PM
Joined: Mar 2004
Posts: 3
P
Self-satisified door
OP Offline
Self-satisified door
P
Joined: Mar 2004
Posts: 3
Hi everyone!

I want to write a short script which say hello when there are more than 2 people on the channel and say hi when there are only 1. I have written one, but it doesn't work, always say hi... I don't know where I made a mistake. Please help if anyone has an idea.

Code:
 on *:join:#:{
  if ($nick == $me) {
    if ($nick($chan,0) >= 2) /msg $chan hello
    else { /msg $chan hi }
  }
  else halt
}

#150716 07/06/06 06:51 PM
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
That's because you haven't received the nicks on the channel at that point. Try this:

Code:
raw 353:*:{
  if ($0 > 5) msg $3 hello
  else msg $3 hi
}

#150717 07/06/06 08:30 PM
Joined: Jun 2006
Posts: 5
R
Nutrimatic drinks dispenser
Offline
Nutrimatic drinks dispenser
R
Joined: Jun 2006
Posts: 5
Another way around the fact that the IAL isn't yet populated is to issue a /WHO $chan when the $nick == $me.

This will populate the IAL which is often what is checked by commands that don't do the raw level interactions.

Read up on the IAL.

One other comment- you might want to get in the habit of having most of your scripts keyed to not take any action while some kind of initialize time variable is set to initializling- this will help you avoid flooding services as so often happens when you have scripts and first get online. You could have most/all scripts test if %initdone == true, and if not, ignore the script. Then, in your start up scripts put something like:

/timer 1 30 /set %initdone == true .

This also helps with the fact that sometimes services lag [alot] especially after netsplits where many people are rejoining with you, and services get really slow.

Just some thoughts!

#150718 07/06/06 08:46 PM
Joined: Mar 2004
Posts: 3
P
Self-satisified door
OP Offline
Self-satisified door
P
Joined: Mar 2004
Posts: 3
I tested my version a lot of way and I noticed that this script is too fast. I mean that I set a variable which contains the number of the nicks and it is always 1. So I think I need to wait until about 1 or 2 secs to the right nick number. (I test it with an /test alias, and it sets the number what I wanted).
So can somebody tell me how can I delay the whole script? I mean that after I joined to a room the script is waiting for some secs and continue to run. Thanks a lot for the helps or ideas!

#150719 07/06/06 09:10 PM
Joined: Jun 2006
Posts: 5
R
Nutrimatic drinks dispenser
Offline
Nutrimatic drinks dispenser
R
Joined: Jun 2006
Posts: 5
Quote:
I tested my version a lot of way and I noticed that this script is too fast. I mean that I set a variable which contains the number of the nicks and it is always 1. So I think I need to wait until about 1 or 2 secs to the right nick number. (I test it with an /test alias, and it sets the number what I wanted).
So can somebody tell me how can I delay the whole script? I mean that after I joined to a room the script is waiting for some secs and continue to run. Thanks a lot for the helps or ideas!


Delaying it won't help. You need to go read and understand the IAL. Basically, many commands check the IAL and IBL for information rather than asking the server. However, the IAL is only updated when a user posts a message or changes a mode. In some rooms I find that the "nicks" known is actually less than 50% of the ones present.

Read about the IAL.

#150720 07/06/06 10:28 PM
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Hixxy's well work and would be the best id say. (havent checked but i trust him!), but it does seem complexe to understand for people who dont know what the raws are.

Here is a method, altering as little of your code as possable.

Code:
on *:join:#:{
  if ($nick == $me) {
    .timer 1 3 on.join.msg $chan
  }
}
alias -l on.join.msg {
  if ($nick($1,0) >= 2) /msg $1 hello
    else { /msg $1 hi }
  }
}

* code untested *
on join , it cheks if it u, then sets off a time to do the rest in ON.JOIN.MSG alias , since the timer wont have $chan i pass it using $1
By waiting 3 seconds u can be pretty sure the channel list of nicks is done with so u know how many people there are, 1 seconds likely long enough.


This could be compacted down to this but again its harder for people to understand

Code:
on me:*:join:#:{ .timer 1 3 msg $chan $!iif($nick( $chan , 0) >=2,hello,hi) }

* code untested *

the me: makes it go off only on you. the timer is the actual MSG with a inline conditional for hi or hello the timer command would end up looking like this
MSG #channel $iif($nick( #channel ,0) >=2,hello,hi)

the $iif means if theres 2 or more it uses hello else use hi aka $iif(<condition>,<true>,<false>) returns with <true> or <false>

#150721 08/06/06 09:56 AM
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Passing $chan to /timer isn't too safe; eg #$me (which is a perfectly valid channel name) would evaluate to your nick. One can use either $encode(#,m) (and $decode($1,m) inside the alias) or . $+ # (and $mid($1,2) inside the alias).


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
#150722 08/06/06 12:26 PM
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Hmmm learn something new everyday, I had assumed the # at the front of the channel name would halt any evaluation of identifiers appears it doesnt, as u expressed.

Your right of course and that little mistake could theroreticly could lead to trouble (well maybe), if i had known that i would have added extra sheilding as u suggested, maybe

ON me:*:join:#:{ .timer 1 3 msg $!( $chan ,) $!iif($nick($( $chan ,),0) >= 2,hello,hi) }

I use these around nicks (well i should but forget to often) becuase the nick | is valid and would make itself into a cmd break of course.

PS also fixed >=2 to be >=<space>2 (oops!)


I do find it strange that # doesnt stop evaluation of a identifier that follows it, I had never encountered that before, am now wondering if there is any reason for it?

#150723 08/06/06 12:45 PM
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
ON me:*:join:#:{ .timer 1 3 msg $!( $chan ,) $!iif($nick($( $chan ,),0) >= 2,hello,hi) }

This can still break if the chan is like #$me) for example. I'd stick to the alias solution wink

As to why #$ident works, it's most probably related to the #$N feature described in /help Aliases


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
#150724 08/06/06 07:49 PM
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Quote:
This can still break if the chan is like #$me) for example. I'd stick to the alias solution wink


naaa screw em! lol, they wanna name there channels something stupid its there own problem. <no actually i use the encode decode one i think>

Quote:
As to why #$ident works, it's most probably related to the #$N feature described in /help Aliases


So it looks like it was a small patch put in becuase people would forget to put # on channel names when asked for them, so now u can add em to the front.

Well we live with what it is I guess.


Link Copied to Clipboard