Page 1 of 1

Botscript / afstemning / vote script

PostPosted: Wed Feb 20, 2008 8:14 pm
by Cristian
Vote script for mirc

!vote start - enables the script, pay attension to the seperator (.) Example: !vote start (vote about) . subject1 . subject2 . subject3
!vote - makes a vote. Example: !vote number1 or number2 or number3
!votestatus - gives a overview of the vote.
!stopvote - stops the vote, and resets all information.
the seperator i currently <.> and can be changes i the alias called 'vote.seperator'

Tested and works on version 6.15

Code: Select all
;# 
;# visit http://sp00fed.org for updates or support.
;# script by Sumsar
;#

alias -l vote.seperator { return $asc(.) }
alias -l vote.db { return vote.txt }


on *:TEXT:!vote start *:#: {
  if ($nick isop $chan) {
    if ($eval($+(!%,vote.,$chan),2)) {
      .remove $vote.db
      set $+(%,vote.,$chan) on

      set $+(%,vote.,$chan,.test) $1-

      set $+(%,vote.,$chan,.info) Vote started by $nick - $date - $time
      set $+(%,vote.,$chan,.afstemning) $gettok($3-,1,$vote.seperator)
      set $+(%,vote.,$chan,.muligheder) $calc($numtok($3-,$vote.seperator) - 1)

      var %z = $eval($+(%,vote.,$chan,.muligheder),2),%x = 1
      while (%x <= %z) {
        set $+(%,vote.,$chan,.bud.,%x) $gettok($3-,$calc(%x + 1),$vote.seperator)
        set %text %text $+($chr(2),%x,.,$chr(2)) $gettok($3-,$calc(%x + 1),$vote.seperator)
        inc %x
      }
      msg $chan $+($chr(2),Vote,$chr(2)): $eval($+(%,vote.,$chan,.afstemning),2)
      msg $chan %text / Use !vote (number) to vote!
      .unset %text
    }
  }
}
on *:TEXT:!vote *:#: {
  if ($eval($+(%,vote.,$chan),2) == on) {
    var %x = $eval($+(%,vote.,$chan,.muligheder),2)
    while (%x) { var %t =  $addtok(%t,%x,46) | dec %x }

    if ($2 isnum) && ($istok(%t,$2,46)) {
      if (!$read($vote.db,w,$address($nick,1))) {
        .write $vote.db $address($nick,1)

        .inc $+(%,vote.,$chan,.incr.,$2)
        .notice $nick You have voted $2 $eval($+(%,vote.,$chan,.bud.,$2),2)
      }
    }
    else { .notice $nick Your vote is invalid. Use: !vote $replace($sorttok(%t,46,n),$chr(46),$chr(32)) }

  }
}


on *:TEXT:!votestatus:#: {
  if ($eval($+(%,vote.,$chan),2) == on) {
    var %z = $eval($+(%,vote.,$chan,.muligheder),2),%x = 1

    while (%x <= %z) {
      set %text %text $+($chr(2),%x,.,$chr(2)) ( $+ $iif($eval($+(%,vote.,$chan,.incr.,%x),2),$ifmatch,0) $+ ) $eval($+(%,vote.,$chan,.bud.,%x),2)
      set $+(%,vote.,$chan,.total) $calc($+(%,vote.,$chan,.total) + $+(%,vote.,$chan,.incr.,%x))
      inc %x
    }
    .msg $chan $+($chr(2),Vote,$chr(2),:) $eval($+(%,vote.,$chan,.afstemning),2) - The scores is currently: %text - Votes total: $eval($+(%,vote.,$chan,.total),2)
    .unset $+(%,vote.,$chan,.total) %text
  }
}
on *:text:!stopvote:#: {

  if ($eval($+(%,vote.,$chan),2) == on) {
    if ($nick isop $chan) {
      unset %vote. [ $+ [ $chan ] ] $+ *
      .msg $chan $+($chr(2),Vote,$chr(2),:) The vote is now deactivated and all data has been deleted!
      .remove $vote.db
    }
  }
}