mIRC Homepage
Posted By: bwr30060 Problem with simple script - 12/05/06 02:56 PM
I came up with this idea to make it easier to send scripts over mIRC. If you paste a script into a channel or query, the person has to remove <Blake> from the beginning of every line, so I'd like to be able to have this dialog for sending scripts. Both people would have to have this script, but what it would do would be to put the sent script into a @window to make it easier to copy. I'm having problems with this though, and I can't figure where all the problems are. In my status window, it's doing a few things. It looks like it's trying to send a notice to someone named Send with the text Script, and I'm also getting "* /ctcp: insufficient parameters (line 19, scriptsend.mrc)". Line 19 is:

ctcp $snick(#,%x) endscript

Here's what I have so far:
Code:
dialog scriptsend {
  title "Script Sender"
  size -1 -1 428 470
  option pixels notheme
  edit "", 1, 4 9 419 316,multiline, vsbar
  button "Send Script", 2, 4 332 65 25
}
On *:Dialog:scriptsend:sclick:2: {
  var %x = 1
  while (%x &lt;= $snick(#,0)) {
    ctcp $snick(#,%x) script
    inc %x
  }      
  var %y = 1
  while %y &lt;= $did(scriptsend,1).lines {
    msg $snick(#,%x) $did(scriptsend,1,%y).text
    inc %y
  }      
  ctcp $snick(#,%x) endscript
}
ctcp ^*:scriptsend: {
  haltdef  
  set %script 1
  if ($window(script)) {
    aline @script $crlf
  }
  else {
    window @script
  }
}
ctcp ^*:endscript: {
  haltdef
  unset %script
}
on *:text:*:*:{
  if (%script) {
    aline @script $1-
  }
}

Thanks for any help.

OK, I fixed the problem with it sending to the wrong nick. I'm still having a problem though. I need to have it remember every selected nick so it can send the script to them, and right now, it's saying:

dialog No such nick/channel
-
title No such nick/channel

etc. How would I save the nicks since I have to get out of that loop to send the script?
Posted By: DaveC Re: Problem with simple script - 12/05/06 03:11 PM
Code:
On *:Dialog:scriptsend:sclick:2: {
  var %x = 1
  while (%x &lt;= $snick(#,0)) {
    ctcp $snick(#,%x) script
    var %y = 1
    while %y &lt;= $did(scriptsend,1).lines {
      msg $snick(#,%x) $did(scriptsend,1,%y).text
      inc %y
    }      
    ctcp $snick(#,%x) endscript
    inc %x
  }      
}
Posted By: bwr30060 Re: Problem with simple script - 12/05/06 03:22 PM
Thanks. That got rid of the errors, but now it just doesn't do anything. It doesn't send any script.
Posted By: bwr30060 Re: Problem with simple script - 12/05/06 05:06 PM
Code:
On *:Dialog:scriptsend:sclick:2: {
  var %x = 1
  while (%x &lt;= $snick(#,0)) {
    ctcp $snick(#,%x) script
    inc %x
  }    
  var %y = 1
  while %y &lt;= $did(scriptsend,1).lines {
    msg Blake $did(scriptsend,1,%y).text
    inc %y
  }      
  ctcp $snick(#,%x) endscript
  inc %x
}
ctcp *:script: {
  set %script 1
}
ctcp ^*:endscript: {
  unset %script
}
on *:text:*:*:{
  if (%script) {
    aline @script $1-
  }
}

This script will send me the text I want, but only because I hard coded my name. It seems to have problems with $snick(#,%x). I left the ctcp the way it is and it always errors out on that line. Any ideas?
Posted By: bwr30060 Re: Problem with simple script - 12/05/06 05:25 PM
This script works. It sends the script to a window, but there's still a problem. To make this work, I had to hard code the name of the channel. It seems like the dialog event won't recognize which nicks are selected in the nick list. I'd really like to fix this so I don't have to hard code channel names.
Code:
dialog scriptsend {
  title "Script Sender"
  size -1 -1 428 470
  option pixels notheme
  edit "", 1, 4 9 419 316,multiline, vsbar
  button "Send Script", 2, 4 332 65 25
}
On *:Dialog:scriptsend:sclick:2: {
  $SendScript($snick(#chat,1))
}
ctcp ^*:script: {
  haltdef  
  set %script 1
}
ctcp ^*:endscript: {
  unset %script
}
on *:text:*:*:{
  if (%script) {
    aline @script $1-
  }
}
alias SendScript {
  if ($window(script)) {
    aline @script $crlf
  }
  else {
    window @script 
    ctcp $1 script
    var %y = 1
    while %y &lt;= $did(scriptsend,1).lines {
      msg $1 $did(scriptsend,1,%y).text
      inc %y
    }  
    ctcp $snick(#,%x) endscript
  }
}
Posted By: schaefer31 Re: Problem with simple script - 12/05/06 05:25 PM
I believe it should be $active in place of # since # isn't going to have a value in a dialog event.
Posted By: bwr30060 Re: Problem with simple script - 12/05/06 05:38 PM
Thanks, that works. grin Another small thing, no big deal if I can't do this. This script sends a query with the script text you'd like to send, and also puts it in a window. If I can, I'd like to not have the query window show up at all. I put a haltdef, but the window still opens, there's just no text in it. Can this be done? Thanks.
Code:
on ^*:text:*:?:{
  if (%script) {
    haltdef    
    if ($window(script)) {    
      aline @script $1-
    }
    else {
      window @script
      aline @script $1-
    }
  }    
}

It's also not halting my CTCPs from showing up.
Posted By: schaefer31 Re: Problem with simple script - 12/05/06 05:47 PM
I'm not sure if you can prevent the window from opening, but you could hide the window while the script is still sending and close it when finished.

/window -h <window-name>
/window -c <window-name>

Also, on this line:

if ($window(script)) {

I believe you meant:
if ($window(@script)) {
Posted By: bwr30060 Re: Problem with simple script - 12/05/06 05:50 PM
Sorry, I meant the query window. I'd like to not have it show up at all if the query I'm getting is a script being sent using this script.
Posted By: schaefer31 Re: Problem with simple script - 12/05/06 05:51 PM
You can hide the query window.

/window -h <some-nick>
Posted By: bwr30060 Re: Problem with simple script - 12/05/06 05:52 PM
Ah, ok. Thanks smile
Posted By: DaveC Re: Problem with simple script - 12/05/06 09:24 PM
Code:
on ^*:open:?:*:{ possable.script.text $1- }
on ^*:text:*:?:{ possable.script.text $1- }
alias -l possable.script.text {
  if (%script) {
    haltdef    
    window @script
    aline @script $1-
  }
}

* code untested *

Try out that, It uses the open pm event to get the text if the window doesnt exist, and stops the Pm window opening, if its already open then it cacthes it using text pm event, I think this is better than hiding the window, as if the user already had a pm open to the person, they most likely dont want it hidden.

I also simplified the sending the text to the @script window, i just create it everytime, if it exists already who cares, telling mirc to create it when already in existence is ignored (and is slightly faster than checking for it anyway)
Posted By: bwr30060 Re: Problem with simple script - 12/05/06 09:28 PM
This works for what I want to do. I might try yours later tonight just to see, but here's what I have.
Code:
dialog scriptsend {
  title "Script Sender"
  size -1 -1 428 470
  option pixels notheme
  edit "", 1, 4 9 419 316, multi vsbar
  button "Send Script", 2, 4 332 65 25
  button "Clear", 3, 76 332 65 25
}
On *:Dialog:scriptsend:sclick:2: {
  var %x = 1
  while (%x &lt;= $snick($active,0)) {
    ctcp $snick($active,%x) script
    var %y = 1
    while %y &lt;= $did(scriptsend,1).lines {
      msg $snick($active,%x) $did(scriptsend,1,%y).text
      inc %y
    }      
    ctcp $snick($active,%x) endscript
    inc %x
  }
}  
ctcp ^*:script: {
  haltdef  
  set %script 1
}
ctcp ^*:endscript: {
  haltdef  
  unset %script
}
on ^*:text:*:?:{
  if (%script) {
    window -h $nick   
    if ($window(@script)) {    
      aline @script $1-
    }
    else {
      window @script
      aline @script $1-
    }
  }    
}
alias SendScript {
  if ($window(script)) {
    aline @script $crlf
  }
  else {
    window @script 
    ctcp $1 script
    var %y = 1
    while %y &lt;= $did(scriptsend,1).lines {
      msg $1 $did(scriptsend,1,%y).text
      inc %y
    }  
    ctcp $snick($active,%x) endscript
  }
}
On *:Dialog:scriptsend:sclick:3: {
  did -r scriptsend 1
}
Posted By: DaveC Re: Problem with simple script - 12/05/06 10:28 PM
Code:
dialog scriptsend {
  title "Script Sender"
  size -1 -1 428 470
  option pixels notheme
  edit "", 1, 4 9 419 316, multi vsbar
  button "Send Script", 2, 4 332 65 25
  button "Clear", 3, 76 332 65 25
}
On *:Dialog:scriptsend:sclick:2: {
  var %x = 1
  while (%x &lt;= $snick($active,0)) {
    .ctcp $snick($active,%x) script
    var %y = 1
    while %y &lt;= $did(scriptsend,1).lines {
      .msg $snick($active,%x) $did(scriptsend,1,%y).text
      inc %y
    }      
    .ctcp $snick($active,%x) endscript
    inc %x
  }
}  
On *:Dialog:scriptsend:sclick:3: {
  did -r scriptsend 1
}
ctcp ^*:script: {
  haltdef  
  set -u600 $+(%,script.,$nick) 1
}
ctcp ^*:endscript: {
  haltdef  
  unset $+(%,script.,$nick)
}
on ^*:open:?:*:{ possable.script.text $1- }
on ^*:text:*:?:{ possable.script.text $1- }
alias -l possable.script.text {
  if ($($+(%,script.,$nick),2)) {
    haltdef
    window @script
    aline @script $1-
  }    
}


try that out, its untested, but i think it well work.
I added . to the ctcp's and the msg's so you dont have to see them all being sent (add or remove at your pleasure)
I added dynamicly named %script vars so its turned of and on per user, while its possable two users might dump u a script at the same moment, causing mucking up of the @script window, this way at least, if one person is sending you a script and another pming you in chat, his chat wont end up in the script window.
Also added a 10min auto unset to the setting of the $script.$nick var incase the user never sends the turn off code
Used my idea for the on texts to not create the pm window, or ignore it if it exists.

One last possable alturnative is also this
Code:
alias -l possable.script.text {
  if ($($+(%,script.,$nick),2)) {
    haltdef
    window $+(@script.,$nick)
    aline $+(@script.,$nick) $1-
  }    
}

This would create sepreate @script.$nick windows so u could track who sent what script, and avoid the chance of two same time sent scripts overlapping in the same window.
This may however be few and far between, i dont know how active the channel u mentioned is.
Posted By: bwr30060 Re: Problem with simple script - 12/05/06 10:34 PM
Thanks. I'll give that one a try too. The channel I'm talking about is on my own IRC server, which really has not had many people at all on it. so at least I won't have to worry about messages getting put in the window. Anyone is still welcome to check out my IRC server. I'd like to have it be a place where you can discuss scripts, if it ever gets going.
Posted By: bwr30060 Re: Problem with simple script - 13/05/06 01:04 AM
This seems to be having a problem. This is the final script I ended up with (I haven't tried the other one yet), and the one loop seems to be failing. It's the loop to check how many lines are in the edit box so that it sends them all. For some reason, the loop seems to keep going even after the number of lines is exceeded, and then %script doesn't get unset. This causes a problem, because then other queries get put into the @window. Can anyone figure out why this is failing? I'll just repost the section of code where that loop is.
Code:
On *:Dialog:scriptsend:sclick:2: {
  var %x = 1
  while (%x &lt;= $snick($active,0)) {
    ctcp $snick($active,%x) script
    var %y = 1
    while %y &lt;= $did(scriptsend,1).lines {
      msg $snick($active,%x) $did(scriptsend,1,%y).text
      inc %y
    }      
    ctcp $snick($active,%x) endscript
    inc %x
  }
}
Posted By: bwr30060 Re: Problem with simple script - 13/05/06 01:42 AM
I know what the issue is, but I'm not sure how to solve it. It only errors out sometimes, and this is because sometimes when I'm sending a script to test, I paste the whole thing and then decide I only need to send a few lines. I then delete all but about three lines, leaving the cursor on a blank line. The line count considers where the cursor is to be a line, but there's no text there, so it can't be set to a variable. How can I handle this so that it would check to make sure that there is something on that line before setting it to a variable? Thanks.

EDIT:

There is another problem. After I send someone a script, they don't get my queries that I send them.
Posted By: genius_at_work Re: Problem with simple script - 13/05/06 02:45 AM
You need to add a line to skip blank lines. Add this line as the first line inside the second while-loop.


if ($did(scriptsend,1,%y).text == $null) continue

-genius_at_work
Posted By: qwerty Re: Problem with simple script - 13/05/06 09:07 AM
I'd use
if ($remove($did(scriptsend,1,%y).text,$chr(32)) == $null) continue
to prevent errors with lines that contain only spaces.
Posted By: bwr30060 Re: Problem with simple script - 13/05/06 01:56 PM
I just tried both ways you two mentioned and the script locks up either way. What am I doing wrong. And this might be a stupid question, but did you literally want me to have the word "continue" there? I haven't seen that used. Thanks.
Code:
On *:Dialog:scriptsend:sclick:2: {
  var %x = 1
  while (%x &lt;= $snick($active,0)) {
    ctcp $snick($active,%x) script
    var %y = 1
    while %y &lt;= $did(scriptsend,1).lines {
      if ($remove($did(scriptsend,1,%y).text,$chr(32)) == $null) continue      
      msg $snick($active,%x) $did(scriptsend,1,%y).text
      inc %y
    }      
    ctcp $snick($active,%x) endscript
    inc %x
  }
} 
Posted By: bwr30060 Re: Problem with simple script - 13/05/06 03:18 PM
I came up with an idea that I thought would work, but it just freezes mIRC, like the other suggestions did too. Why would it do that? Here's what I tried.
Code:
while %y &lt;= $did(scriptsend,1).lines {
      if ($did(scriptsend,1,%y).len &gt;= 1) || ($did(scriptsend,1,%y) == $chr(32)) {      
        msg $snick($active,%x) $did(scriptsend,1,%y).text
        inc %y
      }      
    }
Posted By: genius_at_work Re: Problem with simple script - 13/05/06 05:39 PM
I just noticed that you have the inc %y at the end of the loop. That means, when a blank line is encountered the inc %y never happens. When I'm making loops, I usually put the inc %y part as the first command within the loop so it is guaranteed to work.

Try replacing the second loop with this:

Code:
var %y = 0, %yy = $did(scriptsend,1).lines
while (%y &lt; %yy) {
  inc %y
  if ($remove($did(scriptsend,1,%y).text,$chr(32)) == $null) continue 
  msg $snick($active,%x) $did(scriptsend,1,%y).text 
} 


-genius_at_work
Posted By: hixxy Re: Problem with simple script - 13/05/06 05:43 PM
Just moving the inc %y outside of the if statement would also work:

Code:
while %y &lt;= $did(scriptsend,1).lines {
  if ($did(scriptsend,1,%y).len) || ($did(scriptsend,1,%y) == $chr(32)) {      
    msg $snick($active,%x) $did(scriptsend,1,%y)
  }
  inc %y
}
Posted By: bwr30060 Re: Problem with simple script - 13/05/06 06:53 PM
That's still giving me problems. That actually made me disconnect from the server with a "Connection reset by peer". This seems like it should be easy to come up with, but I'm not able to figure it out.
Posted By: hixxy Re: Problem with simple script - 13/05/06 08:45 PM
Did you try it more than once?
Posted By: bwr30060 Re: Problem with simple script - 13/05/06 09:54 PM
I just tried that last suggestion, and it works to send a script to someone, but the problem is that after I send you a script, you won't see queries from me, and I think anyone else. I don't know why.

I think the problem has to be somewhere here:
Code:
on *:text:*:?:{
  if (%script) {
    window -h $nick   
    if ($window(@script)) {    
      aline @script $1-
    }
    else {
      window @script
      aline @script $1-
    }  
  }    
}
Posted By: bwr30060 Re: Problem with simple script - 13/05/06 10:15 PM
I just made a change, and I have no idea why it won't work. It still blocks queries after you've received a script with this script.
Code:
On *:Dialog:scriptsend:sclick:2: {
  var %x = 1
  while (%x &lt;= $snick($active,0)) {
    ctcp $snick($active,%x) script
    var %y = 1
    while %y &lt;= $did(scriptsend,1).lines {
      if ($did(scriptsend,1,%y).len) || ($did(scriptsend,1,%y) == $chr(32)) {      
        msg $snick($active,%x) $did(scriptsend,1,%y)
      }
      inc %y
    }     
    ctcp $snick($active,%x) endscript
    inc %x
  }
}  
ctcp ^*:script: {
  set %script 1
  window @script
}
ctcp ^*:endscript: {
  unset %script
}
on *:text:*:?:{
  if (%script) {
    window -h $nick    
    aline @script $1-
  }
  else { .echo -q nothing }
}
Posted By: DaveC Re: Problem with simple script - 14/05/06 12:27 AM
if ($remove($did(scriptsend,1,%y).text,$chr(32)) == $null) continue

replace with

if ($remove($did(scriptsend,1,%y).text,$chr(32)) == $null) { inc %y | continue }

/continue means jump execution to the /WHILE loop, it was just a slight oversite in forgetting to increment the loop counter, thus jamming the loop on the same line forever. the inc %y corrects that.
Posted By: bwr30060 Re: Problem with simple script - 14/05/06 01:13 AM
Sorry for the question, but what would that whole section be then? I don't have that $null part you mentioned. My On Dialog event looks like this:
Code:
On *:Dialog:scriptsend:sclick:2: {
  var %x = 1
  while (%x &lt;= $snick($active,0)) {
    ctcp $snick($active,%x) script
    var %y = 1
    while %y &lt;= $did(scriptsend,1).lines {
      if ($did(scriptsend,1,%y).len) || ($did(scriptsend,1,%y) == $chr(32)) {      
        msg $snick($active,%x) $did(scriptsend,1,%y)
      }
      inc %y
    }     
    ctcp $snick($active,%x) endscript
    inc %x
  }
}


I think I know what you meant to try. Is this correct? If it is, I tried it just now, and the other person still doesn't get queries after I send a script with this. I don't think it's a problem in the On Dialog event. I think the problem is with the on *:text:?: event. Here's the dialog event.
Code:
On *:Dialog:scriptsend:sclick:2: {
  var %x = 1
  while (%x &lt;= $snick($active,0)) {
    ctcp $snick($active,%x) script
    var %y = 1
    var %y = 0, %yy = $did(scriptsend,1).lines
    while (%y &lt; %yy) {
      inc %y
      if ($remove($did(scriptsend,1,%y).text,$chr(32)) == $null) { inc %y | continue } 
      msg $snick($active,%x) $did(scriptsend,1,%y).text 
    }      
    ctcp $snick($active,%x) endscript
    inc %x
  }
}  

And here's the text event.
Code:
on *:text:*:?:{
  if (%script) {
    window -h $nick    
    aline @script $1-
  }
  else { .echo -q nothing }
}
© mIRC Discussion Forums