;tinybrak v1.6


;Change charactername, password, and networkname below to your info.

alias -l MyChar return charactername
alias -l MyPass return password
alias -l playnet return networkname


;Bets and Fights, RussRelay used by default. If you want to use SReject's scripts change russ below to sr

alias -l bets return russ
alias -l fights return russ


;Default alignment is human. Change human below to priest or undead if desired

alias -l align return human


; -  -  -  -  -  -  -  -  -  -  -  -  -


alias -l bets2 {
  if ($bets == russ) .msg russrelay !bestbet
  if ($bets == sr) .timer 5 0 msg %Gbot bet $ShortBestBet 100
}

alias -l fights2 {
  if ($fights == russ) .msg russrelay !bestfight $MyChar
  if ($fights == sr) {
    set %tb-opp $mybestfight($MyChar)
    if (%tb-opp != $null) .timer 5 0 msg %Gbot fight %tb-opp
  }
}

alias -l attack {
  if ((%tblvlup == $null) && ($align != priest)) .msg %Gbot align priest
  msg %Gbot attack $creep
  if ((%tblvlup == $null) && ($align != priest)) .timer 1 2 .msg %Gbot align $align
}

alias -l challenge {
  if ((%tblvlup == $null) && ($align != priest)) .msg %Gbot align priest
  msg %Gbot challenge
  if ((%tblvlup == $null) && ($align != priest)) .timer 1 2 .msg %Gbot align $align
}

alias -l slay {
  if ((%tblvlup == $null) && ($align != priest)) .msg %Gbot align priest
  msg %Gbot slay $monster
  if ((%tblvlup == $null) && ($align != priest)) .timer 1 2 .msg %Gbot align $align
}

alias -l lvlup {
  if (%tblevel >= 35) msg %Gbot challenge
  if (%tblevel >= 16) fights2
  unset %tblvlup
  if ($align != priest) .timer 1 60 .msg %Gbot align $align
}


;when saving the file you might get a warning about initialization commands. it's due to the on load event below

on 1:LOAD:{
  auser russrelay russrelay!*@*
  if ($playnet == Undernet) {
    auser tb-gamebot idlerpg*!*multirpg@*
    set %Gbot idlerpg
    set %gamechan #idlerpg
    .timer 1 60 .msg %Gbot rawstats2
  }
  if ($playnet != Undernet) {
    auser tb-gamebot multirpg*!*multirpg@*
    set %Gbot multirpg
    set %gamechan #multirpg
    .timer 1 60 .msg %Gbot rawstats2
  }
}

on 1:CONNECT:{
  if ($network == $playnet) {
    .timer 1 60 join %gamechan
    .timer 1 80 .msg %Gbot rawstats2
  }
}

alias -l creep {
  if (%tblevel < 10) return
  if (%tblevel == 10) return Bush
  if (%tblevel < 16) return Locust
  if (%tblevel < 21) return Spider
  if (%tblevel < 31) return Goblin
  if (%tblevel < 41) return Lich
  if (%tblevel < 44) return Skeleton
  ;if (%tblevel < 61) return Ghost
  if (%tblevel < 71) return Shadow
  ;if (%tblevel < 81) return Troll
  ;if (%tblevel < 91) return Cyclops
  ;if (%tblevel < 101) return Mutant
  if (%tblevel < 111) return Monkey
  ;if (%tblevel < 121) return Phoenix
  ;if (%tblevel < 131) return Minotaur
  if (%tblevel < 141) return Beholder
  if (%tblevel < 151) return Wyvern
  if (%tblevel < 999) return Ogre
}

alias -l monster {
  if (%tbsum >= 6500) return Hippogriff
  if (%tbsum >= 6000) return Sphinx
  if (%tbsum >= 5500) return Dragon
  if (%tbsum >= 5000) return Vampire
  if (%tbsum >= 4500) return Mammoth
  if (%tbsum >= 4000) return Centaur
  if (%tbsum <= 3999) return Medusa
}

alias -l randitem return $gettok(ring amulet charm weapon helm tunic gloves shield leggings boots,$rand(1,10),32)

alias -l ttl {
  if (%tblevel < 40) return 14400
  if (%tblevel < 50) return 18000
  if (%tblevel < 60) return 21600
  if (%tblevel < 70) return 25200
  if (%tblevel < 80) return 28800
  if (%tblevel < 90) return 32400
  if (%tblevel < 999) return 36000
}

