mIRC Home    About    Download    Register    News    Help

Print Thread
D
DuXxXieJ
DuXxXieJ
D
Hi, a while ago I've requested on this forum board an login script, which works fine, but now I want to make other scripts ONLY work when they are logged in (within my login script). So, when I use the trigger ".totalscripts" it may only work when I am logged in.

Here are the 2 scripts, the ".totalscripts" script, and the login script (which contains all the vars etc..)

Code:
ON 1:TEXT:*:#:{
  if $1 == .totalscripts {
    msg $chan TOTAL SCRIPTS: $script(0)
  }
}


Code:
on *:text:*:?: {
  if ($1 == .login) {
    var %nick = $findtok(%admin,$nick,32)
    if (%nick) {
      if ($gettok(%admincode,%nick,164) == $2-) {
        if ($gettok(%adminstatus,%nick,32) == Off) {
          msg $nick LOGIN: You are now logged in as $nick $+ .
          set %adminstatus $puttok(%adminstatus,On,%nick,32)
        }
        else {
          msg $nick LOGIN: You are already logged in.
        }
      }
      else {
        msg $nick LOGIN: Invalid password or nickname (your current nickname).
      }
    }
    else {
      msg $nick LOGIN: You aren't an admin or user.
    }
  }
  elseif ($1 == .logout) {
    var %nick = $findtok(%admin,$nick,32)
    if (%nick) {
      if ($gettok(%admincode,%nick,164) == $2-) {
        if ($gettok(%adminstatus,%nick,32) == On) {
          msg $nick LOGOUT: You are now logged out.
          set %adminstatus $puttok(%adminstatus,Off,%nick,32)
        }
        else {
          msg $nick LOGOUT: You aren't logged in.
        }
      }
      else {
        msg $nick LOGOUT: Invaled password or nickname (your current nickname)
      }
    }
    else {
      msg $nick LOGOUT: You aren't an admin or user.
    }
  }
  elseif ($1 == .add-admin) {
    if ($nick == %owner || $nick == %secondowner) { 
      if (!$3) { msg $nick ADD: Invalid format: .add-admin nick passcode | return }
      var %nick = $findtok(%admin,$2,32)
      if (%nick) {
        msg $nick ADD: $2 is already added.
        msg $nick ADD: $2's password is $gettok(%admincode,%nick,164) $+ .
        return
      }
      else {
        set %admin $instok(%admin,$2,0,32)
        set %admincode $instok(%admincode,$3-,0,164)
        set %adminstatus $instok(%adminstatus,Off,0,32)
        msg $nick ADD: New admin named " $+ $2 $+ ".
        msg $nick ADD: Password of $2 is $3- $+ .
      }
    }
    else { 
      msg $nick ADD: You aren't my owner, or otherwise you aren't an admin or user
    }
  }


Joined: Aug 2004
Posts: 7,168
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,168
Code:
ON 1:TEXT:*:#:{
  if ($gettok(%adminstatus,%nick,32) == On) {
    if $1 == .totalscripts {
      msg $chan TOTAL SCRIPTS: $script(0)
    }
  }
}

K
KageNoOni
KageNoOni
K
var %nick = $findtok(%admin,$nick,32)
That line was used to give %nick a value. Because /var was used, the variable is local, and is deleted after any actions with in the login part of the script. With out adding that line, %nick will return as $null. $gettok(%adminstatus,$null,32) will result in an error message as a result.

Code:
On 1:TEXT:*:#:{
  var %nick = $findtok(%admin,$nick,32)
  if ($gettok(%adminstatus,%nick,32) == On) {
    if $1 == .totalscripts {
      msg $chan TOTAL SCRIPTS: $script(0)
    }
  }
}

Last edited by KageNoOni; 21/08/09 04:56 AM.
D
DuXxXieJ
DuXxXieJ
D
And if I'm not logged in, how do I add an else that it msg's me that I'm not logged in?

EDIT: Both of them don't work frown


Last edited by DuXxXieJ; 21/08/09 11:01 AM.
Joined: Oct 2003
Posts: 3,641
A
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,641
How do you add an else?

Why, with an else, of course

/help /if should show you how if-then-else is structured, of course you have plenty of examples in the very code you pasted.

S
s00p
s00p
S
The second code pasted may appear to "not work" because it will only trigger for channel messages. If the rest of your code works, then that will work. If your ".login" displays "You are already logged in", then you need to think about initialising %adminstatus because it might evaluate (return isn't quite the right word) to $null. In this case you're also likely to recieve "You aren't logged in" when you try to ".logout".

edit: read /help moar, and manually iterate over each branch putting "echo" code around the place if you want to debug it quickly.

Last edited by s00p; 03/09/09 11:25 AM.

Link Copied to Clipboard