mIRC Homepage
Posted By: miguelpucela Get first lines of /names command - 10/03/19 02:56 AM
Hello,
I'm trying to make a script that echos the first 3 lines of the output of the comand /names #channel.

I've being guessing of geting the output of names command into a variable, but I don't know how to do it.

I supose there's a better way to do it.

Any help or tip is welcome.

Thank you in advance.
Miguel
Posted By: Raccoon Re: Get first lines of /names command - 10/03/19 09:40 AM
Why only the first 3 lines?

Is it a channel that you're already in? If so, you can just use $nick(#,%i) to iterate though them.

RAW 353:*: { } will fire for each line of names listings

RAW 366:*: { } will fire for End of /Names List.

Use /debug -p @debug
Posted By: miguelpucela Re: Get first lines of /names command - 10/03/19 04:43 PM
I want to make a command to execute it in the status window. Let's say I want to print the first N lines of the names output of the M input arguments of the command:

/mycommand #chan1 #chan2 ... #chanM 4

The output should be the first 4 lines of the /names output of the M channels.

Another option could be to print the last M users connected to each channel.
Posted By: Raccoon Re: Get first lines of /names command - 11/03/19 12:43 AM
Are these channels that you are already joined to, or are these channels that you are sitting outside of?
Posted By: miguelpucela Re: Get first lines of /names command - 11/03/19 05:45 PM
In principle these are channels I'm sitting outside of.
Posted By: Erasimus Re: Get first lines of /names command - 22/03/19 07:04 PM
I too don't understand why you only want the 1st 3 lines.

I also dont understand why you find this difficult.
Code:
 
; set line counter to 1 and then only echo the lines 1-3
; to the status window. Use haltdef to prevent mIRC
; from sending any line to status window.
; needs to be set at some point -- say @ raw 001
On raw 001 :*: {
   Set %LineCounter 1
}

On raw 353:*: {
   if (%LineCounter <= 3) { //echo -s $1- }
   inc %LineCounter
   haltdef
}

; reset counter to 1 ready for next channel
On raw 366:*: { %LineCounter = 1 }


Of course this will affect any usage of the /names command, so you could set a variable in your 'mycommand' which you test for in the above on raw events, then reset that variable at the end of your command, to allow for normal usage.
Posted By: Raccoon Re: Get first lines of /names command - 22/03/19 10:52 PM
Not every network outputs RAW 001. Use On Connect instead to initialize your variables.
Posted By: miguelpucela Re: Get first lines of /names command - 23/03/19 01:19 AM
The final objective is to get the last users connected to several channels in only one command invokation.

I'm new to mirc scripting. That's why I find this difficult eek

Thank you for your help.
Posted By: Erasimus Re: Get first lines of /names command - 08/04/19 02:35 AM
Ooops, I forgot something from the last part of the code I gave.
Code:
; reset counter to 1 ready for next channel
On raw 366:*: { 
   %LineCounter = 1
   haltdef
}


As stated in the comments at the start of the previous code I detailed, haltdef tells mIRC to NOT display it's default output from the raw 366 message, namely the 'End of /NAMES list.'

Sorry about that .. I was coding on the fly at the time of my previous posting
Posted By: miguelpucela Re: Get first lines of /names command - 08/04/19 03:12 AM
I'm a bit confused ... I was trying to make a function in the Aliases window, but I cannot see any piece of code with that syntax (On raw ...) ... So I don't know where I'm suppose to include that code confused
Posted By: maroon Re: Get first lines of /names command - 08/04/19 03:41 AM
aliases window can only hold aliases, without the alias keyword. The alt+R remotes tab can have aliases, as well as events, so the ON events go there.

Good reading on various topics here
Posted By: miguelpucela Re: Get first lines of /names command - 09/04/19 12:44 AM
So after reading a bit and reading your code, I think I cannot do what I mean.

With your code, what I get is first 3 lines of names command everytime I invoke /names command.

What I wanted is to create a command (or alias) with which I get first 3 lines of names of each channel is input as argument of that command, but all the users are output if the normal /names command is used.

I don't know if inside a alias (or a command) I can set a flag variable that I can read inside a raw event to decide wether to output all the lines of names or only the first 3 ...
Posted By: Erasimus Re: Get first lines of /names command - 09/04/19 06:38 PM
You missed a bit from my 1st post in this thread:
Quote:
Of course this will affect any usage of the /names command, so you could set a variable in your 'mycommand' which you test for in the above on raw events, then reset that variable at the end of your command, to allow for normal usage.


If I remeber correctly your alias is called 'MyCommand'. In there set a variable to 1 and at the end of that alias set it to 0 (zero). Into that section On Raw 353

You put a test of that variable and only execute the code I wrote if it is true (i.e. is equal to 1).

Change things to this as an example
Code:
On raw 001 :*: {
   Set %LineCounter 1
}

On raw 353:*: {
   if (%MyTrigger) {
      if (%LineCounter <= 3) { //echo -s $1- }
      inc %LineCounter
      haltdef
   }
}

; reset counter to 1 ready for next channel
On raw 366:*: { 
   if (%MyTrigger) {
      %LineCounter = 1
      haltdef
   }
}


Now your My command will set %MyTrigger to 1, and any name commands that the alias sends will only get the 1st 3 lines displayed, and when all channels have been processed, you alias sets %MyTrigger to 0. If you then type /names #<whatever> the 'if %MyTrigger' will be false and those lines about %linecounter and haltdef are not executed.
Posted By: miguelpucela Re: Get first lines of /names command - 10/04/19 01:24 AM
Thank you!!

Now it's much clearer smile
© mIRC Discussion Forums