;rawstats2 event
on tb-gamebot:TEXT:*challengettl*:?:{
  if ($network == $playnet) {
    set %tblevel $2
    set %tbsum $10
    set %tbbet $14
    set -u0 %tta $22
    set -u0 %ttc $24
    set -u0 %tts $26
    set %tbttl $28
    set %tbherolevel $32
    set %tbengineerlevel $36
    if (%tblevel >= 10) .timertb-tta 1 %tta attack
    if (%tblevel >= 35) .timertb-ttc 1 %ttc challenge
    if (%tblevel >= 40) .timertb-tts 1 %tts slay
  }
}

on tb-gamebot:TEXT:$($MyChar $+ $chr(44) * has attained*):%gamechan:{
  if ($network == $playnet) {
    .timertb* off
    set %tblevel $remove($strip($gettok($1-,$calc($findtok($strip($1-),level,1,32) + 1),32)),!)
    if (%tblevel > 16) set %tblvlup on
    if (($align != priest) && (%tblevel > 16)) msg %Gbot align priest
    set %tbdepositpause on
    .timer -o 1 90 unset %tbdepositpause
    unset %tbttl
    if (%tblevel >= 10) attack
    if (%tblevel == 15) .msg %Gbot load power 0
    if (%tblevel >= 30) {
      set %tbbet 0
      .timer 1 25 .msg %Gbot bank withdraw all
      .timer 1 32 bets2
      .timer 1 45 .msg %Gbot bank deposit all
    }
    if (%tblevel >= 40) .timer 1 15 slay
    if (%tblevel < 30) .timer 1 25 .msg %Gbot bank deposit all
    if ((%tbherolevel != 9) && (%tblevel >= 17)) .timer 1 80 .msg %Gbot rawstats2
    if (%tblevel >= 16) .timer 1 95 .msg %Gbot bank
  }
}

on tb-gamebot:NOTICE:You can attack again in*:?:{
  if ($network == $playnet) {
    set -u0 %attacktime $duration($8)
    .timertb-tta 1 %attacktime attack
  }
}

on tb-gamebot:TEXT:$($MyChar $+ $chr(44) * (manual challenge)):%gamechan:{
  if ($network == $playnet) {
    .timertb-ttc 1 10800 challenge
  }
}

on tb-gamebot:TEXT:$($MyChar $+ $chr(44) *has tried to slay*):%gamechan:{
  if ($network == $playnet) {
    .timertb-tts 1 86400 slay
  }
}

on tb-gamebot:TEXT:$($MyChar $+ $chr(44) *has attacked a*):%gamechan:{
  if (($network == $playnet) && (%tbherolevel == 9)) {
    if (($14 == killed) && ($29 == 0)) set %tbttl $calc($duration($31))
    if (($14 == lost!) && ($28 == 0)) set %tbttl $calc($duration($30))
  }
}

on tb-gamebot:TEXT:$($MyChar has won the Champion*):%gamechan:{
  if ($network == $playnet) {
    set %tbdepositpause on
    set %tbbet 0
    .timer 1 10 bets2
    .timer 1 25 .msg %Gbot bank deposit all
    .timer 1 26 unset %tbdepositpause
    .timer 1 26 .msg %Gbot bank
  }
}

on tb-gamebot:TEXT:$($MyChar * gold*):%gamechan:{
  if (($network == $playnet) && (%tbdepositpause == $null)) {
    .msg %Gbot bank deposit all
    if (%tblevel >= 16) .msg %Gbot bank
  }
}

on tb-gamebot:TEXT:You have * gold in the bank*:?:{
  if (($network == $playnet) && (%tbdepositpause == $null)) {
    set -u0 %bankgold $3
    if ((%tblevel >= 30) && (%tbbet < 5) && (%bankgold >= 120)) {
      .timer 1 5 .msg %Gbot bank withdraw all
      .timer 1 10 bets2
      .timer 1 30 .msg %Gbot bank deposit all
      .timer 1 32 .msg %Gbot bank withdraw 20
      if (%tblvlup == on) .timer 1 40 lvlup
    }
    elseif ((%tbherolevel == 9) && (%tbttl < $ttl)) .msg %Gbot bank withdraw 20
    else {
      if ((%tbengineerlevel < 9) && (%bankgold >= 2820) && (%tblevel >= 18)) {
        .msg %Gbot bank withdraw 2820
        .timer 1 2 msg %Gbot hire engineer
        .timer 1 5 .timer 9 2 .msg %Gbot engineer level
        if (%tblvlup == on) .timer 1 35 lvlup
        halt
      }
      if ((%tbengineerlevel == 9) && (%tbherolevel < 9) && (%bankgold >= 2820)) {
        .msg %Gbot bank withdraw 2820
        .timer 1 2 msg %Gbot summon hero
        .timer 1 5 .timer 9 2 .msg %Gbot hero level
        if (%tblvlup == on) .timer 1 35 lvlup
        if (%tblevel > 33) .timer 1 60 .msg %Gbot rawstats2
        halt
      }
      if ((%tbherolevel == 9) && (%bankgold >= 40) && (%tbbet == 5)) {
        .msg %Gbot bank withdraw all
        .msg %Gbot upgrade $randitem $int($calc((%bankgold - 20) / 20))
        if (%tblvlup == on) .timer 1 5 lvlup
      }
      elseif (%tblevel >= 16) {
        .msg %Gbot bank withdraw 20
        if (%tblvlup == on) .timer 1 5 lvlup
      }
    }
  }
}

