;;;;Buzz-Zyrus SoulFly Multi-Gamer by d33j4y™  ©2010 EvolutionScriptz d0t c0m;;;;
;;;;;;;;;;;;Evolution Scriptz Website http://www.evolutionscriptz.com;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;Advertisement Dialog by Travis;;;;;;;;;;;;;;;;;;;;;;;;;;

on *:unload:remini soulfly.ini version $nopath($script)
on *:start:writeini soulfly.ini version $nopath($script) 4.1
alias f8 adv
alias sf8 adv_chk
menu channel {
  -
  Advertiser
  .Open Advertiser:Adv
  .-
  .Check Active Advertisements:Adv_chk
  -
}
alias adv {
  if (%adv_c) dialog $iif($dialog(sf_advert),-v,-mh) sf_advert sf_advert
  else {
    set %adv_chan $chan
    dialog $iif($dialog(sf_advert),-v,-mh) sf_advert sf_advert
  }
}
dialog sf_advert {
  title "Advertising Options"
  size -1 -1 220 102
  option dbu
  icon %tbar
  icon 1, 109 -4 144 18, imgs\sf1.jpg, 1, noborder
  combo 2, 2 12 90 60, drop size edit
  combo 3, 96 12 27 60, drop size
  edit "", 4, 2 40 216 60, multi vsbar autovs return
  text "Frequency in minutes", 5, 129 12 27 16, wrap
  edit "", 6, 157 12 22 13, autohs limit 4
  combo 7, 183 28 35 60, drop size
  text "Message Type", 8, 183 19 35 7
  button "Set Ad", 9, 2 27 38 12
  button "Delete", 11, 44 27 38 12
  button "", 10, 86 27 38 12
  button "Check All", 12, 128 27 48 12
  text "", 98, 217 0 3 10
  text "", 97, 29 0 116 10
  text "", 96, 0 0 2 10
  button "Close", 100, 2 -2 27 13
}
on *:dialog:sf_advert:init:*:{
  did -f $dname 1 | did -b $dname 9,10,11
  mdx_head
  xmdx SetDialog sf_advert bgcolor $rgb(255,255,255)
  xmdx SetColor sf_advert 5,8 background $rgb(255,255,255)
  xmdx SetColor sf_advert 5,8 textbg $rgb(255,255,255)
  xmdx SetColor sf_advert 96,97,98,100 background $rgb(224,223,228)
  xmdx SetColor sf_advert 96,97,98 textbg $rgb(224,223,228)
  xmdx SetFont sf_advert 9,10,11,12,100 24 500 Trebuchet MS Bold
  xmdx SetFont sf_advert 2,3,4,6,97 14 500 Tahoma
  did -ra sf_advert 97 $str($chr(160),3) $v_ $chr(160) Advertiser
  if (%adv_c) {
    did -ca sf_advert 2 %adv_c
    adv_2 | adv_3
    did -c sf_advert 3 $calc(%adv_i + 1)
    did -ra sf_advert 6 $gettok($readini(lists\adv.ini,%adv_c,%adv_i),1,32)
    did -cra sf_advert 7 $gettok($readini(lists\adv.ini,%adv_c,%adv_i),2,32)
    did -ca sf_advert 7 $iif($gettok($readini(lists\adv.ini,%adv_c,%adv_i),2,32) = msg,action,msg)
    did -ra sf_aDVERT 4 $gettok($readini(lists\adv.ini,%adv_c,%adv_i),3-,32)
    unset %adv_*
    did -e $dname 11
    did -era $dname 10 Stop
  }
  else {
    if (%adv_chan != $null) did -ca sf_advert 2 $ifmatch
    adv_2 | adv_3
    didtok $dname 7 44 msg,action
    did -c $dname 3 1
    did -c $dname 7 1
  }
}
on *:dialog:sf_advert:sclick:*:{
  if ($did = 100) { unset %adv_chan | dialog -x $dname $dname }
  elseif ($did = 2) {
    adv_3
    did -b $dname 9 | did -r $dname 4,6
    if ($did(3) = 1) {
      did -e $dname 10 | did -ra sf_advert 10 $iif($timer($+($did(2),$did(3))),Stop,Start)
      did -ra sf_advert 6 $gettok($readini(lists\adv.ini,$did(2),$did(3)),1,32)
      did -cr sf_advert 7
      didtok sf_advert 7 32 $gettok($readini(lists\adv.ini,$did(2),$did(3)),2,32) $iif($gettok($readini(lists\adv.ini,$did(2),$did(3)),2,32) = msg,action,msg)
      did -ra sf_aDVERT 4 $gettok($readini(lists\adv.ini,$did(2),$did(3)),3-,32)
      did -c sf_advert 7 1
    }
  }
  elseif ($did = 3) {
    did -b $dname 9
    if ($did(3) != New) {
      did -e $dname 11 | did -e $dname 10 | did -ra sf_advert 10 $iif($timer($+($did(2),$did(3))),Stop,Start)
      did -ra sf_advert 6 $gettok($readini(lists\adv.ini,$did(2),$did(3)),1,32)
      did -ra sf_aDVERT 4 $gettok($readini(lists\adv.ini,$did(2),$did(3)),3-,32)
    }
    if ($did(3) = New) {
      did -rb $dname 10 | did -b $dname 9,11
      did -r $dname 4,6 | did -cr sf_advert 7
      didtok sf_advert 7 44 msg,action
      did -c sf_advert 7 1
    }
    else {
      did -cr sf_advert 7
      didtok sf_advert 7 32 $gettok($readini(lists\adv.ini,$did(2),$did(3)),2,32) $iif($gettok($readini(lists\adv.ini,$did(2),$did(3)),2,32) = msg,action,msg)
      did -c sf_advert 7 1
    }
  }
  elseif (($did = 7) && ($did(4)) && ($did(6))) did -e $dname 9
  elseif ($did = 9) {
    did -e $dname 10,11
    did -ra $dname 10 Start
    var %h- = $did(2), %n = $iif($did(3) = New,$calc($ini(lists\adv.ini,%h-,0) + 1),$ifmatch), %6 = $iif($did(6) = $null,1,$did(6))
    writeini lists\adv.ini %h- %n %6 $did(7) $didtok(4,32)
    adv_3 %n
  }
  elseif ($did = 10) {
    var %h- = $did(2)
    if ($did(10) = start) {
      $+(.timer,%h-,$did(3)) 0 $calc($did(6) * 60) /advmsg $did(2) $did(7) $didtok(4,32)
      error -n SoulFly Advertiser $crlf $crlf Advertising for $hget(soulfly,%h-) has begun.
      did -ra $dname 10 Stop
    }
    elseif ($did(10) = stop) {
      $+(.timer,%h-,$did(3)) off
      did -ra $dname 10 Start
      error -n SoulFly Advertiser $crlf $crlf Stopped Advertising Message For $hget(soulfly,%h-)
    }
  }
  elseif ($did = 11) {
    var %n- = $ini(lists\adv.ini,$did(2),0)
    remini lists\adv.ini $did(2) $iif(%n- != 1,$did(3))
    ref_ini $did(2) | did -r $dname 4,6
    adv_2 | adv_3
  }
  elseif ($did = 12) adv_chk
}
on *:dialog:sf_advert:edit:*:{
  if (($did = 4) && ($did(6))) did -e sf_advert 9
  elseif (($did = 6) && ($did(4)) && ($did(6) != $null)) did -e sf_advert 9
  elseif ($did = 2) did -cra $dname 3 New
}
on *:dialog:sf_advert:close:*:unset %adv_chan
alias adv_2 {
  var %2t = $ini(lists\adv.ini,0)
  if (%2t = 0) return
  else {
    var %2i = 1
    while (%2i <= %2t) {
      if ($ini(lists\adv.ini,%2i) != %adv_chan) did -ca sf_advert 2 $ini(lists\adv.ini,%2i)
      inc %2i
    }
  }
  did -c sf_advert 2 1
}
alias adv_3 {
  did -cr sf_advert 3
  var %3t = $iif($ini(lists\adv.ini,$did(sf_advert,2),0),$ifmatch,0), %3i = 1
  if (%3t = 0) did -ca sf_advert 3 New
  did -ca sf_advert 3 New
  while (%3i <= %3t) { did -ca sf_advert 3 %3i | inc %3i }
  did -c sf_advert 3 $iif($1,$calc($1 + 1),1)
}
alias adv_chk dialog $iif($dialog(sf_advert_chk),-v,-m) sf_advert_chk sf_advert_chk
dialog sf_advert_chk {
  title "Active Advertisements"
  size -1 -1 160 77
  option dbu
  icon %tbar
  text "", 100, 0 0 86 10
  text "", 101, 158 0 2 10
  icon 1, 50 -4 144 18, imgs\sf1.jpg, 1, noborder
  button "Close", 2, 2 -2 27 13
  button "Refresh", 4, 38 -1 26 12
  list 3, 1 12 158 80
}
on *:dialog:sf_advert_chk:init:*:{
  did -f sf_advert_chk 1
  mdx_head
  xmdx SetDialog sf_advert_chk bgcolor $rgb(255,255,255)
  xmdx SetFont sf_advert_chk 2 24 500 Trebuchet MS Bold
  xmdx SetFont sf_advert_chk 3,4 16 500 Tahoma
  xmdx SetColor sf_advert_chk 100,101 background $rgb(224,223,228)
  xmdx SetControlMDX $dname 3 ListView nosortheader showsel grid rowselect single labeltip report > dlls\VIEWS.MDX
  did -i $dname 3 1 headerdims 150:1 30:2 130:3
  did -i $dname 3 1 headertext + 0 Room $+ $chr(9) $+ + 0 $chr(35) $+ $chr(9) $+ + 0 Message
  sf_advert_chk
}
on *:dialog:sf_advert_chk:sclick:*:{
  if ($did = 2) dialog -x sf_advert_chk sf_advert_chk
  elseif ($did = 4) sf_advert_chk
  elseif ($did = 3) {
    if (rclick* !iswm $did(3,1)) || (No* iswm $gettok($did(3).seltext,6,32)) return
    adv_pp
  }
}
alias adv_pp {
  if ($xpopup(adv_).ismenu) xpopup -d adv_
  xpopup -c adv_ graderev
  xpopup -x adv_ +p
  xpop -a adv_ 1 $chr(9) + 1 0 Cancel
  xpop -a adv_ 2 $chr(9) + 0 0 -
  xpop -a adv_ 3 $chr(9) + 2 0 Edit
  xpopup -s adv_ +c $Mouse.dx $Mouse.dy
}
ON *:SIGNAL:Xpopup-adv_:{
  if ($1 = 1) advchk c $gettok($did(sf_advert_chk,3).seltext,6,32) $gettok($did(sf_advert_chk,3).seltext,11,32)
  elseif ($1 = 2) advchk e $gettok($did(sf_advert_chk,3).seltext,6,32) $gettok($did(sf_advert_chk,3).seltext,11,32)
}
alias advchk {
  if ($1 = c) {
    $+(.timer,$2,$3) off
    error -n SoulFly Advertiser $crlf $crlf Advertisement $3 for $hget(soulfly,$2) has been cancelled.
    if ($dialog(sf_advert)) { dialog -x sf_advert sf_advert | adv }
    sf_advert_chk
  }
  elseif ($1 = e) {
    set %adv_c $2
    set %adv_i $3
    .timeradvs -m 1 100 /dialog -x sf_advert_chk sf_advert_chk
    .timeradvclose -m 1 200 /dialog -x sf_advert sf_advert
    .timeradxc -m 1 600 /adv
  }
}
alias sf_advert_chk {
  did -cr sf_advert_chk 3 | var %a = $ini(lists\adv.ini,0), %ai = 1
  if (%a = $null) || ($timer(0) = 0) did -ca sf_advert_chk 3 No Active $chr(9) $chr(9) Advertisements
  else {
    while (%ai <= %a) {
      var %n = $ini(lists\adv.ini,%ai), %nx = $ini(lists\adv.ini,%ai,0), %nxi = 1
      while (%nxi <= %nx) {
        if ($timer(%n $+ %nxi)) did -ca sf_advert_chk 3 %n $chr(9) %nxi $chr(9) $gettok($timer($ifmatch).com,3-,32)
        inc %nxi
      }
      inc %ai
    }
  }
}
alias ref_ini {
  var %ad_r = $ini(lists\adv.ini,$1,0), %ad_ri = 1
  while (%ad_ri <= %ad_r) {
    hadd -m ref_ini %ad_ri $readini(lists\adv.ini,$1,$ini(lists\adv.ini,$1,%ad_ri))
    inc %ad_ri
  }
  remini lists\adv.ini $1 %ad_ri
  if ($timer($+($1,%ad_ri))) $+(timer,$1,%ad_ri) off
  while (%ad_ri <= %ad_r) {
    writeini lists\adv.ini $1 %ad_ri $hget(ref_ini,%ad_ri).data
    inc %ad_ri
  }
  .hfree ref_ini
}
alias advmsg { $iif($2 = msg,msg,describe) $1 $3- }
