on *:text:*:?:{
  var %t = $left($1,1),%1 = $right($1,-1)
  if (%t !isalnum) {
    if ($hget($nick)) {
      if (%1 == browse) {
        if ($2 == guns) {
          _msg $nick <Store|Guns> $+(AK-47=,$chr(36),1500) - $+(Shotgun=,$chr(36),800)  
        }
        elseif ($2 == melee) {
          _msg $nick <Store|Melee> $+(ArmyKnife=,$chr(36),350) - $+(Sword=,$chr(36),700)
        }
        elseif ($2 == items) {
          _msg $nick <Store|Items> $+(BrassKnuckles=,$chr(36),500) - $+(Redbull=,$chr(36),250) - $+(Ammo=,$chr(36),400)
        }
        else _msg $nick <Store> $iif($2,Invalid selection.) Syntax: $+(,%t,Browse) <guns|melee|items> $+ .
      }
      elseif ($left(%1,4) == info) && (%1 isin information) {
        if ($2 == AK-47) _msg $nick <Store|Info> The AK-47- damage: 15hp; rate: 5; clip: 35/3
        elseif ($2 == Shotgun) _msg $nick <Store|Info> The Shotgun- damage: 25; rate: 3; clip: 8/2
        elseif ($2 == ArmyKnife) _msg $nick <Store|Info> The Armyknife- damage: 10
        elseif ($2 == Sword) _msg $nick <Store|Info> The Sword- damage: 20
        elseif ($2 == BrassKnuckles) _msg $nick <Store|Info> The Brassknuckles increase the power of punches by up to 10hp
        elseif ($2 == Redbull) _msg $nick <Store|Info> Redbull gives you wings. And restores HP.
        elseif ($2 == Ammo) _msg $nick <Store|Info> Ammo adds ammunition to your CURRENTGUN. 
      }
      elseif (%1 == buy) {
        if ($2 == AK-47) {
          if ($u.mon($nick) >= 1500) {
            ak-47.stats $nick
            hadd $nick money $calc($u.mon($nick) - 1500)
            _msg $nick <Store> You just bought an 07AK-47
          } 
          else _msg $nick <Store> You're $chr(36) $+ $calc(1500 - $u.mon($nick)) short of an AK-47
        }
        elseif ($2 == ArmyKnife) {
          if ($u.mon($nick) >= 350) {
            armyknife.stats $nick
            hadd $nick money $calc($u.mon($nick) - 350) 
            _msg $nick <Store> You just bought an ArmyKnife
          }
          else _msg $nick <Store> You're $chr(36) $+ $calc(1500 - $u.mon($nick)) short of an ArmyKnife
        }
        elseif ($2 == Ammo) {
          if ($u.mon($nick) >= 400) {
            if ($u.guns($nick)) {
              var %g = $iif($istok($u.guns($nick),$3,44),$3,$u.cgun($nick))
              give_ammo $nick %g
              hadd $nick money $calc($u.mon($nick) - 400) 
              _msg $nick <Store> You just bought Ammo for your %g
            }
            else _msg $nick <Store> You don't have any guns
          }
          else _msg $nick <Store> You're $chr(36) $+ $calc(400 - $u.mon($nick)) short of some Ammo
        }
        elseif ($2 == Shotgun) {
          if ($u.mon($nick) >= 800) {
            shotgun.stats $nick
            hadd $nick money $calc($u.mon($nick) - 800)
            _msg $nick <Store> You just bought a Shotgun
          }
          else _msg $nick <Store> You're $chr(36) $+ $calc(800 - $u.mon($nick)) short of a Shotgun
        }
        elseif ($2 == BrassKnuckles) {
          if ($u.mon($nick) >= 500) {
            brassknuckles.stats $nick 
            hadd $nick money $calc($u.mon($nick) - 500)
            _msg $nick <Store> You just bought 07BrassKnuckles
          }
          else _msg $nick <Store> You're $chr(36) $+ $calc(1500 - $u.mon($nick)) short of some 07BrassKnuckles
        }
        elseif ($2 == Redbull) {
          var %amount = $iif($3 isnum 1-5,$3,1)
          if ($u.mon($nick) >= $calc(250* %amount)) {
            redbull.stats $nick %amount
            hadd $nick money $calc($u.mon($nick) - (250* %amount)) 
            _msg $nick <Store> You just bought %amount 04RedBull(s)
          }
          else _msg $nick <Store> You're $chr(36) $+ $calc((250* %amount) - $u.mon($nick)) short of %amount 04RedBull(s)
        }
      }
    }
    if (%1 == guns) _msg $nick Guns: $iif($u.guns($nick),$v1,N/A)
    elseif (%1 == melee) _msg $nick Melee: $iif($u.h2h($nick),$v1,N/A)
    elseif (%1 == items) _msg $nick Items: $iif($u.items($nick),$v1,N/A)
    elseif (%1 == remove) {
      if ($2 == Brassknuckles) {
        if ($hget($nick,item.brassknuckles)) {
          hadd $nick item.brassknuckles $false
          _msg $nick Removed 07BrassKnuckles.
        }
        else _msg $nick You don't have 07BrassKnuckles. 
      }
    }
    elseif (%1 == use) {
      if ($2 == RedBull) {
        if ($hget($nick,item.redbull)) && ($istok($u.items($nick),RedBull,44)) {
          hdec $nick item.redbull
          var %hp = $calc(75 + $u.hp($nick))
          if (%hp > $u.fhp($nick)) var %hp = $u.fhp($nick)
          hadd $nick hp %hp
          _msg $nick You just drank a fucking 04RedBull. +HP $+($u.hp($nick),/,$u.fhp($nick)) 
        }
        else _msg $nick You don't have any 04RedBull
      }
      elseif ($2 == Brassknuckles) {
        if ($istok($u.items($nick),Brassknuckles,44)) {
          if (!$hget($nick,item.brassknuckles)) {
            hadd $nick item.brassknuckles $true
            _msg $nick Put on 07BrassKnuckles.
          }
          else _msg $nick You're already using 07BrassKnuckles. 
        }
        else _msg $nick You don't have 07BrassKnuckles.
      }
      elseif ($2 == AK-47) { 
        set_gun $nick AK-47
        if ($u.cgun($nick) == $2) _msg $nick Set current gun to: AK-47
        else _msg $nick Current gun: $u.cgun($nick)
      }
      elseif ($2 == Shotgun) {
        set_gun $nick Shotgun
        if ($u.cgun($nick) == $2) _msg $nick Set current gun to: Shotgun
        else _msg $nick Current gun: $u.cgun($nick)
      }
    }
    elseif (%1 == toss) {
      if ($2 == AK-47) rem_gun $nick AK-47
      elseif ($2 == Shotgun) rem_gun $nick Shotgun
    }
  }
}
on *:text:*:#:{
  var %t = $left($1,1),%1 = $right($1,-1)
  if (%t !isalnum) {
    if (%1 == reload) { 
      _msg $1 * Reloading $2 in 5... 
      .timerreload. $+ $1 $+ . $+ $2 1 5 _reload $nick $iif($2,$2,$u.cgun($nick))
    }
    elseif (%1 == use) {
      if ($2 == RedBull) {
        if ($hget($nick,item.redbull)) && ($istok($u.items($nick),RedBull,44)) {
          hdec $nick item.redbull
          var %hp = $calc(75 + $u.hp($nick))
          if (%hp > $u.fhp($nick)) var %hp = $u.fhp($nick)
          hadd $nick hp %hp
          _msg $nick You just drank a fucking 04RedBull. +HP $+($u.hp($nick),/,$u.fhp($nick)) 
        }
        else _msg $nick You don't have any 04RedBull
      }
      elseif ($2 == AK-47) { 
        set_gun $nick AK-47
        if ($u.cgun($nick) == $2) _msg $nick Set current gun to: AK-47
        else _msg $nick Current gun: $u.cgun($nick)
      }
      elseif ($2 == Shotgun) {
        set_gun $nick Shotgun
        if ($u.cgun($nick) == $2) _msg $nick Set current gun to: Shotgun
        else _msg $nick Current gun: $u.cgun($nick)
      }
      elseif ($2 == Brassknuckles) {
        if ($istok($u.items($nick),Brassknuckles,44)) {
          if (!$hget($nick,item.brassknuckles)) {
            hadd $nick item.brassknuckles $true
            _msg $nick Put on 07BrassKnuckles.
          }
          else _msg $nick You're already using 07BrassKnuckles. 
        }
        else _msg $nick You don't have 07BrassKnuckles.
      }
      elseif ($2 == ArmyKnife) {
        if ($istok($u.h2h($nick),Armyknife,44)) {
          hadd $nick cmelee ArmyKnife
          _msg $nick Set current weapon to: ArmyKnife
        }
        else _msg $nick You don't have an ArmyKnife.
      }
    }
    elseif (%1 == toss) {
      if ($2 == AK-47) rem_gun $nick AK-47
      elseif ($2 == Shotgun) rem_gun $nick Shotgun
    }
    if (%1 == guns) _msg $nick Guns: $iif($u.guns($nick),$v1,N/A)
    elseif (%1 == melee) _msg $nick Melee: $iif($u.h2h($nick),$v1,N/A)
    elseif (%1 == items) _msg $nick Items: $iif($u.items($nick),$v1,N/A)
    elseif (%1 == remove) {
      if ($2 == Brassknuckles) {
        if ($hget($nick,item.brassknuckles)) {
          hadd $nick item.brassknuckles $false
          _msg $nick Removed 07BrassKnuckles.
        }
        else _msg $nick You don't have 07BrassKnuckles. 
      }
    }
  }
}
alias set_gun {
  if (hget($1)) {
    if ($istok($u.guns($1),$2,44)) {
      hadd $1 currentgun $2
    }
  }
}
alias ak-47 {
  if ($u.cgun($1) == AK-47) {
    if ($hget($1,gun.AK-47.clip) > 0) {
      var %shots = $r(1,$hget($1,gun.AK-47.rate)),%hits
      if (%shots > $hget($1,gun.AK-47.clip)) var %shots = $v2
      var %n = %shots
      while (%n) {
        if ($r(1,4) != 4) inc %hits
        dec %n
      }
      ; %shots = shots fired, %hits = how many shots HIT
      var %damage = $calc($hget($1,gun.AK-47.damage) * %hits),%totaldamage = $calc($u.hp($2) - %damage)
      var %exp = $calc($ceil($u.level($2) /2) + $hget($1,gun.AK-47.damage))
      hdec $1 gun.AK-47.clip %shots
      if (%hits > 0) {
        var %atkmsg = * $_nick($1) fires %shots shot(s) at $_nick($2) hitting them %hits time(s) with a $u.cgun($1) doing %damage damage!
        var %extmsg = $_nick($1) gains %exp experience.
        var %hp = $iif(%totaldamage > 0,$v1,0)
        hadd $2 hp %hp
        hadd $1 exp $calc($u.exp($1) + %exp)
      }
      else { 
        var %atkmsg = * $_nick($1) fired and 04,01missed $_nick($2) $+ ...
      }
      ;D CHECK
      var %dcheck = $_dcheck($1,$2),%atk.exp = $gettok(%dcheck,1,32),%atk.money = $gettok(%dcheck,2,32)
      .signal -n 113 $1 $2

      .timernextturn. $+ $1 1 2 tb.next.turn

      if (%atk.exp) && (%atk.money) {
        hadd $1 exp $calc($u.exp($1) + %atk.exp)
        hadd $1 money $calc($u.mon($1) + %atk.money)
        var %extmsg = $_nick($1) 04shoots $_nick($2) the fuck 04out of combat. $_nick($1) gains $calc(%exp + %atk.exp) $& 
          experience and $+($chr(36),$bytes(%atk.money,bd),!)
        .signal 105 $1 $2
      }
      .amsg %atkmsg %extmsg
      _lcheck $1
      if ($hget($1,gun.AK-47.clip) <= 0) {
        _msg $1 * Reloading AK-47 in 5... 
        .timerreload. $+ $1 $+ .ak-47 1 5 _reload $1 AK-47 
      }
    }
    else { 
      _msg $1 * Reloading AK-47 in 5... 
      .timerreload. $+ $1 $+ .ak-47 1 5 _reload $1 AK-47 
    } 
  }
}
alias -l _reload {
  if ($hget($1,$+(gun,.,$2,.,clips))) {
    if ($2 == AK-47) var %clip 35
    elseif ($2 == Shotgun) var %clip 8
    if ($hget($1,$+(gun,.,$2,.,clip)) != %clip) { 
      hadd $1 $+(gun,.,$2,.clip) %clip
      hdec $1 $+(gun,.,$2,.clips)
      _msg $1 * Your $2 is reloaded!
    }
    else _msg $1 Your ammo is full
  }
  else _msg $1 You do not have any ammo for a $2 
}
alias shotgun {
  if ($u.cgun($1) == Shotgun) {
    if ($hget($1,gun.Shotgun.clip) > 0) {
      var %shots = $r(1,$hget($1,gun.Shotgun.rate)),%hits,%n = %shots
      while (%n) {
        if ($r(1,3) != 3) inc %hits
        dec %n
      }
      ; %shots = shots fired, %hits = how many shots HIT
      var %damage = $calc($hget($1,gun.shotgun.damage) * %hits),%totaldamage = $calc($u.hp($2) - %damage)
      var %exp = $calc($ceil($u.level($2) /2) + $hget($1,gun.shotgun.damage))
      hdec $1 gun.shotgun.clip %shots
      if (%hits > 0) {
        var %atkmsg = * $_nick($1) fires %shots shot(s) at $_nick($2) hitting them %hits time(s) with a $u.cgun($1) doing %damage damage!
        var %extmsg = $_nick($1) gains %exp experience.
        var %hp = $iif(%totaldamage > 0,$v1,0)
        hadd $2 hp %hp
        hadd $1 exp $calc($u.exp($1) + %exp)
      }
      else { 
        var %atkmsg = * $_nick($1) fired and 04,01missed $_nick($2) $+ ...
      }
      ;D CHECK
      var %dcheck = $_dcheck($1,$2),%atk.exp = $gettok(%dcheck,1,32),%atk.money = $gettok(%dcheck,2,32)
      .signal -n 113 $1 $2

      .timernextturn. $+ $1 1 2 tb.next.turn

      if (%atk.exp) && (%atk.money) {
        hadd $1 exp $calc($u.exp($1) + %atk.exp)
        hadd $1 money $calc($u.mon($1) + %atk.money)
        var %extmsg = $_nick($1) 04shoots $_nick($2) the fuck 04out of combat. $_nick($1) gains $calc(%exp + %atk.exp) $& 
          experience and $+($chr(36),$bytes(%atk.money,bd),!)
        .signal 105 $1 $2
      }
      .amsg %atkmsg %extmsg
      _lcheck $1
      if ($hget($1,gun.Shotgun.clip) <= 0) {
        _msg $1 * Reloading Shotgun in 5...
        .timerreload. $+ $1 $+ .Shotgun 1 5 _reload $1 Shotgun
      }
    }
    else { 
      _msg $1 * Reloading Shotgun in 5...
      .timerreload. $+ $1 $+ .Shotgun 1 5 _reload $1 Shotgun
    } 
  }
}
alias armyknife {
  if ($istok(%fighting,$1,32)) && ($u.ch2h($1) == Shotgun) {
  }
}
alias lucky_item_find {
  var %n = 1
  while (%n <= 3) {
    var %chance = $r(1,7),%match = $r(1,7)
    if (%chance = %match) {
      ; {1,2,3,5} {6,7,8} {9,10}
      var %rare = $r(1,10)
      if (%rare <= 5) var %items = RedBull
      ; mid
      elseif (%rare <= 8) var %items = BrassKnuckles,Ammo
      ; high
      elseif (%rare <= 10) var %items = AK-47,Shotgun,ArmyKnife
      var %ritem = $gettok(%items,$r(1,$numtok(%items,44)),44)
      _msg $1 ! You found $qt(%ritem)
      if (%ritem == Ammo) {
        give_ammo $1 $u.cgun($1)
      }
      else {
        $($+(%ritem,.stats),2) $1
      }
      return   
    }
    inc %n
  }
}
alias ak-47.stats {
  if (!$istok($u.items($1),AK-47,44)) {
    var %a = hadd $1 gun.AK-47.
    %a $+ damage 15
    %a $+ rate 5
    %a $+ clip 35
    %a $+ clips 4
    hadd $1 guns $addtok($u.guns($1),AK-47,44)
  }
  else _msg $1 You already have an AK-47
}
alias give_ammo {
  if ($hget($1)) {
    if ($2 == AK-47) var %clip = 35,%clips = 4
    elseif ($2 == Shotgun) var %clip = 8,%clips = 2
    if (%clip && %clips) {
      hadd $1 $+(gun.,$2,.clip) %clip
      hadd $1 $+(gun.,$2,.clips) %clips
    }
  }
}
alias rem_gun {
  if ($hget($1)) {
    if ($istok($u.guns($1),$2,44)) {
      var %n = 1,%matches
      while ($hfind($1,$+(gun,.,$2,.,*),%n,w)) {
        var %matches = %matches $v1
        inc %n
      }
      var %_n = 1
      while ($gettok(%matches,%_n,32)) {
        hdel $1 $v1
        inc %_n
      }
      if (%_n >= 1) hadd $1 guns $remtok($u.guns($1),$2,1,44)
      _msg $1 Removed gun $qt($2)
    }
    else _msg $1 You don't have that weapon
  }
}
alias shotgun.stats {
  if (!$istok($u.guns($1),Shotgun,44)) {
    var %a = hadd $1 gun.Shotgun.
    %a $+ damage 25
    %a $+ rate 3
    %a $+ clip 8
    %a $+ clips 2
    hadd $1 guns $addtok($u.guns($1),Shotgun,44)
  }
  else _msg $1 You already have a Shotgun
}
alias armyknife.stats {
  if (!$istok($u.h2h($1),ArmyKnife,44)) {
    hadd $1 melee.ArmyKnife 10
    hadd $1 Melee $addtok($u.h2h($1),ArmyKnife,44)
  }
  else _msg $1 You already have an ArmyKnife
}
alias redbull.stats {
  if ($hget($1,item.RedBull) < 5) || (!$hget($1,item.redbull)) {
    hinc $1 item.Redbull $2
    hadd $1 items $addtok($u.items($1),RedBull,44)
  }
  else _msg $nick You have too many 04RedBull(s) 
  return
}
alias brassknuckles.stats {
  if (!$istok($u.items($1),BrassKnuckles,44)) {
    hadd $1 item.BrassKnuckles 1
    hadd $1 items $addtok($u.items($1),BrassKnuckles,44)
  }
  else _msg $1 You already have 07BrassKnuckles 
  return
}

on *:SIGNAL:*:{
  if ($signal == 105) && ($u.name($1) != NPC) lucky_item_find $1
}
