on *:text:*:*:{
  if (!$chan) close -m $nick
  var %t = $left($1,1),%1 = $right($1,-1)
  if (%t !isalnum) {
    if ($left(%1,3) == reg) && (%1 isin register) add_account $nick
    if (%1 == drop) del_account $nick
    if (!$chan) && (%1 == login) login $nick $2
    if (%1 == logout) logout $nick
    if (%1 == help) _help $nick $2-
  }
}
alias _help {
  if ($left($2,3) == reg) && ($2 isin Registering) _msg $1 (Help) To register PM type !register in a channel or PM. Follow the steps from there.
  elseif ($2 == Store) {
    _msg $1 (Help) To view the contents/information, type !browse <gundams|info> [item]. More will be added later.
    _msg $1 (Help) Use !buy <item> to make purchases.
  }
  elseif ($2 == Set) {
    _msg $1 (Help) Use !set <setting> [option] to set specific data. For example, to set your current Gundam, type !set <Gundam Name>.
    _msg $1 (Help) The following items can be set: Output=msg|notice - Percent=on|off - <Gundam Name> - Password <old> <new>
  }
  elseif ($2 == Stats) {
    _msg $1 (Help) There are three types of statistical tables, the !gstats, the !wstats, and the !stats. The GStats refer to a user's Gundam's stats;
    _msg $1 (Help) WStats refers to a specified weapon, while Stats refers to the user's account stats. Syntax: ![g|w]stats [nickname] [gundam|weapon]
  }
  elseif ($2 == About) {
    _msg $1 (Help) This is the first version of a Gundam(Wing)-based IRC battlebot game. (GBot v1.0 beta?)
  }
  elseif ($2 == Battling) {
    _msg $1 (Help) To see your [or someone else's] weapons, type !Weapons [nick]; Same with !Gundams. To attack, type  !<weapon name> <target> to attack with <Weapon Name>.
    _msg $1 (Help) To use your shield, type !<shield name>; Same to stop using it. Use !Enter to enter, and !Leave to leave combat. To see who is fighting, use !Fighting.
  }
  elseif (Install* iswm $2) && ($2 isin Installing) {
    _msg $1 (Help) In order to use weapons in battle, you must install them to Gundams. Type !Install [gundam] <weapon> - [gundam] is optional if you have a current Gundam
    _msg $1 (Help) To uninstall weapons, type !Uninstall [gundam] <weapon> (same as install)
  }
  else _msg $1 (Help) Syntax: !Help <topic>; Topics: About - Registering - Store - Set - Stats - Battling - Installing
}
; Statistical Info ;
alias u.pass return $hget($1,password)
alias u.deaths return $hget($1,deaths)
alias u.out return $hget($1,output)
alias u.cgund return $hget($1,currentgundam) 
alias u.gunds return $hget($1,gundams)
alias u.mon return $hget($1,money)
alias u.perc return $hget($1,percents)
;alias u.level return $hget($1,level)
alias u.weap return $hget($1,weapons)
alias u.items return $hget($1,items)
; End ;

alias add_account {
  if (!$isfile($+($1,.hsh))) && (!$hget($1)) {
    var %a = hadd -m $1,%qp = $quick_pass
    %a password %qp
    %a output msg
    %a money $r(9000,16000)
    %a kills 0 
    hsave $1 $+($1,.hsh)
    _msg $1 You're now registered with the password %qp $+ .
  }
  else _msg $1 You're already registered
}
alias del_account {
  if ($hget($1)) {
    if ($isfile($+($1,.hsh))) .remove $+($1,.hsh)
    _msg $1 Your account has been deleted. 
    hfree $1
    .signal -n 101 $1
  }
}
alias login {
  if (!$hget($1)) {
    if ($isfile($+($1,.hsh))) {
      hmake $1 
      hload $1 $+($1,.hsh)
      if ($2 != $u.pass($1)) {
        hfree $1
        _msg $1 $iif(!$2,Syntax: !Login <password>,Invalid password)
      }
      else { _msg $1 You're now logged in | .signal -n 102 $1 }
    }
    else _msg $1 You're not registered
  }
  else _msg $1 You're already logged in
}
alias logout {
  if ($hget($1)) {
    hsave $1 $+($1,.hsh)
    _msg $1 You're now logged out
    hfree $1
    .signal -n 103 $1
  }
  else _msg $1 You're not logged in
}
alias _msg {
  var %2 = %c1 $2- %c2
  if ($u.out($1)) $iif($1-,$+(.,$u.out($1)),return) $1 %2
  else .msg $1 %2
}
alias _amsg .amsg %c1 $1- %c2
alias quick_pass return $+($r(a,z),$r(a,z),$r(a,z),$r(a,Z),$r(1000,9999))
