mIRC Home    About    Download    Register    News    Help

Print Thread
#40629 09/08/03 02:16 AM
K
KewlioMZX
KewlioMZX
K
As much as my scripting capability has evolved, these two scripts seem to not want to work. When I trigger one, it says "(mode name) OFF" without it even being on. It may be because of the "%md $+ $chan" within the "if" conditions; however, they seem to work fine when it comes to setting and unsetting. Here are my malfunctioning snippets:

/autoecho {
if (%md $+ $chan == sm) { echo 4 ERROR: Cannot use Auto Echo with Self-Mod on | halt }
if (%md $+ $chan == $null) {
if ($1- == $null) { echo 7 -at Auto Echo ON (default params) | set %md $+ $chan ae 14 -at }
else { echo 7 -at Auto Echo ON | set %md $+ $chan ae $1- }
}
else { echo 7 -at Auto Echo OFF | unset %md $+ $chan }
}

/selfmod {
if ($left (%md $+ $chan,2) == ae) { echo 4 ERROR: Cannot use Self-Mod with Auto Echo on | halt }
elseif (%md $+ $chan == $null) { echo 7 -at Self-Mod ON | set %md $+ $chan sm }
else { echo 7 -at Self-Mod OFF | unset %md $+ $chan }
}

#40630 09/08/03 02:32 AM
Joined: Dec 2002
Posts: 1,253
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Dec 2002
Posts: 1,253
if ($eval($+(%,md,$chan) ,2) == sm)
if ($eval($+(%,md,$chan) ,2) == $null)

#40631 09/08/03 03:06 AM
K
KewlioMZX
KewlioMZX
K
OK, it now triggers semi-correctly. However, there's still a problem. Here's what I have so far:

/autoecho {
if ($eval($+(%,md,$chan) ,2) == sm) { echo 4 ERROR: Cannot use Auto Echo with Self-Mod on | halt }
if ($eval($+(%,md,$chan) ,2) == $null) {
if ($1- == $null) { echo 7 -at Auto Echo ON (default params) | set %md $+ $chan ae 14 -at }
else { echo 7 -at Auto Echo ON | set %md $+ $chan ae $1- }
}
else { echo 7 -at Auto Echo OFF | unset %md $+ $chan }
}

/selfmod {
if ($left ($eval($+(%,md,$chan) ,2),2) == ae) { echo 4 ERROR: Cannot use Self-Mod with Auto Echo on | halt }
elseif ($eval($+(%,md,$chan) ,2) == $null) { echo 7 -at Self-Mod ON | set %md $+ $chan sm }
else { echo 7 -at Self-Mod OFF | unset %md $+ $chan }
}

At this point, both modes will succesfully trigger on, but if I were to use /autoecho to turn Auto Echo on, then used /selfmod, it says "Self-Mod OFF" and turns everything off. I may have corrected the script incorrectly, but not many instructions were left to fix it. Also:

on *:input:#:{
if ($left($1,1) != /) {
if ($eval($+(%,md,$chan) ,2) == sm) { /echo 4 -at SELF-MOD IS ON: 7Cannot chat in this channel | /halt }
if ($left($eval($+(%,md,$chan) ,2),2) == ae) { /echo $right(%md $+ $chan,len(%md $+ $chan - 3) $1- | halt }
}
}

Self-Mod works correctly; no messages get through, but commands do. However, Auto Echo doesn't. Here, Auto Echo is a feature that makes anything you type into an echo instead of a message transmitted to the channel. I tried to make it read the parameters, but it gives me a scripting error and sends the given message to the channel. An example of parameters:

%md#(channel name) ae 14 -at

It should read past the "ae" (which the script would recognize as "Auto Echo") and look at the parameters, then use them automatically in the echoed line.

Last edited by KewlioMZX; 09/08/03 03:19 AM.
#40632 09/08/03 08:59 AM
Joined: Dec 2002
Posts: 1,253
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Dec 2002
Posts: 1,253
%md#channel can be only in 3 states:
  • ae # -at
  • sm
  • $null
which means we can tidy up the script slightly by simply using if !$eval( ) (which is true in the $null state). Here's how I would have written the same functions (cleaning up your code slightly):
Code:

