mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Aug 2004
Posts: 7,252
R
RusselB Offline OP
Hoopy frood
OP Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
I have the following line in a script, and was wondering if there was an easier way to do the same thing. I'm not sure why, but I've got a funny feeling that a regex format would work better, but my attempts haven't worked (probably due to a lack of knowledge rather than lack of ability via regex)
Code:
set %user $iif(a isincs $usermode,Services Admin,$iif(A isincs $usermode,Server Admin,$iif(C isincs $usermode,Co-Admin,$iif(h isincs $usermode,Help-Op,$iif(o isincs $usermode,Global Op,$iif(O isincs $usermode,Local Op,Regular User))))))

Joined: Oct 2006
Posts: 166
B
Vogon poet
Offline
Vogon poet
B
Joined: Oct 2006
Posts: 166
I never tried it but might be..

Code:
alias xx {
  if (aAChoO isincs $usermode) {
    set %user $replacexcs($v1,A,Services Admin,A,Server Admin,C,Co-Admin,h,Help-Op,o,Global Op,O,Local Op)
  }
  if (%user) return $ifmatch
  return Regular User
}


Kind Regards, blink
Joined: Oct 2005
Posts: 1,741
G
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
I don't think that a regex would be very useful in this situation. And personally, I don't like the $iif($iff($iff($iff style of coding as I find it hard to follow.

Here is how I would write that code:
Code:
alias usertype {
  ;$1= usermode string
  var %umode = $1, %L = O,o,h,C,A,a
  var %T = Local Op,Global Op,Help-Op,Co-Admin,Server Admin,Services Admin
  var %type = Regular User, %c = 0, %cc = $numtok(%L,44)
  while (%c < %cc) {
    inc %c
    if ($gettok(%L,%c,44) isincs %umode) %type = $gettok(%T,%c,44)
  }
  return %type
}


You can add more modes by adding the mode to %L and its corresponding string to %T. The modes are read from right to left in %L, so modes to the right overwrite existing modes to the left. Example:

o = Local Op
a = Server Admin
ao = Server Admin ('a' is farther right in %L than 'o' is)

-genius_at_work

Joined: Aug 2004
Posts: 7,252
R
RusselB Offline OP
Hoopy frood
OP Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Thanks to both of you for your suggestions.

Joined: Aug 2004
Posts: 7,252
R
RusselB Offline OP
Hoopy frood
OP Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
I thank you again for your assistance, but was wondering if this could be done in a single line, since I want to use it in a menu system, so multiple lines don't work well, or at least, I haven't found a way to get them to work well.

Never mind...Just have to call the alias as an identifier

Last edited by RusselB; 06/11/06 12:24 AM.

Link Copied to Clipboard