mIRC Homepage

Bet + Death script

Posted By: Newbie

Bet + Death script - 09/03/15 02:24 AM

This works and all but I was wondering if there's anything I could improve about it?

Code:
alias deathcounter {
  if (%killer == gravity) {
    hadd -m death gravity $calc($hget(death,gravity) + 1)
  }
  elseif (%killer == SE) {
    hadd -m death SE $calc($hget(death,SE) + 1)
  }
  elseif (%killer == invader) {
    hadd -m death invader $calc($hget(death,invader) + 1)
  }
  else {
    hadd -m death boss $calc($hget(death,boss) + 1)
  }
  unset %killer
}

on *:TEXT:!deathcount &:#: {
  if ((%flooddeath) || ($($+(%,flooddeath.,$nick),2))) { return }
  set -u10 %flooddeath On
  set -u60 %flooddeath. $+ $nick On
  if ($2 == gravity) {
    msg # Newbie has died $hget(death,gravity) time(s) to GRAVITY. 
  }
  elseif ($2 == SE) {
    msg # Newbie has died $hget(death,SE) time(s) to STANDARD ENEMIES.
  }
  elseif ($2 == invader) {
    msg # Newbie has died $hget(death,invader) time(s) to INVADERS.
  }
  elseif ($2 == boss) {
    msg # Newbie has died $hget(death,boss) time(s) to BOSSES.
  }
  elseif ($2 == total) {
    msg # Newbie has died a total of $calc($hget(death,gravity) + $hget(death,SE) + $hget(death,invader) + $hget(death,boss))
  }
  elseif ($2 == end) {
    if ($mod($nick,#)) {
      hfree death 
      write -c deathcounnter.ini
      msg # Death Counter has been reset. 
    }
    else {
      msg # This command is for mods only.
    }
  }
  elseif ($2 == save) {
    if ($mod($nick,#)) {
      hsave -ia death deathcounter.ini
      msg # The death counter has been saved for future runs
    }
    else {
      msg # This command is for mods only.
    }
  }
  elseif ($2 == load) {
    if ($mod($nick,#)) {
      hmake death
      hload -i death deathcounter.ini
      msg # The death counter has now been loaded and has a total of $calc($hget(death,gravity) + $hget(death,SE) + $hget(death,invader) + $hget(death,boss))
    }
    else {
      msg # This command is for mods only.
    }
  }
  else {
    msg # Sorry we are not keeping track of $2. Please try typing --> !deathcount boss/invader/gravity/SE.
  }
}

on *:TEXT:!bet *:#: {
  if (!%firstdeath) {
    if (!%bet) {
      if ($2 isnum) {
        var %dinocoins $readini(Dinocoins.ini,$+(#,.,$nick),dinocoins)
        var %subtraction $calc(%dinocoins - $2)
        if (%subtraction < 0) { msg # Sorry $nick you don't have enough dinocoins. }
        elseif ($2 < 0) { msg # You can't bet negative dinocoins. }
        elseif ($0 < 3) { msg # To bet type --> !bet boss dinocoins <-- }
        else {
          var %included $hget(bet,$3)
          var %participating $hget(participants,bet)
          hadd -m bet $3 %included $+ , $+ $nick
          hadd -m dinocoins $nick $2
          hadd -m participants bet %participating $+ , $+ $nick
          writeini -n Dinocoins.ini $+(#,.,$nick) dinocoins %subtraction 
        } 
      }
      elseif ($2 == allin) {
        if ($0 < 3) { msg # To bet type --> !bet boss dinocoins <-- }
        else {
          var %dinocoins $readini(Dinocoins.ini,$+(#,.,$nick),dinocoins)
          var %included $hget(bet,$3)
          var %participating $hget(participants,bet)
          hadd -m bet $3 %included $+ , $+ $nick 
          hadd -m dinocoins $nick %dinocoins
          hadd -m participants bet %participating $+ , $+ $nick
          writeini -n Dinocoins.ini $+(#,.,$nick) dinocoins 0
        }
      }
      elseif ($2 == stop) {
        if ($0 < 3) { msg # To stop bets type --> !bet stop bossname <-- }
        else {
          set %bet 1
          msg # /me Bets have been stopped by $nick for boss $3
        }
      }
    }
    elseif (%bet == 1) {
      if ($2 == continue) {
        if ($0 < 3) { msg # To resume bets type --> !bet continue bossname <-- }
        else {
          msg # /me Bets have resumed thanks to $nick $+ , the boss $3 has been slain.
          hdel bet $3
          unset %bet 
        }
      }
      else {
        msg # /me Bets have been stopped, but will resume once this boss is defeated. 
      }
    }
    if ($2 == close) {
      if ($mod($nick,#)) {
        if ($0 < 3) { msg # To close bets type --> !bet close bossname <-- }
        else {
          unset %bet
          var %winners $gettok($hget(bet,$3),0,44)
          var %i %winners
          while (%winners) {
            var %winner $gettok($hget(bet,$3),%winners,44)
            var %wins %wins %winner
            var %dinocoins $hget(dinocoins,%winner)
            if (%roll_bet != $null) {
              var %multiplier $calc((%roll_bet * (%dinocoins / %i)) + %dinocoins)
              writeini -n Dinocoins.ini $+(#,.,%winner) dinocoins $calc($readini(Dinocoins.ini,$+(#,.,%winner),dinocoins) + %multiplier)
            }
            else {
              var %multiplier $calc(%dinocoins + (%dinocoins / %i))
              writeini -n Dinocoins.ini $+(#,.,%winner) dinocoins $calc($readini(Dinocoins.ini,$+(#,.,%winner),dinocoins) + %multiplier)
            }
            dec %winners
          }
        }
      }
      else { msg # This command is for mods only }
      msg # The winner(s) are: %wins 
      set %killer $3
      deathcounter
      hfree bet
      hfree dinocoins
      hfree participants
    }  
  }
  else {
    msg # First death is open, bets cannot be placed at this time. 
  }
}


Commands

!bet currency boss --> Bets a set amount, saying that I will die to said boss

!bet allin boss --> Bets all currency.

!bet stop boss --> Stops the betting

!bet continue boss --> Continues the bet

!bet close boss --> Closes the bet according to the boss that just killed me and gives currency depending on how much you wagered. Also triggers the death counter

!deathcount boss/invader/gravity/SE --> Says the number of deaths according the bets close command.

Just wondering if there's anyway to improve the script?
Oh and thanks Nillen for the help with the first death script.
© 2019 mIRC Discussion Forums