autoecho {
  if $eval($+(%,md,$chan), 2) == sm {
    echo 4 ERROR: Cannot use Auto Echo with Self-Mod on
  }
  elseif !$eval($+(%,md,$chan), 2) { 
    if !$1- {
      echo 7 -at Auto Echo ON (default params)
      set %md $+ $chan ae 14 -at 
    }
    else {
      echo 7 -at Auto Echo ON
      set %md $+ $chan ae $1- 
    }
  }
  else {
    echo 7 -at Auto Echo OFF
    unset %md $+ $chan 
  }
}
selfmod {
  if ae * iswm $eval($+(%,md,$chan), 2) {
    echo 4 ERROR: Cannot use Self-Mod with Auto Echo on
  }
  elseif !$eval($+(%,md,$chan), 2) {
    echo 7 -at Self-Mod ON
    set %md $+ $chan sm 
  }
  else {
    echo 7 -at Self-Mod OFF
    unset %md $+ $chan 
  }
}
on *:input:#:{
  if $left($1,1) != / {
    if $eval($+(%,md,$chan), 2) == sm {
      echo 4 -at SELF-MOD IS ON: 7Cannot chat in this channel
      halt
    }
    if ae * iswm $eval($+(%,md,$chan), 2) {
      echo $right($eval($+(%,md,$chan), 2), -3) $1-
      halt
    }
  }
}

Your two errors are:
  • In the /selfmod alias, $left must touch its ( .. yours had a space between them. This causes the initial condition (the ae check) to fail since "($eval($+(%,md,$chan) ,2),2)" will be treated as the string to compare to "ae" which is obviously no match and the condition fails. The elseif will fail because "%md#channel" is not $null. That leaves only the else, which correctly echo "Self-Mod off" and unset the variable.
  • In the on INPUT, you can simply use $right($eval($+(%,md,$chan), 2), -3) instead of doing all the calculations. Your calculations were completely hosed, anyway, as were your mismatched parentheses. $right($eval($+(%,md,$chan), 2), $calc($len($eval($+(%,md,$chan), 2)) - 3) would be correct, though cumbersome. Also, your $len needed a $, in addition to needing a $calc( ) to calculate everything. You could also have used $mid($eval($+(%,md,$chan), 2), 4) if that is more intuitive for you.
There's no need for a halt in the aliases, if you slightly restructure your if statements as I have done above. Once the code inside the matching if-elseif condition is completed, control drops out of the if-elseif-else control structure with no other code other than that control structure.

#40633 10/08/03 01:02 AM
K
KewlioMZX
KewlioMZX
K
OK, now it's working, but when I exit mIRC, it leaves the residue of the previously set switches. I know this is no longer troubleshooting but rather improving upon my script, but this board works both ways, right? smile

Anyhow, I've set it so it'll go away if I leave a channel normally...but how do I set it so it'll go away on quit and on disconnect?

#40634 10/08/03 01:51 AM
Joined: Dec 2002
Posts: 1,253
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Dec 2002
Posts: 1,253
on *:DISCONNECT: unset %md*

This brings me to an important point. If you are setting %md#channel and are in the same channel on multiple connections (even different networks), you need to use $cid as part of the variable name or you'll unset the wrong connection's variables.

Suppose that I happen to be connected to DALnet on my first connection, EFnet on my second connection and undernet on my third connection (as I currently happen to be). DALnet's $cid is 1, EFnet's is 2 and undernet's is 3. By building my variables using the $cid, I can get disconnected from any of them and still unset the correct connection's variable set.

DALnet
[color:00007F]%md1#mIRC
%md1#HelpDesk[/color]

EFnet
[color:00007F]%md2#mIRC
%md2#Help[/color]

undernet
[color:00007F]%md3#mIRC[/color]

To build your variables this way works exactly the same (with little added code) way you're building them already: the % to indicate a variable, md, followed by $cid and finally the $chan.

To create the variable:
[color:840017]$+(%, md, $cid, $chan)[/color]

To get the value of that variable:
[color:00007F]$eval([color:840017]$+(%, md, $cid, $chan)[/color], 2)[/color]

NOTE: This will change the event I posted first, but only slightly. The ON START is added in case you lose power rather than quitting normally where mIRC has a chance to clean up before exiting cleanly.
[color:840017]
on *:START: unset %md*
on *:DISCONNECT: unset $+(%, md, $cid, *)[/color]

#40635 10/08/03 06:38 AM
K
KewlioMZX
KewlioMZX
K
It's Hammer Time, isn't it? laugh

Anyhow, thanks for the help.


Link Copied to Clipboard