;####################; 
;#  DM Script v1.0  #; 
;#     By  Kol      #; 
;####################; 

alias dmc1 return $+(,$iif($dms(c1),$v1,14),$$1-) 
alias dmc2 return $+(,$iif($dms(c2),$v1,10),$$1-) 
on *:START: { 
  hmake dm 1 
  hmake dma 1
  hmake dme 1
  hmake dmd 1
  hmake dmw 1
  if ($read(dm.txt)) hload dm dm.txt 
  else dmset
  if ($read(dma.txt)) hload dma dma.txt 
  if ($read(dme.txt)) hload dme dme.txt
  if ($read(dmd.txt)) hload dmd dmd.txt
  if ($read(dmw.txt)) hload dmw dmw.txt
  else dmwupd
  if ($dms(timercheck)) { updatedm | .timercdmcheck 0 1200 updatedm }
} 
alias hpbar { 
  var %g $round($calc($$1 /5),-1), %r $calc(20 - %g), %x 1 
  var %t $right(0 $+ $1,-1) 
  while (%x < 21) { 
    var %c $iif(%x isnum 1- $+ %g,09,04) 
    if (%x isnum 10-11) { var %m $+(,01,$chr(44),%c,$mid(%t,$calc(%x -9),1)) } 
    else { var %m $+(,%c,$chr(44),%c,$chr(160)) } 
    var %re %re $+ %m 
    inc %x 
  } 
  return %re $+  
} 
on $*:TEXT:/^[!.@]dmset(tings)?\s.+/Si:#: { 
  if ($wildsite = $address($me,2)) || ($admin($nick) && $dms(set)) && ((!$istok(set chans,$2,32))) { 
    if ($istok(sharks timeout timer barrage,$2,32) && $3 isnum) { 
      dms $2 $$3 
      notice $nick [DM] DM setting $2 is now $3- 
      hsave dm dm.txt 
      var %set .
    } 
    elseif ($istok(c1 c2,$2,32) && $3 isnum 0-15) { 
      dms $2 $right(0 $+ $$3,2) 
      notice $nick [DM] $2 is now color $dms($2) 
      hsave dm dm.txt 
      var %set .
    } 
    elseif ($istok(timeout[st] hpbar timer[st],$2,32) && $istok($true $false on off,$3,32)) { 
      dms $2 $iif($istok($true on,$3,32),$true,$false) 
      notice $nick [DM] DM setting $2 is now $3 
      hsave dm dm.txt 
      var %set .
    } 
    else {
      notice $nick [DM] Incorrect syntax. Type !dmcmds and scroll down on the webpage for the admin commands.
      var %set .
    }
  } 
  if ($wildsite = $address($me,2) && !%set) {
    if ($2 = set && $istok(admin owner,$3,32)) { 
      dms $2 $iif($3 = admin,$true,$false) 
      notice $nick [DM] $iif($3 = owner,Only owners can set settings now.,Admins and owners can set settings now.) 
      hsave dm dm.txt 
      var %set .
    }
    elseif ($2 = chans && $istok(enable disable dis,$3,32)) {
      if ($dms(chans)) { dms chans $true }
      if ($dms(chans) = $true && $3 = enable) { notice $nick [DM] All channels are already set to enable. }
      elseif ($dms(chans) = $false && $3 = enable) {
        dms chans $true
        notice $nick [DM] All chans will now be enabled. Use .dischan #chan to halt DMs for a channel. 
        hsave dm dm.txt 
        var %set .
      }
      if ($dms(chans) = $false && dis* iswm $3) { notice $nick [DM] All channels are already set to disable. }
      elseif ($dms(chans) = $true && dis* iswm $3) {
        dms chans $false
        notice $nick [DM] All chans will now be disabled. Use .enchan to allow the script to be used in the channel(s). 
        hsave dm dm.txt 
      }
      var %set .
    }
    elseif (!%set) notice $nick [DM] Incorrect syntax. Type !dmcmds and scroll down on the webpage for the admin commands.
  } 
  elseif ($wildsite != $address($me,2) || !$admin($nick) && $dms(set)) && (!%set) { notice $nick [DM] You do not have sufficient access to set DM settings. } 
} 
alias dme $iif($isid,return $hget(dme,$1-),hadd -m dme $$1-) 
alias dmd $iif($isid,return $hget(dmd,$1-),hadd -m dmd $$1-) 
on $*:TEXT:/^[!.@]en(able)?chan( -r)? \S+$/Si:#: {
  if (!$dms(chans)) && (($wildsite = $address($me,2)) || ($admin($nick) && $dms(set))) {
    if (!$regml(1)) {
      if (!$dme(#$2)) {
        dme #$2 $true
        hsave dme dme.txt
        notice $nick [DM] DMs will now be able to be played in #$2 $+ .
      }
      elseif ($dme(#$2)) { notice $nick [DM] People can already DM in #$2 }
    }
    elseif ($regml(1)) {
      if ($dme(#$3)) {
        hdel dme #$3
        hsave dme dme.txt
        notice $nick [DM] #$3 removed from the enable list.
      }
      elseif (!$dme(#$3)) { notice $nick [DM] #$3 is not on the enable list. }
    }
  }
  elseif ($dms(chans)) { notice $nick [DM] Channels are currently set to Enable, that means that you can DM in all of them already. Type .dischan #chan to disable a channel. }
  elseif ($wildsite != $address($me,2)) || (!$admin($nick) && !$dms(set)) { notice $nick [DM] You do not have sufficient access to enable channels. }
}
on $*:TEXT:/^[!.@]dis(able)?chan( -r)? \S+$/Si:#: {
  if ($dms(chans)) && (($wildsite = $address($me,2)) || ($admin($nick) && $dms(set))) {
    if (!$regml(1)) {
      if (!$dmd(#$2)) {
        dmd #$2 $true
        hsave dmd dmd.txt
        notice $nick [DM] DMs will not be played in #$2 $+ .
      }
      elseif ($dmd(#$2)) { notice $nick [DM] #$2 is already disabled. }
    }
    elseif ($regml(1)) {
      if ($dmd(#$3)) {
        hdel dmd #$3
        hsave dmd dmd.txt
        notice $nick [DM] #$3 removed from the disable list.
      }
      elseif (!$dmd(#$3)) { notice $nick [DM] #$3 is not on the disable list. }
    }
  }
  elseif (!$dms(chans)) { notice $nick [DM] Channels are currently set to Disable, that means that you can't DM in any channels except for the ones enabled with .enchan #chan. Type .dmset chans enable to use this command. }
  elseif (($wildsite != $address($me,2))) || ((!$admin($nick) && !$dms(set))) { notice $nick [DM] You do not have sufficient access to disable channels. }
}
on $*:TEXT:/^[!.@]c(han(nel)?)?list (en(abled?)?|dis(abled?)?)$/Si:#: {
  if (($wildsite = $address($me,2)) || ($admin($nick) && $dms(set))) {
    var %c $iif(en* iswm $2,Enable,Disable), %x 1
    if (%c = enable) {
      if ($hget(dme,0).item = 0) {
        notice $nick [DM] There are not any channels in the enable list
        halt
      }
      notice $nick [DM] List of channels that are enabled.
      while ($hget(dme,%x).item) {
        notice $nick [DM] %x $+ : $v1
        inc %x
      }
    }
    elseif (%c = disable) {
      if ($hget(dmd,0).item = 0) {
        notice $nick [DM] There are not any channels in the disabled list
        halt
      }
      notice $nick [DM] List of channels that are disabled.
      while ($hget(dmd,%x).item) {
        notice $nick [DM] %x $+ : $v1
        inc %x
      }
    }
  }
  else notice $nick [DM] You do not have sufficient access to see the $iif(en* iswm $2,enabled,disabled) channel list. 
}
alias dms $iif($isid,return $hget(dm,$1-),hadd -m dm $$1-) 
alias dm $iif($isid,return $hget(dm $+ #,$1-),hadd -m dm $+ # $$1-) 
alias dm1 $iif($isid,return $hget(dm1 $+ #,$1-),hadd -m dm1 $+ # $$1-) 
alias dm2 $iif($isid,return $hget(dm2 $+ #,$1-),hadd -m dm2 $+ # $$1-) 
alias dmt { 
  if ($isid) return $hget($+(dm,$dm(t),#),$1-) 
  else { 
    if ($1 = -d) hdec $+(dm,$dm(t),#) $2- 
    if ($1 = -i) hinc $+(dm,$dm(t),#) $2- 
    else hadd -m $+(dm,$dm(t),#) $1- 
  } 
} 
alias dmo { 
  if ($isid) return $hget($+(dm,$dm(o),#),$1-) 
  else { 
    if ($1 = -d) hdec $+(dm,$dm(o),#) $2- 
    if ($1 = -i) hinc $+(dm,$dm(o),#) $2- 
    else hadd -m $+(dm,$dm(o),#) $1- 
  } 
} 
alias dma { 
  hadd -m dm1 $+ # $$1- 
  hadd -m dm2 $+ # $$1- 
}
on $*:TEXT:/^[!.]d(eath)?m(atch)?c(om)?m(an)?ds?$/Si:*: { 
  msg $nick $dmc1([DM] A list of commands can be found at:) $dmc2(http://forum.swiftirc.net/viewtopic.php?p=112076#112076) 
  msg $nick $dmc1([DM] Scroll lower for) $dmc2(Admin) $dmc1(commands.) 
  msg $nick $dmc1([DM] If you can't see the URL $+ $chr(44) Type:) $dmc2(/mode $nick -f) $dmc1(and type) $dmc2($1) $dmc1(again.) 
} 
alias updatehs { filter -ac DMs.txt DMo.txt sort } 
alias sort { 
  if ($token($1,1,32) > $token($2,1,32)) return -1 
  elseif ($v1 = $v2) return 0 
  return 1 
} 
alias score { 
  if ($read(dms.txt,w,* $1)) { write -l $+ $readn dms.txt $calc(1+ $token($v1,1,32)) $token($v1,2,32) $1 } 
  else { write dms.txt 1 0 $1 } 
  if ($read(dms.txt,w,* $2)) { write -l $+ $readn dms.txt $token($v1,1,32) $calc(1+ $token($v1,2,32)) $2 } 
  else { write dms.txt 0 1 $2 } 
  msg $3 $dmc1([DM]) $dmc2(Wins) $+ $dmc1(: $1) $dmc2($wins($1)) $dmc1($chr(44) $2) $dmc2($wins($2)) $dmc1($chr(124)) $dmc2(Losses) $+ $dmc1(: $1) $dmc2($loss($1)) $dmc1($chr(44) $2) $dmc2($loss($2)) 
  updatehs 
} 
on $*:TEXT:/^[!.@](dm ?)?top([3-9]|1[0-5]) ?(win(ner)?s?)?$/Si:#: { 
  var %n $iif($regml(1) isnum,$v1,$regml(2)) 
  var %x 1 
  while ($read(dmo.txt,%x) && %x <= %n) { 
    var %read $read(dmo.txt,%x) 
    var %msg %msg $dmc1($chr(124)) $dmc2(%x) $+ $dmc1(: $token(%read,3,32) [) $+ $dmc2($token(%read,1,32))) $+ $dmc1($chr(93)) 
    inc %x 
  } 
  $iif($left($1,1) = @,msg #,notice $nick) $dmc1([DM] Top %x) $dmc2(Wins) 
  $iif($left($1,1) = @,msg #,notice $nick) $token(%msg,2-,32) 
} 
on $*:TEXT:/^[!.@](rank|score) \S+$/Si:#: { 
  var %way $iif($left($1,1) = @,msg #,notice $nick) 
  if ($read(dmo.txt,w,* $2)) { 
    tokenize 32 $v1 
    var %wpc $round($calc(($1 / ($1 + $2))* 100),3) 
    var %lpc $calc(100 - %wpc) 
    %way $dmc1([DM] Score for) $dmc2($3) $+ $dmc1(: Rank:) $dmc2($readn) $dmc1(Wins-) $dmc2($1) $dmc1(Losses-) $dmc2($2) $dmc1($chr(124) Win - Loss Perecentage:) $dmc2(%wpc $+ %) $dmc1(-) $dmc2(%lpc $+ %) 
  } 
  else %way $dmc1([DM]) $dmc2($2) $dmc1(not found in the DM highscores.) 
} 
alias wins return $iif($token($read(dms.txt,w,* $$1),1,32) != $null,$v1,$false)
alias loss return $iif($token($read(dms.txt,w,* $$1),2,32) != $null,$v1,$false)
on $*:TEXT:/^[!.@](start)?(d(eath)?m(atch)?|fight)$/Si:#: { 
  if (!$dmd(#) && $dms(chans)) || ($dme(#) && !$dms(chans)) {     if (!$dm(open)) {
      dm1 name $nick 
      dm open $true 
      msg # $dmc1([DM]) $dmc2($nick) $dmc1(has initiated a DM. Type) $dmc2($1) $iif($dms(timer[st]),$dmc1(in the next) $dmc2($iif($dms(timer),$v1,30)) $dmc1(seconds to accept the challenge.),$dmc1(to accept the challenge))
      .timer 1 1 msg # $dmc1([DM] Type) $dmc2(!dmcmds) $dmc1(for a list of DM commands.) 
      if ($dms(timer[st)) .timerdmo $+ # 1 $iif($dms(timer),$v1,30) checkdm # 
    } 
    elseif ($dm(open) && !$dm2(name) && $wildsite != $address($dm1(name),2)) { 
      msg # $dmc1([DM]) $dmc2($nick) $dmc1(has accepted) $dmc2($dm1(name)) $+ $dmc1('s challenge.) 
      dm2 name $nick 
      dma hp 99 
      dma spec 100 
      dma sharks $iif($dms(sharks),$v1,5) 
      dma barrages $iif($dms(barrage),$v1,6) 
      dma frozen $false 
      dm t $r(1,2) 
      dm o $iif($dm(t) = 1,2,1) 
      .timerdmo $+ # off 
      .timer 1 1 msg # $dmc1([DM] It is now) $dmc2($dmt(name)) $+ $dmc1('s turn.) 
      if ($dms(timeout[st])) .timertimeout $+ # 1 $iif($dms(timeout),$v1,60) timeout # 
    } 
    elseif ($wildsite = $address($dm1(name),2)) { msg # $dmc1([DM]) $dmc2($nick) $dmc1(wants to battle themself. Smart $+ $chr(44) eh?) } 
    elseif ($dm(open) && $dm2(name)) { notice $nick [DM] Sorry, there is already a DM going on between $dm1(name) and $dm2(name) $+ . } 
  } 
}
on $*:TEXT:/^[!.@](s(top)?(d(eath)?m(atch)?|fight)|d(eath)?m(atch)?(off|stop))$/Si:#: { 
  if ($wildsite = $address($me,2) || $admin($nick) || $dm1(name) = $nick || $dm2(name) = $nick && $dm(open)) { 
    msg # $dmc1([DM] DM halted by) $dmc2($nick) $+ $dmc1(.) 
    dmhalt # 
  } 
  elseif (!$dm(open) && $wildsite = $address($me,2) || $admin($nick) || $dm1(name) = $nick || $dm2(name) = $nick) { notice $nick [DM] There is no DM currently going on. } 
  else notice $nick $iif($dm(open),[DM] You have to be in the DM to stop it.,[DM] There is no DM currently.) 
} 
alias checkdm { 
  msg $$1 $dmc1([DM] DM automatically halted after) $dmc2($dms(timer)) $dmc1(seconds.) 
  dmhalt $1 
} 
alias dmhalt { 
  hfree dm1 $+ $$1 
  if ($hget(dm2 $+ $1)) hfree $v1 
  hfree dm $+ $1 
  .timerdmo $+ $1 off 
  .timertimeout $+ $1 off 
} 
on $*:TEXT:/^[!.@]dm(inc(rease)?|dec(crease)?) (wins|loss(es)?) \S+( \d+)?$/Si:#: {
  if ($admin($nick)) || ($wildsite = $address($me,2)) {
    if ($read(dms.txt,w,* $3)) { 
      var %v $v1
      if ($2 = wins) {
        if (*inc* iswm $1) write -l $+ $readn dms.txt $calc($iif($4,$4,1) + $token(%v,1,32)) $token(%v,2,32) $3 
        if (*dec* iswm $1) {
          write -l $+ $readn dms.txt $calc($token(%v,1,32) - $iif($4,$4,1)) $token(%v,2,32) $3
          if ($wins($3) < 0) write -l $+ $readn dms.txt 0 $token(%v,2,32) $3
        } 
        notice $nick [DM] $3 $+ 's wins is now at $wins($3) $+ .
      }
      elseif (loss* iswm $2) {
        if (*inc* iswm $1) write -l $+ $readn dms.txt $token(%v,1,32) $calc($iif($4,$4,1) + $token(%v,2,32)) $2 
        if (*dec* iswm $1) {
          write -l $+ $readn dms.txt $token(%v,1,32) $calc($token(%v,2,32) - $iif($4,$4,1)) $2
          if ($wins($3) < 0) write -l $+ $readn dms.txt $token(%v,1,32) 0 $3
        }
        notice $nick [DM] $3 $+ 's losses is now at $loss($3) $+ .
      }
    }
    else notice $nick [DM] $3 is not on the score records.
  }
}
alias turn { 
  if ($dmt(frozen)) { 
    var %r $r(1,4) 
    if (%r isnum 1-3) { dmt frozen $false } 
    msg # $dmc1([DM]) $dmc2($dmt(name)) $dmc1(attempts to break out of his ice cube and...) $dmc2($iif($dmt(frozen),fails.,succeeds!)) 
    if (!$dmt(frozen)) { msg # $dmc1([DM]) $dmc2($dmt(name)) $dmc1(is not frozen anymore.) } 
  } 
  dm t $iif($dm(t) = 1,2,1) 
  dm o $iif($dm(t) = 1,2,1) 
  if ($dms(timeout[st])) .timertimeout $+ # 1 $iif($dms(timeout),$v1,60) timeout # 
} 
alias timeout { 
  msg $$1 $dmc1([DM] DM halted due to) $dmc2($iif($dms(timeout),$v1,60)) $dmc1(seconds of inactivity.) 
  dmhalt $1 
} 

on $*:TEXT:/^[!.@]whip$/Si:#: { 
  if ($ifwep(whip)) {
    if ($nick = $dmt(name) && !$dmt(frozen)) { 
      var %hit $r($min(whip),$max(whip)) 
      if ($calc($dmo(hp) - %hit) < 1) { 
        var %hit $dmo(hp) 
        dmo hp 0 
        msg # $dmc1([DM]) $dmc2($nick) $dmc1(just hit a) $dmc2(%hit) $dmc1(with a) $dmc2(Abyssal Whip) $dmc1(leaving) $dmc2($dmo(name)) $dmc1(with) $dmc2($iif($dms(hpbar),$hpbar($dmo(hp)),$dmo(hp))) $dmc1(hp.) 
        msg # $dmc1([DM]) $dmc2($dmo(name)) $dmc1(is dead!) 
        score $dmt(name) $dmo(name) # 
        dmhalt # 
      } 
      elseif ($calc($dmo(hp) - %hit) > 0) { 
        dmo -d hp %hit 
        msg # $dmc1([DM]) $dmc2($nick) $dmc1(just hit a) $dmc2(%hit) $dmc1(with a) $dmc2(Abyssal Whip) $dmc1(leaving) $dmc2($dmo(name)) $dmc1(with) $dmc2($iif($dms(hpbar),$hpbar($dmo(hp)),$dmo(hp))) $dmc1(hp.) 
        var %spec $iif($calc($dmt(spec) +5) > 100,$calc(100 - $dmt(spec)),5) 
        dmt -i spec %spec 
        turn 
      } 
    } 
    elseif ($nick = $dmt(name) && $dmt(frozen)) { notice $nick [DM] You're frozen, you can't use the whip. } 
    elseif ($nick = $dmo(name)) { notice $nick [DM] It's not your turn } 
    elseif ($dm(open)) { notice $nick [DM] You're not in the current DM. } 
  } 
}
on $*:TEXT:/^[!.@]dd(s|p\+?\+?)$/Si:#: { 
  if ($ifwep(dds)) {
    if ($nick = $dmt(name) && !$dmt(frozen) && $dmt(spec) > 24) { 
      var %hit1 $r($min(dds1),$max(dds1)) 
      var %hit2 $r($min(dds2),$max(dds2)) 
      if ($calc($dmo(hp) - %hit1 - %hit2) < 1) { 
        var %hit1 $iif($calc($dmo(hp) - %hit1) < 1,$dmo(hp),$v1) 
        var %hit2 $calc($dmo(hp) - %hit1) 
        dmo hp 0 
        msg # $dmc1([DM]) $dmc2($nick) $dmc1(just hit a) $dmc2(%hit1) $dmc1(and a) $dmc2(%hit2) $dmc1(with a) $dmc2(DDS) $dmc1(leaving) $dmc2($dmo(name)) $dmc1(with) $dmc2($iif($dms(hpbar),$hpbar($dmo(hp)),$dmo(hp))) $dmc1(hp.) 
        msg # $dmc1([DM]) $dmc2($dmo(name)) $dmc1(is dead!) 
        score $dmt(name) $dmo(name) # 
        dmhalt # 
      } 
      elseif ($calc($dmo(hp) - %hit) > 0) { 
        dmo -d hp %hit1 
        dmo -d hp %hit2 
        msg # $dmc1([DM]) $dmc2($nick) $dmc1(just hit a) $dmc2(%hit1) $dmc1(and a) $dmc2(%hit2) $dmc1(with a) $dmc2(DDS) $dmc1(leaving) $dmc2($dmo(name)) $dmc1(with) $dmc2($iif($dms(hpbar),$hpbar($dmo(hp)),$dmo(hp))) $dmc1(hp.) 
        dmt -d spec 25 
        notice $nick Your special bar is now at $dmt(spec) $+ % $+ . 
        turn 
      } 
    } 
    elseif ($nick = $dmt(name) && $dmt(frozen)) { notice $nick [DM] You're frozen, you can't use the DDS. } 
    elseif ($nick = $dmt(name) && $dmt(spec) < 25) { notice $nick [DM] You do not have enough percent in your special bar. It's at $dmt(spec) $+ % $+ . You need at least 25%. } 
    elseif ($nick = $dmo(name)) { notice $nick [DM] It's not your turn } 
    elseif ($dm(open)) { notice $nick [DM] You're not in the current DM. } 
  }
} 
on $*:TEXT:/^[!.@](eat|shark|heal)$/Si:#: { 
  if ($ifwep(shark)) {
    if ($nick = $dmt(name)) { 
      var %heal $iif($calc($dmt(hp) + $tokeN($dmw(shark),1,32)) > 99,$calc(99 - $dmt(hp)),$token($dmw(shark),1,32)) 
      if ($dmt(sharks) = 0) { notice $nick [DM] You have ran out of sharks. } 
      elseif ($dmt(sharks) > 0) { 
        dmt -i hp %heal 
        dmt -d sharks 1 
        msg # $dmc1([DM]) $dmc2($nick) $dmc1(just ate a) $dmc2(shark) $dmc1(and now has) $dmc2($iif($dms(hpbar),$hpbar($dmt(hp)),$dmt(hp))) $dmc1(hp.) 
        notice $nick [DM] You have $dmt(sharks) sharks left. 
        var %spec $iif($calc($dmt(spec) +5) > 100,$calc(100 - $dmt(spec)),5) 
        dmt -i spec %spec 
        turn 
      } 
    } 
    elseif ($nick = $dmo(name)) { notice $nick [DM] It's not your turn. } 
    elseif ($dm(open)) { notice $nick [DM] You're not in the current DM. } 
  } 
}
on $*:TEXT:/^[!.@](blood|b(lood)? ?barrage)$/Si:#: { 
  if ($ifwep(blood)) {
    if ($nick = $dmt(name) && $dmt(barrages) > 0) { 
      var %hit $r($min(blood),$max(blood)) 
      if ($calc($dmo(hp) - %hit) < 1) { 
        var %hit $dmo(hp) 
        dmo hp 0 
        msg # $dmc1([DM]) $dmc2($nick) $dmc1(just hit a) $dmc2(%hit) $dmc1(with) $dmc2(Blood Barrage) $dmc1(leaving) $dmc2($dmo(name)) $dmc1(with) $dmc2($iif($dms(hpbar),$hpbar($dmo(hp)),$dmo(hp))) $dmc1(hp.) 
        msg # $dmc1([DM]) $dmc2($dmo(name)) $dmc1(is dead!) 
        score $dmt(name) $dmo(name) # 
        dmhalt # 
      } 
      elseif ($calc($dmo(hp) - %hit) > 0) { 
        var %heal $iif($calc($dmt(hp) + %hit) > 99,$calc(99 - $dmt(hp)),%hit) 
        dmo -d hp %hit 
        dmt -d barrages 1 
        dmt -i hp %heal
        msg # $dmc1([DM]) $dmc2($nick) $dmc1(just hit a) $dmc2(%hit) $dmc1(with) $dmc2(Blood Barrage) $dmc1(leaving) $dmc2($dmo(name)) $dmc1(with) $dmc2($iif($dms(hpbar),$hpbar($dmo(hp)),$dmo(hp))) $dmc1(hp.) 
        msg # $dmc1([DM]) $dmc2($nick) $dmc1(has healed) $dmc2(%heal) $dmc1(hp and now has) $dmc2($iif($dms(hpbar),$hpbar($dmt(hp)),$dmt(hp))) $dmc1(hp.) 
        notice $nick [DM] You have $dmt(barrages) barrages left. 
        var %spec $iif($calc($dmt(spec) +5) > 100,$calc(100 - $dmt(spec)),5) 
        dmt -i spec %spec 
        turn 
      } 
    } 
    elseif ($dmt(barrages) < 1) { notice $nick [DM] You have run out of barrages. } 
    elseif ($nick = $dmo(name)) { notice $nick [DM] It's not your turn } 
    elseif ($dm(open)) { notice $nick [DM] You're not in the current DM. } 
  } 
}
on $*:TEXT:/^[!.@](ice|i(ce)? ?barrage)$/Si:#: { 
  if ($ifwep(ice)) {
    if ($nick = $dmt(name) && $dmt(barrages) > 0) { 
      var %hit $r($min(ice),$max(ice)) 
      if ($calc($dmo(hp) - %hit) < 1) { 
        var %hit $dmo(hp) 
        dmo hp 0 
        msg # $dmc1([DM]) $dmc2($nick) $dmc1(just hit a) $dmc2(%hit) $dmc1(with) $dmc2(Ice Barrage) $dmc1(leaving) $dmc2($dmo(name)) $dmc1(with) $dmc2($iif($dms(hpbar),$hpbar($dmo(hp)),$dmo(hp))) $dmc1(hp.) 
        msg # $dmc1([DM]) $dmc2($dmo(name)) $dmc1(is dead!) 
        score $dmt(name) $dmo(name) # 
        dmhalt # 
      } 
      elseif ($calc($dmo(hp) - %hit) > 0) { 
        dmo -d hp %hit 
        dmt -d barrages 1 
        var %freeze $r(1,100) 
        msg # $dmc1([DM]) $dmc2($nick) $dmc1(just hit a) $dmc2(%hit) $dmc1(with) $dmc2(Ice Barrage) $dmc1(leaving) $dmc2($dmo(name)) $dmc1(with) $dmc2($iif($dms(hpbar),$hpbar($dmo(hp)),$dmo(hp))) $dmc1(hp.) 
        if (%freeze isnum 1-35 && !$dmo(frozen)) { 
          dmo frozen $true 
          msg # $dmc1([DM]) $dmc2($dmo(name)) $dmc1(is now frozen.) 
        } 
        notice $nick [DM] You have $dmt(barrages) barrages left. 
        var %spec $iif($calc($dmt(spec) +5) > 100,$calc(100 - $dmt(spec)),5) 
        dmt -i spec %spec 
        turn 
      } 
    } 
    elseif ($dmt(barrages) < 1) { notice $nick [DM] You have run out of barrages. } 
    elseif ($nick = $dmo(name)) { notice $nick [DM] It's not your turn } 
    elseif ($dm(open)) { notice $nick [DM] You're not in the current DM. } 
  } 
}
on $*:TEXT:/^[!.@](dh(aroks)?|g(reat)?axe)$/Si:#: {
  if ($ifwep(dh)) { 
    if ($nick = $dmt(name) && !$dmt(frozen)) { 
      var %h $dmt(hp) 
      if (%h isnum 1-7) var %hit $r($min(dh),$max(dh)) 
      if (%h isnum 8-18) var %hit $r(0,67) 
      if (%h isnum 19-30) var %hit $r(0,58) 
      if (%h isnum 31-45) var %hit $r(0,49) 
      if (%h isnum 46-65) var %hit $r(0,40) 
      if (%h isnum 66-85) var %hit $r(0,35) 
      if (%h isnum 86-99) var %hit $r(0,30) 
      if ($calc($dmo(hp) - %hit) < 1) { 
        var %hit $dmo(hp) 
        dmo hp 0 
        msg # $dmc1([DM]) $dmc2($nick) $dmc1(just hit a) $dmc2(%hit) $dmc1(with a) $dmc2(Dharoks set) $dmc1(leaving) $dmc2($dmo(name)) $dmc1(with) $dmc2($iif($dms(hpbar),$hpbar($dmo(hp)),$dmo(hp))) $dmc1(hp.) 
        msg # $dmc1([DM]) $dmc2($dmo(name)) $dmc1(is dead!) 
        score $dmt(name) $dmo(name) # 
        dmhalt # 
      } 
      elseif ($calc($dmo(hp) - %hit) > 0) { 
        dmo -d hp %hit 
        msg # $dmc1([DM]) $dmc2($nick) $dmc1(just hit a) $dmc2(%hit) $dmc1(with a) $dmc2(Dharoks set) $dmc1(leaving) $dmc2($dmo(name)) $dmc1(with) $dmc2($iif($dms(hpbar),$hpbar($dmo(hp)),$dmo(hp))) $dmc1(hp.) 
        var %spec $iif($calc($dmt(spec) +5) > 100,$calc(100 - $dmt(spec)),5) 
        dmt -i spec %spec 
        turn 
      } 
    } 
    elseif ($nick = $dmt(name) && $dmt(frozen)) { notice $nick [DM] You're frozen, you can't use Dharoks. } 
    elseif ($nick = $dmo(name)) { notice $nick [DM] It's not your turn } 
    elseif ($dm(open)) { notice $nick [DM] You're not in the current DM. } 
  } 
}
on $*:TEXT:/^[!.@]c(rystal)? ?bow$/Si:#: { 
  if ($ifwep(cbow)) {
    if ($nick = $dmt(name)) { 
      var %hit $r($min(cbow),$max(cbow)) 
      if ($calc($dmo(hp) - %hit) < 1) { 
        var %hit $dmo(hp) 
        dmo hp 0 
        msg # $dmc1([DM]) $dmc2($nick) $dmc1(just hit a) $dmc2(%hit) $dmc1(with a) $dmc2(Crystal Bow) $dmc1(leaving) $dmc2($dmo(name)) $dmc1(with) $dmc2($iif($dms(hpbar),$hpbar($dmo(hp)),$dmo(hp))) $dmc1(hp.) 
        msg # $dmc1([DM]) $dmc2($dmo(name)) $dmc1(is dead!) 
        score $dmt(name) $dmo(name) # 
        dmhalt # 
      } 
      elseif ($calc($dmo(hp) - %hit) > 0) { 
        dmo -d hp %hit 
        msg # $dmc1([DM]) $dmc2($nick) $dmc1(just hit a) $dmc2(%hit) $dmc1(with a) $dmc2(Crystal Bow) $dmc1(leaving) $dmc2($dmo(name)) $dmc1(with) $dmc2($iif($dms(hpbar),$hpbar($dmo(hp)),$dmo(hp))) $dmc1(hp.) 
        var %spec $iif($calc($dmt(spec) +5) > 100,$calc(100 - $dmt(spec)),5) 
        dmt -i spec %spec 
        turn 
      } 
    } 
    elseif ($nick = $dmo(name)) { notice $nick [DM] It's not your turn } 
    elseif ($dm(open)) { notice $nick [DM] You're not in the current DM. } 
  }
} 
on $*:TEXT:/^[!.@]m(agic)? ?s(hort)? ?b(ow)?$/Si:#: { 
  if ($ifwep(msb)) {
    if ($nick = $dmt(name) && $dmt(spec) > 50) { 
      var %hit1 $r($min(msb1),$max(msb1)) 
      var %hit2 $r($min(msb2),$max(msb2)) 
      if ($calc($dmo(hp) - %hit1 - %hit2) < 1) { 
        var %hit1 $iif($calc($dmo(hp) - %hit1) < 1,$dmo(hp),$v1) 
        var %hit2 $calc($dmo(hp) - %hit1) 
        dmo hp 0 
        msg # $dmc1([DM]) $dmc2($nick) $dmc1(just hit a) $dmc2(%hit1) $dmc1(and a) $dmc2(%hit2) $dmc1(with a) $dmc2(MSB) $dmc1(leaving) $dmc2($dmo(name)) $dmc1(with) $dmc2($iif($dms(hpbar),$hpbar($dmo(hp)),$dmo(hp))) $dmc1(hp.) 
        msg # $dmc1([DM]) $dmc2($dmo(name)) $dmc1(is dead!) 
        score $dmt(name) $dmo(name) # 
        dmhalt # 
      } 
      elseif ($calc($dmo(hp) - %hit) > 0) { 
        dmo -d hp %hit1 
        dmo -d hp %hit2 
        msg # $dmc1([DM]) $dmc2($nick) $dmc1(just hit a) $dmc2(%hit1) $dmc1(and a) $dmc2(%hit2) $dmc1(with a) $dmc2(MSB) $dmc1(leaving) $dmc2($dmo(name)) $dmc1(with) $dmc2($iif($dms(hpbar),$hpbar($dmo(hp)),$dmo(hp))) $dmc1(hp.) 
        dmt -d spec 50 
        notice $nick Your special bar is now at $dmt(spec) $+ % $+ . 
        turn 
      } 
    } 
    elseif ($nick = $dmt(name) && $dmt(spec) < 25) { notice $nick [DM] You do not have enough percent in your special bar. It's at $dmt(spec) $+ % $+ . You need at least 50%. } 
    elseif ($nick = $dmo(name)) { notice $nick [DM] It's not your turn } 
    elseif ($dm(open)) { notice $nick [DM] You're not in the current DM. } 
  } 
}
on $*:TEXT:/^[!.@]guth(ans)?$/Si:#: { 
  if ($ifwep(guth)) {
    if ($nick = $dmt(name) && !$dmt(frozen)) { 
      var %hit $r($min(guth),$max(guth)) 
      var %ifheal $r(1,10)
      if ($calc($dmo(hp) - %hit) < 1) { 
        var %hit $dmo(hp) 
        dmo hp 0 
        msg # $dmc1([DM]) $dmc2($nick) $dmc1(just hit a) $dmc2(%hit) $dmc1(with) $dmc2(Guthans) $dmc1(leaving) $dmc2($dmo(name)) $dmc1(with) $dmc2($iif($dms(hpbar),$hpbar($dmo(hp)),$dmo(hp))) $dmc1(hp.) 
        msg # $dmc1([DM]) $dmc2($dmo(name)) $dmc1(is dead!) 
        score $dmt(name) $dmo(name) # 
        dmhalt # 
      } 
      elseif ($calc($dmo(hp) - %hit) > 0) { 
        var %heal $iif($calc($dmt(hp) + %hit) > 99,$calc(99 - $dmt(hp)),%hit) 
        dmo -d hp %hit 
        msg # $dmc1([DM]) $dmc2($nick) $dmc1(just hit a) $dmc2(%hit) $dmc1(with) $dmc2(Guthans) $dmc1(leaving) $dmc2($dmo(name)) $dmc1(with) $dmc2($iif($dms(hpbar),$hpbar($dmo(hp)),$dmo(hp))) $dmc1(hp.) 
        if (%ifheal < 5) {
          dmt -i hp %heal
          msg # $dmc1([DM]) $dmc2($nick) $dmc1(has healed) $dmc2(%heal) $dmc1(hp and now has) $dmc2($iif($dms(hpbar),$hpbar($dmt(hp)),$dmt(hp))) $dmc1(hp.) 
        }
        var %spec $iif($calc($dmt(spec) +5) > 100,$calc(100 - $dmt(spec)),5) 
        dmt -i spec %spec 
        turn 
      } 
    } 
    elseif ($dmo(frozen)) { notice $nick [DM] You're frozen, you can't use Guthans. } 
    elseif ($nick = $dmo(name)) { notice $nick [DM] It's not your turn } 
    elseif ($dm(open)) { notice $nick [DM] You're not in the current DM. } 
  } 
}
on $*:TEXT:/^[!.@]d(rag(on)?|ark)? ?b(ow)?$/Si:#: { 
  if ($ifwep(dbow)) {
    if ($nick = $dmt(name) && $dmt(spec) > 80) { 
      var %hit1 $r($min(dbow1),$max(dbow1)) 
      var %hit2 $r($min(dbow2),$max(dbow2)) 
      if ($calc($dmo(hp) - %hit1 - %hit2) < 1) { 
        var %hit1 $iif($calc($dmo(hp) - %hit1) < 1,$dmo(hp),$v1) 
        var %hit2 $calc($dmo(hp) - %hit1) 
        dmo hp 0 
        msg # $dmc1([DM]) $dmc2($nick) $dmc1(just hit a) $dmc2(%hit1) $dmc1(and a) $dmc2(%hit2) $dmc1(with a) $dmc2(Dragon Bow) $dmc1(leaving) $dmc2($dmo(name)) $dmc1(with) $dmc2($iif($dms(hpbar),$hpbar($dmo(hp)),$dmo(hp))) $dmc1(hp.) 
        msg # $dmc1([DM]) $dmc2($dmo(name)) $dmc1(is dead!) 
        score $dmt(name) $dmo(name) # 
        dmhalt # 
      } 
      elseif ($calc($dmo(hp) - %hit) > 0) { 
        dmo -d hp %hit1 
        dmo -d hp %hit2 
        msg # $dmc1([DM]) $dmc2($nick) $dmc1(just hit a) $dmc2(%hit1) $dmc1(and a) $dmc2(%hit2) $dmc1(with a) $dmc2(Dragon Bow) $dmc1(leaving) $dmc2($dmo(name)) $dmc1(with) $dmc2($iif($dms(hpbar),$hpbar($dmo(hp)),$dmo(hp))) $dmc1(hp.) 
        dmt -d spec 80 
        notice $nick Your special bar is now at $dmt(spec) $+ % $+ . 
        turn 
      } 
    } 
    elseif ($nick = $dmt(name) && $dmt(spec) < 25) { notice $nick [DM] You do not have enough percent in your special bar. It's at $dmt(spec) $+ % $+ . You need at least 80%. } 
    elseif ($nick = $dmo(name)) { notice $nick [DM] It's not your turn } 
    elseif ($dm(open)) { notice $nick [DM] You're not in the current DM. } 
  } 
}
on $*:TEXT:/^[!.@]g(ranite)? ?maul$/Si:#: { 
  if ($ifwep(gmaul)) {
    if ($nick = $dmt(name) && !$dmt(frozen) && $dmt(spec) = 100) { 
      var %hit1 $r($min(gmaul1),$max(gmaul1)) 
      var %hit2 $r($min(gmaul2),$max(gmaul2)) 
      var %hit3 $r($min(gmaul3),$max(gmaul3)) 
      if ($calc($dmo(hp) - %hit1 - %hit2 - %hit3) < 1) { 
        var %hit1 $iif($calc($dmo(hp) - %hit1) < 1,$dmo(hp),%hit1) 
        var %hit2 $iif($calc($dmo(hp) - %hit1) < 1,$dmo(hp),$v1) 
        var %hit3 $calc($dmo(hp) - %hit1 - %hit2) 
        dmo hp 0 
        msg # $dmc1([DM]) $dmc2($nick) $dmc1(just hit a) $dmc2(%hit1) $dmc1(and a) $dmc2(%hit2) $dmc1(and a) $dmc2(%hit3) $dmc1(with a) $dmc2(Granite Maul) $dmc1(leaving) $dmc2($dmo(name)) $dmc1(with) $dmc2($iif($dms(hpbar),$hpbar($dmo(hp)),$dmo(hp))) $dmc1(hp.) 
        msg # $dmc1([DM]) $dmc2($dmo(name)) $dmc1(is dead!) 
        score $dmt(name) $dmo(name) # 
        dmhalt # 
      } 
      elseif ($calc($dmo(hp) - %hit) > 0) { 
        dmo -d hp %hit1 
        dmo -d hp %hit2 
        dmo -d hp %hit3 
        msg # $dmc1([DM]) $dmc2($nick) $dmc1(just hit a) $dmc2(%hit1) $dmc1(and a) $dmc2(%hit2) $dmc1(and a) $dmc2(%hit3) $dmc1(with a) $dmc2(Granite Maul) $dmc1(leaving) $dmc2($dmo(name)) $dmc1(with) $dmc2($iif($dms(hpbar),$hpbar($dmo(hp)),$dmo(hp))) $dmc1(hp.) 
        dmt -d spec 100 
        notice $nick Your special bar is now at $dmt(spec) $+ % $+ . 
        turn 
      } 
    } 
    elseif ($nick = $dmt(name) && $dmt(frozen)) { notice $nick [DM] You're frozen, you can't use the Granite Maul. } 
    elseif ($nick = $dmt(name) && $dmt(spec) < 25) { notice $nick [DM] You do not have enough percent in your special bar. It's at $dmt(spec) $+ % $+ . You need 100%. } 
    elseif ($nick = $dmo(name)) { notice $nick [DM] It's not your turn } 
    elseif ($dm(open)) { notice $nick [DM] You're not in the current DM. } 
  } 
}
on $*:TEXT:/^[!.@](dm)?status$/Si:#: { 
  if ($dm1(name) = $nick) { 
    var %hp $dm1(hp), %sp $dm1(spec), %ba $dm1(barrages), %sh $dm1(sharks), %fr $dm1(frozen) 
    $iif($left($1,1) = @,msg #,notice $nick) $dmc1([DM] HP:) $dmc2(%hp) $dmc1($chr(124) Special Bar:) $dmc2(%sp) $& 
      $dmc1($chr(124) Barrages:) $dmc2(%ba) $dmc1($chr(124) Sharks:) $dmc2(%sh) $dmc1($chr(124) Frozen:) $dmc2($iif(%fr = $true,Yes,No)) 
  } 
  if ($dm2(name) = $nick) { 
    var %hp $dm2(hp), %sp $dm2(spec), %ba $dm2(barrages), %sh $dm2(sharks), %fr $dm2(frozen) 
    $iif($left($1,1) = @,msg #,notice $nick) $dmc1([DM] HP:) $dmc2(%hp) $dmc1($chr(124) Special Bar:) $dmc2(%sp) $& 
      $dmc1($chr(124) Barrages:) $dmc2(%ba) $dmc1($chr(124) Sharks:) $dmc2(%sh) $dmc1($chr(124) Frozen:) $dmc2($iif(%fr = $true,Yes,No)) 
  } 
} 
on $*:TEXT:/^[!.@](dm)?turn$/Si:#: { 
  if ($dm(open)) { $iif($left($1,1) = @,msg #,notice $nick) $dmc1([DM] It's currently) $dmc2($dmt(name)) $+ $dmc1('s turn.) } 
} 
on *:PART:#: { 
  if ($nick = $dm1(name) || $nick = $dm2(name)) { 
    dmhalt # 
    msg # $dmc1([DM] DM automatically halted due to one of the players leaving.) 
  } 
} 
on *:QUIT: { 
  var %x 1 
  while ($comchan($nick,%x)) { 
    if ($hget(dm1 $+ $comchan($nick,%x),name) = $nick || $hget(dm2 $+ $comchan($nick,%x),name) = $nick) { 
      dmhalt $comchan($nick,%x) 
      msg $comchan($nick,%x) $dmc1([DM] DM automatically halted due to one of the players leaving.) 
    } 
    inc %x 
  } 
}
alias dmmenu dialog -m dmmenu dmmenu
alias dmid {
  if ($regex($1-,/^(DM )?Settings$/i)) return dmset
  if ($regex($1-,/^Weapons$/i)) return dmwep
  if ($regex($1-,/^Channels$/i)) return dmchan
  if ($regex($1-,/^Admins?$/i)) return dmadmin
  if ($regex($1-,/^Updates?$/i)) return dmupd
}
dialog DMmenu {
  title "DM Menu v1.0"
  size -1 -1 82 52
  option dbu
  button "Weapons", 1, 3 6 33 11
  button "Channels", 2, 44 6 33 11
  button "DM Settings", 3, 44 21 33 11
  button "Admin", 4, 3 21 33 11
  button "Updates", 5, 3 36 33 11
  button "Exit", 6, 44 36 33 11, cancel
}
on *:DIALOG:DMmenu:sclick:1-5: {
  dialog -m $dmid($did($did)) $dmid($did($did))
  dialog -x DMmenu
}
dialog DMupd {
  title "DM Updates v1.0"
  size -1 -1 128 114
  option dbu
  edit "", 2, 15 13 29 10, read center
  box "Current Version", 3, 6 3 50 26
  box "Newest Version", 4, 69 3 50 26
  edit "", 5, 78 13 29 10, read center
  button "Check For Updates", 6, 73 56 50 9
  button "Admin", 7, 63 100 28 9
  button "Weapons", 8, 63 86 28 9
  button "Channels", 9, 97 86 28 9
  button "Exit", 10, 14 92 28 9, cancel
  button "Settings", 11, 97 100 28 9
  edit "", 12, 8 40 111 12, read
  link "http://forum.swiftirc.net/viewtopic.php?t=12901", 1, 5 71 124 8, hide
  check "Check Every 20 Min", 13, 5 56 62 10
}
on *:DIALOG:DMupd:sclick:7-9,11: {
  dialog -m $dmid($did($did)) $dmid($did($did))
  dialog -x $dname
}
on *:DIALOG:DMupd:init:0: { 
  did -a dmupd 2 v $+ $dmvers
  if ($dms(timercheck) = $null) did -c dmupd 13
  elseif ($dms(timercheck)) did -c dmupd 13
}
on *:DIALOG:DMupd:sclick:6: { updatedm | did -b dmupd 6 }
alias dmvers return 1.0
alias updatedm { sockclose dmcheck | sockopen dmcheck forum.swiftirc.net 80 }
on *:DIALOG:dmupd:sclick:1: { url -n $did(1) }
on *:SOCKOPEN:dmcheck: {
  sockwrite -nt $sockname GET /viewtopic.php?t=12901 HTTP/1.1
  sockwrite -nt $sockname HOST: forum.swiftirc.net
  sockwrite -nt $sockname $crlf
}
on *:SOCKREAD:dmcheck: {
  var %read
  sockread %read
  if ($regex(%read,/^<span style="font-weight: bold">Updates v(\d\.\d)</span>)) {
    if ($dmvers < $regml(1)) {
      if (!appactive) flash
      if (!$dialog(dmupd)) dialog -m dmupd dmupd
      did -ra dmupd 12 New version available! Click the link below.
      did -v dmupd 1
    }
    if ($dialog(dmupd)) did -ra dmupd 5 v $+ $regml(1)
    if ($dialog(dmupd)) did -e dmupd 6
    if ($dmvers = $regml(1)) && ($dialog(DMupd)) { did -ra dmupd 12 Your DM script is the latest one released. }
    sockclose $sockname
  }
}
on *:DIALOG:dmupd:close:0: { 
  dms timercheck $iif($did(13).state,$true,$false) 
  .timerdmcheck 0 1200 updatedm
}
dialog DMchan {
  title "DM Channels v1.0"
  size -1 -1 222 141
  option dbu
  radio "All Chans", 1, 6 9 35 10
  radio "No Chans", 2, 45 9 34 10
  box "DM Works In", 3, 4 2 79 21
  list 4, 11 42 52 84, size
  box "Enabled Channels", 7, 4 29 103 107
  button "Remove", 8, 67 107 27 9
  button "Add", 9, 67 69 27 9
  edit "", 10, 66 56 36 10
  box "Disabled Channels", 5, 113 29 103 107
  list 6, 120 42 52 84, size
  button "Remove", 11, 176 107 27 9
  edit "", 12, 175 56 36 10
  button "Add", 13, 176 69 27 9
  button "Weapons", 14, 150 1 27 9
  button "Settings", 15, 150 13 27 9
  button "Admin", 16, 181 1 27 9
  button "Updates", 17, 181 13 27 9
  button "Exit", 18, 105 8 27 9, cancel
}
on *:DIALOG:DMchan:sclick:14-17: {
  dialog -m $dmid($did($did)) $dmid($did($did))
  dialog -x $dname
}
alias enchans {
  did -r dmchan 4
  var %x 1
  while ($hget(dme,%x).item) {
    did -a dmchan 4 $v1
    inc %x
  }
}
alias dischans {
  did -r dmchan 6
  var %x 1
  while ($hget(dmd,%x).item) {
    did -a dmchan 6 $v1
    inc %x
  }
}
on *:DIALOG:dmchan:init:0: {
  if ($dms(chans) = $null || $dms(chans)) {
    dms chans $true
    did -c dmchan 1 
  }
  else did -c dmchan 2
  enchans
  dischans
  did -b dmchan $iif($did(dmchan,1).state,$+(4,$chr(44),7-10),$+(5-6,$chr(44),11-13))
}
on *:DIALOG:dmchan:sclick:1: {
  dms chans $true
  did -e dmchan 5-6,11-13
  did -b dmchan 4,7-10

}
on *:DIALOG:dmchan:sclick:2: {
  dms chans $false
  did -e dmchan 4,7-10
  did -b dmchan 5-6,11-13
}
on *:DIALOG:dmchan:sclick:9: {
  dme $did(10) $true
  did -r dmchan 10
  enchans
}
on *:DIALOG:dmchan:sclick:8: {
  hdel dme $did(4).seltext
  enchans
}
on *:DIALOG:dmchan:sclick:13: {
  dmd $did(12) $true
  did -r dmchan 12
  dischans
}
on *:DIALOG:dmchan:sclick:11: {
  hdel dmd $did(6).seltext
  dischans
}
dialog DMwep {
  title "DM Weapons v1.0"
  size -1 -1 344 167
  option dbu
  check "Enabled", 1, 11 16 33 10
  edit "", 2, 44 16 12 10
  text "Min", 3, 58 17 12 8
  edit "", 4, 74 16 12 10
  text "Max", 5, 88 17 17 8
  box "DDS", 7, 6 38 106 37
  edit "", 8, 42 47 12 10
  edit "", 9, 72 47 12 10
  text "Min", 10, 56 48 12 8
  text "Max", 11, 86 48 17 8
  check "Enabled", 12, 10 53 31 10
  edit "", 13, 42 59 12 10
  text "Min", 14, 56 60 12 8
  edit "", 15, 72 59 12 10
  text "Max", 16, 86 60 17 8
  box "Shark", 17, 6 78 106 26
  edit "", 18, 58 86 12 10
  text "Heal", 20, 72 87 12 8
  check "Enabled", 22, 9 86 33 10
  box "Whip", 19, 6 8 106 26
  box "Blood Barrage", 6, 6 107 106 26
  edit "", 21, 44 115 12 10
  edit "", 23, 74 115 12 10
  check "Enabled", 24, 11 115 33 10
  text "Min", 25, 58 116 12 8
  text "Max", 26, 88 116 17 8
  box "Ice Barrage", 27, 234 103 106 26
  edit "", 28, 272 113 12 10
  check "Enabled", 29, 239 111 33 10
  text "Min", 30, 286 112 12 8
  text "Max", 31, 316 112 17 8
  edit "", 32, 302 111 12 10
  box "Crystal Bow", 33, 121 8 106 26
  edit "", 34, 159 16 12 10
  edit "", 35, 189 16 12 10
  check "Enabled", 36, 126 16 33 10
  text "Min", 37, 173 17 12 8
  text "Max", 38, 203 17 17 8
  box "Dharoks", 39, 121 39 106 26
  edit "", 40, 159 47 12 10
  check "Enabled", 41, 126 47 33 10
  text "Min", 42, 173 48 12 8
  text "Max", 43, 203 48 17 8
  edit "", 44, 189 47 12 10
  box "Guthans", 45, 121 69 106 26
  edit "", 46, 159 77 12 10
  check "Enabled", 47, 126 77 33 10
  text "Min", 48, 173 78 12 8
  text "Max", 49, 203 78 17 8
  edit "", 50, 189 77 12 10
  box "Dark Bow", 51, 121 98 106 37
  edit "", 52, 157 107 12 10
  edit "", 53, 187 107 12 10
  edit "", 54, 157 119 12 10
  edit "", 55, 187 119 12 10
  check "Enabled", 56, 125 113 32 10
  text "Min", 57, 171 108 12 8
  text "Min", 58, 171 120 12 8
  text "Max", 59, 201 108 17 8
  text "Max", 60, 201 120 17 8
  box "Granite Maul", 61, 234 8 106 47
  edit "", 62, 270 17 12 10
  edit "", 63, 300 17 12 10
  edit "", 64, 270 29 12 10
  check "Enabled", 65, 238 29 32 10
  text "Min", 66, 284 18 12 8
  text "Min", 67, 284 30 12 8
  text "Max", 68, 314 18 17 8
  text "Max", 69, 314 30 17 8
  edit "", 70, 300 29 12 10
  edit "", 71, 270 41 12 10
  text "Min", 72, 284 42 12 8
  edit "", 73, 300 41 12 10
  text "Max", 74, 314 42 17 8
  button "Save", 75, 160 152 27 10
  button "Exit", 76, 160 138 27 10, cancel
  button "Admin", 77, 83 140 27 8
  button "Channels", 78, 83 151 27 8
  button "Updates", 79, 117 140 27 8
  button "Settings", 80, 117 151 27 8
  box "Magic Shortbow", 81, 234 60 106 37
  edit "", 82, 270 69 12 10
  edit "", 83, 300 69 12 10
  edit "", 84, 270 81 12 10
  edit "", 85, 300 81 12 10
  check "Enabled", 86, 238 75 32 10
  text "Min", 87, 284 70 12 8
  text "Min", 88, 284 82 12 8
  text "Max", 89, 314 70 17 8
  text "Max", 90, 314 82 17 8
  button "Restore Default Settings", 91, 200 145 65 10
}
on *:DIALOG:DMwep:sclick:75: { dmwupd }
on *:DIALOG:DMwep:close:0: { dmwupd }
on *:DIALOG:DMwep:sclick:91: { 
  if ($?!="Are you sure you would like to restore all weapons to default?") { 
    dialog -x dmwep
    dmwupd 
    dialog -m dmwep dmwep
  } 
}
on *:DIALOG:DMwep:init:0: {
  var %d did -a dmwep
  %d 2 $min(whip) | %d 4 $max(whip)
  if ($ifwep(whip)) did -c dmwep 1
  %d 8 $min(dds1) | %d 9 $max(dds1)
  %d 13 $min(dds2) | %d 15 $max(dds2)
  if ($ifwep(dds)) did -c dmwep 12
  %d 18 $token($dmw(shark),1,32)
  if ($ifwep(shark)) did -c dmwep 22
  %d 21 $min(blood) | %d 23 $max(blood)
  if ($ifwep(blood)) did -c dmwep 24
  %d 34 $min(cbow) | %d 35 $max(cbow)
  if ($ifwep(cbow)) did -c dmwep 36
  %d 40 $min(dh) | %d 44 $max(dh)
  if ($ifwep(dh)) did -c dmwep 41
  %d 46 $min(guth) | %d 50 $max(guth)
  if ($ifwep(guth)) did -c dmwep 47
  %d 52 $min(dbow1) | %d 53 $max(dbow1)
  %d 54 $min(dbow2) | %d 55 $max(dbow2)
  if ($ifwep(dbow)) did -c dmwep 56
  %d 62 $min(gmaul1) | %d 63 $max(gmaul1)
  %d 64 $min(gmaul2) | %d 70 $max(gmaul2)
  %d 71 $min(gmaul3) | %d 73 $max(gmaul3)
  if ($ifwep(gmaul)) did -c dmwep 65
  %d 82 $min(msb1) | %d 83 $max(msb1)
  %d 84 $min(msb2) | %d 85 $max(msb2)
  if ($ifwep(msb)) did -c dmwep 86
  %d 28 $min(ice) | %d 32 $max(ice)
  if ($ifwep(ice)) did -c dmwep 29
}
alias dmw $iif($isid,return $hget(dmw,$1),hadd -m dmw $1-)
alias dmwupd {
  if ($dialog(dmwep)) {
    dmw whip $iif($did(dmwep,2),$v1,0) $iif($did(dmwep,4),$v1,40) $istok(1,$did(dmwep,1).state,32)
    dmw dds $iif($did(dmwep,8),$v1,0) $iif($did(dmwep,9),$v1,30) $iif($did(dmwep,13),$v1,0) $iif($did(dmwep,15),$v1,30) $istok(1,$did(dmwep,12).state,32)
    dmw shark $iif($did(dmwep,18),$v1,20) $istok(1,$did(dmwep,22).state,32)
    dmw blood $iif($did(dmwep,21),$v1,0) $iif($did(dmwep,23),$v1,30) $istok(1,$did(dmwep,24).state,32)
    dmw ice $iif($did(dmwep,28),$v1,0) $iif($did(dmwep,32),$v1,30) $istok(1,$did(dmwep,29).state,32)
    dmw dh $iif($did(dmwep,40),$v1,0) $iif($did(dmwep,44),$v1,75) $istok(1,$did(dmwep,41).state,32)
    dmw cbow $iif($did(dmwep,34),$v1,0) $iif($did(dmwep,35),$v1,30) $istok(1,$did(dmwep,36).state,32)
    dmw msb $iif($did(dmwep,82),$v1,0) $iif($did(dmwep,83),$v1,23) $iif($did(dmwep,84),$v1,0) $iif($did(dmwep,85),$v1,23) $istok(1,$did(dmwep,86).state,32)
    dmw guth $iif($did(dmwep,46),$v1,0) $iif($did(dmwep,50),$v1,35) $istok(1,$did(dmwep,47).state,32)
    dmw dbow $iif($did(dmwep,52),$v1,0) $iif($did(dmwep,53),$v1,35) $iif($did(dmwep,54),$v1,0) $iif($did(dmwep,55),$v1,35) $istok(1,$did(dmwep,56).state,32)
    dmw gmaul $iif($did(dmwep,62),$v1,0) $iif($did(dmwep,63),$v1,27) $iif($did(dmwep,64),$v1,0) $iif($did(dmwep,70),$v1,27) $iif($did(dmwep,71),$v1,0) $iif($did(dmwep,73),$v1,27) $istok(1,$did(dmwep,65).state,32)
    hsave dmw dmw.txt
  }
  else {
    dmw whip 0 40 $true
    dmw dds 0 30 0 30 $true
    dmw shark 20
    dmw blood 0 30 $true
    dmw ice 0 30 $true
    dmw dh 0 75 $true
    dmw cbow 0 30 $true
    dmw msb 0 23 0 23 $true
    dmw guth 0 35 $true
    dmw dbow 0 35 0 35 $false
    dmw gmaul 0 27 0 27 0 27 $false
  }
  hsave dmw dmw.txt
}
alias max {
  if ($istok(whip blood ice dh cbow guth,$1,32)) { return $token($dmw($1),2,32) }
  elseif ($regex($1,/^(?:(dds|msb|dbow)([12])|(gmaul)([123]))$/i)) { return $token($dmw($regml(1)),$calc(2* $regml(2)),32) }
}
alias min {
  if ($istok(whip blood ice dh cbow guth,$1,32)) { return $token($dmw($1),1,32) }
  elseif ($regex($1,/^(?:(dds|msb|dbow)([12])|(gmaul)([123]))$/i)) { return $token($dmw($regml(1)),$calc(2* $regml(2) -1),32) }
}
alias ifwep { return $token($dmw($1),-1,32) }
on *:DIALOG:DMwep:sclick:77-80: {
  dialog -m $dmid($did($did)) $dmid($did($did))
  dialog -x $dname
}
on $*:TEXT:/^[!.@]dmwea?p(ons?)? /Si:#: {
  if ($wildsite = $address($me,2)) {
    if ($4 != $null) {
      if ($regex($2-,/^(whip|blood|cbow|dh|guth|ice) max \d+$/i)) { 
        dmw $2 $min($2) $4 $ifwep($2) 
        notice $nick [DM] $2 $+ 's max is now $max($2)
      }
      elseif ($regex($2-,/^(whip|blood|cbow|dh|guth|ice) min \d+$/i)) { 
        dmw $2 $4 $max($2) $ifwep($2)
        notice $nick [DM] $2 $+ 's min is now $min($2)
      }
      elseif ($regex($2-,/^(dds|dbow|gmaul|msb)1 max \d+$/i)) { 
        dmw $2 $min($2) $4 $token($dmw($regml(1)),3-,32) 
        notice $nick [DM] $2 $+ 's max is now $max($2)
      }
      elseif ($regex($2-,/^(dds|dbow|gmaul|msb)1 min \d+$/i)) { 
        dmw $2 $4 $max($2) $token($dmw($regml(1)),3-,32)
        notice $nick [DM] $2 $+ 's min is now $min($2)
      }
      elseif ($regex($2-,/^(dds|dbow|gmaul|msb)2 max \d+$/i)) { 
        dmw $regml(1) $token($dmw($regml(1),1-2,32) $min($2) $4 $token($dmw($regml(1)),5-,32) 
        notice $nick [DM] $2 $+ 's max is now $max($2)
      }
      elseif ($regex($2-,/^(dds|dbow|gmaul|msb)2 min \d+$/i)) { 
        dmw $regml(1) $token($dmw($regml(1),1-2,32) $4 $max($2) $token($dmw($regml(1)),5-,32) 
        notice $nick [DM] $2 $+ 's min is now $min($2)
      }
      elseif ($regex($2-,/^gmaul3 max \d+$/i)) { 
        dmw gmaul $token($dmw(gmaul),1-4,32) $min(gmaul3) $4 $ifwep(gmaul) 
        notice $nick [DM] $2 $+ 's max is now $max($2)
      }
      elseif ($regex($2-,/^gmaul3 min \d+$/i)) { 
        dmw gmaul $token($dmw(gmaul),1-4,32) $4 $max(gmaul3) $ifwep(gmaul) 
        notice $nick [DM] $2 $+ 's min is now $min($2)
      }
    }
    elseif ($istok(on off,$3,32)) { 
      dmw $2 $token($dmw($2),1- $+ $calc($numtok($dmw($2),32) -1),32) $replace($3,on,$true,off,$false) 
      notice $nick [DM] $2 can now $iif($3 = off,not) be used in DMs
    }
  }
}
dialog dmset {
  title "DM Settings v1.0"
  size -1 -1 176 135
  option dbu
  box "Access Commands", 1, 4 4 66 34
  radio "Owner", 2, 20 13 29 10
  radio "Admin", 3, 20 24 27 10
  box "Beginning Timer", 4, 4 44 66 41
  check "Enabled", 5, 9 53 50 10
  edit "", 6, 8 68 15 10, disable center
  text "seconds", 7, 27 70 25 8, disable
  box "In-Match Timer", 8, 4 91 66 41
  check "Enabled", 9, 9 100 50 10
  edit "", 10, 8 115 15 10, disable center
  text "seconds", 11, 27 117 25 8, disable
  box "Hpbar", 12, 80 5 47 25
  check "Enabled", 13, 86 14 34 10
  box "# of Barrages", 14, 80 65 47 26
  edit "", 15, 94 45 16 10, center
  edit "", 17, 94 75 16 10, center
  box "# of Sharks", 16, 80 35 47 26
  box "Colors", 18, 80 96 47 36
  text "c1", 19, 84 105 10 8
  text "c2", 20, 84 119 10 8
  edit "", 21, 101 103 14 10, center
  edit "", 22, 101 118 14 10, center
  button "Admin", 23, 138 8 28 9
  button "Updates", 24, 138 19 28 9
  button "Channels", 25, 138 30 28 9
  button "Weapons", 26, 138 41 28 9
  button "Save", 27, 139 80 30 10
  button "Exit", 28, 139 96 30 10, cancel
  button "Default", 29, 139 112 30 10
}
on *:DIALOG:dmset:sclick:5,9: {
  var %d did $iif($did($did).state,-e,-b) dmset
  if ($did = 5) %d 6-7
  else %d 10-11
}
on *:DIALOG:DMset:sclick:23-26: {
  dialog -m $dmid($did($did)) $dmid($did($did))
  dialog -x $dname
}
on *:DIALOG:dmset:sclick:27: { dmset }
on *:DIALOG:dmset:init:0: {
  did -c dmset $iif($dms(set),2,3)
  if ($dms(timeout[st])) {
    did -c dmset 5
    did -e dmset 6-7
  }
  if ($dms(timer[st])) {
    did -c dmset 9
    did -e dmset 10-11
  }
  did -a dmset 6 $dms(timer)
  did -a dmset 10 $dms(timeout)
  if ($dms(hpbar)) { did -c dmset 13 }
  did -a dmset 15 $dms(sharks)
  did -a dmset 17 $dms(barrage)
  did -a dmset 21 $dms(c1)
  did -a dmset 22 $dms(c2)
}
on *:DIALOG:dmset:close:0: { dmset }
on *:DIALOG:dmset:sclick:29: {
  if ($?!="Are you sure you would like to restore all settings to default?") { 
    dialog -x dmset
    dmset 
    dialog -m dmset dmset
  } 
}
alias dmset {
  if ($dialog(dmset)) {
    dms set $iif($did(dmset,2).state,owner,admin)
    dms timer[st] $iif($did(dmset,5).state,$true,$false)
    dms timer $iif($did(dmset,6),$v1,30)
    dms timeout[st] $iif($did(dmset,9).state,$true,$false)
    dms timeout $iif($did(dmset,10),$v1,60)
    dms hpbar $iif($did(dmset,13).state,$true,$false)
    dms sharks $iif($did(dmset,15),$v1,5)
    dms barrage $iif($did(dmset,17),$v1,6)
    dms c1 $iif($did(dmset,21),$right(0 $+ $v1,2),14)
    dms c2 $iif($did(dmset,22),$right(0 $+ $v1,2),10)
  }
  else {
    dms set owner
    dms chans $true
    dms timer[st] $false
    dms timer 30
    dms timeout[st] $false
    dms timeout 60
    dms hpbar $false
    dms shark 5
    dms barrage 6
    dms c1 14
    dms c2 10
  }
  hsave dm dm.txt
}
dialog dmadmin {
  title "DM Admins v1.0"
  size -1 -1 289 137
  option dbu
  list 1, 10 18 198 88, size vsbar
  box "Admin List (Nick!User@Host)", 2, 4 5 213 124
  box "Add", 3, 224 5 61 38
  edit "", 4, 229 13 50 10, autohs center
  button "Add", 5, 236 27 33 9
  button "Remove", 6, 88 113 33 9
  button "Settings", 7, 238 52 32 9
  button "Updates", 8, 238 63 32 9
  button "Weapons", 9, 238 74 32 9
  button "Channels", 10, 238 85 32 9
  button "Exit", 11, 237 111 33 10, cancel
}
on *:DIALOG:DMadmin:sclick:7-10 {
  dialog -m $dmid($did($did)) $dmid($did($did))
  dialog -x $dname
}
on *:DIALOG:dmadmin:sclick:5: {
  if ($address($did(4),5) && !$admin($did(4))) {
    hadd -m dma $address($did(4),5)
    adminupd
    did -r dmadmin 4
  }
  elseif ($admin($did(4))) { noop $input($qt($did(4)) is already an admin,oi,Already Admin,,) }
  elseif (!$address($did(4),5)) {
    noop $input(No such user $qt($did(4)) $+ . Trying to retrieve address; try in a few seconds,ow,No User,,)
    whois $did(4)
  }
}
on *:DIALOG:dmadmin:sclick:6: {
  hdel dma $$did(1).seltext
  adminupd
}
on *:DIALOG:dmadmin:init:0: { adminupd }
alias adminupd {
  noop $$dialog(dmadmin)
  did -r dmadmin 1
  var %x 1
  while ($hget(dma,%x).item) {
    did -a dmadmin 1 $v1
    inc %x
  }
}
alias uhost {
  noop $regex($1,/^([^!@]+)$|^(.+)!/U)
  var %user $regml(1)
  noop $regex($1,/^[^!]+!([^@]+)$|([^@!]+)@/)
  var %ident $regml(1)
  noop $regex($1,/@(.+)$/)
  var %host $regml(1)
  return $+($iif(%user,$v1,*),!,$iif(%ident,$v1,*),@,$iif(%host,$v1,*))
}
on $*:TEXT:/^[!.@](add|(rem(ove)?|del(ete)?))(admin|staff) /Si:#: { 
  if ($regml(1) = add) { 
    if (!$address($2,5)) { 
      notice $nick [DM] $2 has to be online for you to add admins. 
      whois $2
      halt 
    }
    if ($wildsite = $address($me,2) && !$admin($$2)) { 
      hadd -m dma $address($2,5) $true 
      hsave dma dma.txt 
      notice $nick [DM] $2 added to the admin list 
    } 
    elseif ($wildsite = $address($me,2) && $admin($2)) { notice $nick [DM] $2 is already an admin. } 
    else notice $nick [DM] You do not have sufficient access to add/remove admins. 
  }
  else { 
    if (!$address($2,5)) {
      notice $nick [DM] $2 has to be online for you to remove admins. 
      whois $2
      halt 
    }
    if ($wildsite = $address($me,2) && $admin($$2)) { 
      var %x 1,%a $iif($address($2,2),$v1,$uhost($2))
      while ($hget(dma,%x).item) {
        if (%a iswm $v1) {
          hdel dma $v2
          dec %x
        }
        inc %x
      }
      notice $nick [DM] $2 removed from the admin list. 
      hsave dma dma.txt 
    } 
    elseif ($wildsite = $address($me,2) && !$admin($$2)) { notice $nick [DM] $2 is not an admin. } 
  else notice $nick [DM] You do not have sufficient access to add/remote admins. } 
} 
alias admin {
  var %x 1,%a $iif($address($2,2),$v1,$uhost($1))
  while ($hget(dma,%x).item) {
    if (%a iswm $v1) return $true
    inc %x
  }
  return $false
}
on $*:TEXT:/^[!.@](admin|staff)list$/Si:#: {
  if ($wildsite = $address($me,2)) {
    if (!$hget(dma,1).item) { notice $nick [DM] There are no admins in the list right now }
    else {
      var %x 1
      notice $nick [DM] Admin list- (Nick!User@Host)
      while ($hget(dma,%x).item) {
        notice $nick [DM] %x - $v1
        inc %x
      }
    }
  }
}