on russrelay:NOTICE:Best fight*:?:{
  if ($network == $playnet) {
    if ($strip($6) == $MyChar) .timerfighttb 5 0 msg %Gbot fight $strip($11)
  }
}

on russrelay:NOTICE:Best bet*:?:{
  if (($network == $playnet) && (%tbbet < 5)) .timerbettb $calc(5 - %tbbet) 0 msg %Gbot bet $strip($8) $strip($15) 100
}

on tb-gamebot:TEXT:* has made a BET*:%gamechan:{ 
  if (($network == $playnet) && ($strip($1) == $MyChar)) inc %tbbet 1
}

on tb-gamebot:TEXT:*You are not logged in*:?:{
  if ($network == $playnet) .msg %Gbot login $MyChar $MyPass
  .timer 1 60 .msg %Gbot rawstats2
}

on tb-gamebot:TEXT:Next Event*:%gamechan:{
  if ($network == $playnet) set %Gbot $nick
}

on tb-gamebot:NICK:{
  if ($network == $playnet) && (($newnick isop %gamechan) || ($newnick ishop %gamechan)) {
    set %Gbot $newnick
  }
}

alias -l gamebot {
  .timertb-gb1 1 120 gamebot2
  .timertb-gb2 1 3610 gamebot2
}

alias -l gamebot2 .msg %Gbot rawstats2

on tb-gamebot:JOIN:%gamechan:{
  if ($network == $playnet) {
    gamebot
    if (($nick isop %gamechan) || ($nick ishop %gamechan)) {
      set %Gbot $nick
      gamebot
    }
  }
}

on *:OP:%gamechan:{
  if ($network == $playnet) {
    if ((%gamechan == #multirpg) && (multirpg isin $opnick)) {
      set %Gbot $opnick
      gamebot
    }
    if ((%gamechan == #idlerpg) && (idlerpg isin $opnick)) {
      set %Gbot $opnick
      gamebot
    }
  }
}

on *:HELP:%gamechan:{
  if ($network == $playnet) {
    if ((%gamechan == #multirpg) && (multirpg isin $hnick)) {
      set %Gbot $hnick
      gamebot
    }
    if ((%gamechan == #idlerpg) && (idlerpg isin $hnick)) {
      set %Gbot $hnick
      gamebot
    }
  }
}

on tb-gamebot:TEXT:*automatically logged in*:%gamechan:{
  if ($strip($4) == $playnet) {
    set %Gbot $nick
    gamebot
  }
}

alias -l stopmsg return Stop command received from gamebot. Game timers stopped and script unloaded. See notes in the readme file
alias -l wrongpass return Wrong password entered. Game timers stopped and script unloaded. See notes in the readme file

on tb-gamebot:TEXT:stop:?:{
  if ($network == $playnet) {
    .timertb* off
    unset %tbdepositpause
    echo %Gbot $stopmsg
    echo -a $stopmsg
    echo -s $stopmsg
    unload -rs $qt($script)
  }
}

on tb-gamebot:NOTICE:Wrong password.:?:{
  if ($network == $playnet) {
    .timertb* off
    unset %tbdepositpause
    echo %Gbot $wrongpass
    echo -a $wrongpass
    echo -s $wrongpass
    unload -rs $qt($script)
  }
}

on tb-gamebot:TEXT:*Game Reset!*:%gamechan:{
  if ($network == $playnet) {
    .timertb* off
    unset %tbdepositpause
    if ($align != priest) .timer 1 10 .msg %Gbot align priest
    .timer 1 30 .msg %Gbot rawstats2
    .timer 1 40 .msg %Gbot bank deposit all
    .timer -o 1 300 set %tblvlup on
  }
}
