alias -l oknow {
  dialog -md scrapic scrapic
}

alias -l pictcheck {
  if ($dialog(scrapic) && ( %one.more == %goal.check ) ) {
    .timergoon off
    did -r scrapic 69
    did -a scrapic 69 $duration($calc($ctime - %cntm))
    dialog -md cong cong
  }
}

alias -l mambo {
  .timergoon 0 1 pictcheck
  did -r scrapic 69,66
  did -a scrapic 66 %kliks
  did -a scrapic 69 Counting
  inc %kliks
}

alias -l bambini {
  set %ten.less $did
  set %find.keno $findtok(%one.more,30,1,45)
  set %mone $left($right($did(scrapic,%ten.less),6),2)
  if ( %ten.less == $calc(%find.keno - 1) || %ten.less == $calc(%find.keno + 1) || %ten.less == $calc(%find.keno - 5) || %ten.less == $calc(%find.keno + 5) ) {
    did -g scrapic %ten.less $chr(34) $+ %npa $+ 30.bmp $+ $chr(34)
    did -g scrapic %find.keno $chr(34) $+ %npa $+ %mone $+ .bmp $+ $chr(34)
    set %one.more $deltok(%one.more,1-30,45)
    var %tote = 1
    while ( %tote <= 30 ) {
      set %one.more $addtok(%one.more,$left($right($did(scrapic,%tote),6),2),45)
      inc %tote
    }
  }
  mambo
}

alias -l allwaystrue {
  set %cntm $ctime
  set %one.more
  var %zet = 1
  while ( %zet <= 30 ) {
    set %main.tok $addtok(%main.tok,%zet,45)
    inc %zet
  }
  var %qu = 1
  while ( %qu <= 30 ) {
    :begin
    set %tyxaio $rand(1,30)
    if ( $len($gettok(%main.tok,%tyxaio,45)) == 1 ) {
      did -g scrapic %qu $chr(34) $+ %pic.path $+ %mg $+ $chr(48) $+ $gettok(%main.tok,%tyxaio,45) $+ .bmp $+ $chr(34)
      set %main.tok $deltok(%main.tok,%tyxaio,45)
      set %bt $left($right($did(scrapic,%qu),5),1)
      set %one.more $addtok(%one.more,%bt,45)
      inc %qu
    }
    elseif ( $len($gettok(%main.tok,%tyxaio,45)) == 2 ) {
      did -g scrapic %qu $chr(34) $+ %pic.path $+ %mg $+ $gettok(%main.tok,%tyxaio,45) $+ .bmp $+ $chr(34)
      set %main.tok $deltok(%main.tok,%tyxaio,45)
      set %one.more $addtok(%one.more,$left($right($did(scrapic,%qu),6),2),45)
      inc %qu
    }
  }
  else { 
    goto begin
  }
  set %npa %pic.path $+ %mg 
  if ($dialog(prev)) {
    did -g prev 1 $chr(34) $+ %pic.path $+ %mg $+ preview.bmp $+ $chr(34)
  }
  mambo
}

alias -l sameas {
  set %goal.check 01-02-03-04-05-06-07-08-09-10-11-12-13-14-15-16-17-18-19-20-21-22-23-24-25-26-27-28-29-30
  set %mg $readini($scriptdir $+ sav3.ini,n,PICPATH,CurrentPath)
  set %pic.path $scriptdir $+ scrapic $+ $chr(92) $+ images $+ $chr(92)
  set %one.more $readini($scriptdir $+ sav3.ini,n,SAVEDGAME,SlicesPlaces)
  set %npa %pic.path $+ %mg
  if ($dialog(prev)) {
    did -g prev 1 %npa $+ preview.bmp
  }
  bambini
}


dialog scrapic {
  title "Picture Scramble Trouble!® 1.0.2"
  size -1 -1 150 131
  option dbu
  icon 1, 6 8 17 17
  icon 2, 24 8 17 17
  icon 3, 42 8 17 17
  icon 4, 60 8 17 17
  icon 5, 78 8 17 17
  icon 6, 6 26 17 17
  icon 7, 24 26 17 17
  icon 8, 42 26 17 17
  icon 9, 60 26 17 17
  icon 10, 78 26 17 17
  icon 11, 6 44 17 17
  icon 12, 24 44 17 17
  icon 13, 42 44 17 17
  icon 14, 60 44 17 17
  icon 15, 78 44 17 17
  icon 16, 6 62 17 17
  icon 17, 24 62 17 17
  icon 18, 42 62 17 17
  icon 19, 60 62 17 17
  icon 20, 78 62 17 17
  icon 21, 6 80 17 17
  icon 22, 24 80 17 17
  icon 23, 42 80 17 17
  icon 24, 60 80 17 17
  icon 25, 78 80 17 17
  icon 26, 6 98 17 17
  icon 27, 24 98 17 17
  icon 28, 42 98 17 17
  icon 29, 60 98 17 17
  icon 30, 78 98 17 17
  button "", 61, 154 127 4 3, cancel hide
  box "", 62, 103 46 39 11
  box "", 63, 103 56 39 17
  box "", 64, 103 28 39 17
  box "", 65, 103 18 39 11
  edit "", 66, 105 33 35 10, read center
  text "Clicks", 67, 105 22 35 7, center
  text "Timer", 68, 105 50 35 7, center
  edit "", 69, 105 61 35 10, read center
  box "", 70, 101 16 43 59
  box "", 71, 4 3 93 114
  text "Statistics", 72, 101 8 44 8, center
  box "", 73, 101 4 43 14
  box "", 74, 99 3 47 73
  box "", 75, 2 1 146 118
  icon 76, 100 75 44 47, $mircdirSpiele\picpuzzel\mainlogo.jpg, noborder
  menu "Game", 77
  item "...Save...", 80, 77
  item "...Load...", 82, 77
  item "....Exit....", 84, 77
  menu "Picture", 85
  item "...Load...", 86, 85
  item ".Preview.", 87, 85
  menu "Help", 88
  item "Main help", 89, 88
  item "...About...", 91, 88
}

;size of the slices 42x42 pixels (30 equal slices in a 5x6 grid)
;size of pic to be sliced 210x252

dialog selpic {
  title "Picture Album"
  size -1 -1 182 146
  option dbu
  icon 1, 6 28 51 51
  icon 2, 65 28 51 51
  icon 3, 124 28 51 51
  icon 4, 6 88 51 51
  icon 5, 65 88 51 51
  icon 6, 124 88 51 51
  box "", 7, 4 23 55 58
  text "Double click on a picture to load it in the game!", 8, 35 8 111 8, center
  box "", 9, 32 3 118 14
  button "", 10, 0 0 4 3, cancel hide
  box "", 11, 63 23 55 58
  box "", 12, 122 23 55 58
  box "", 13, 122 83 55 58
  box "", 14, 63 83 55 58
  box "", 15, 4 83 55 58
}

;size of preview 121x121 pixels

dialog prev {
  title "Preview"
  size -1 -1 64 67
  option dbu
  icon 1, 6 9 51 51
  box "", 2, 4 4 55 58
  button "", 3, 0 0 4 3, cancel hide
}

dialog cong {
  title "Congratulation!!"
  size -1 -1 152 100
  option dbu
  icon 1, 2 8 145 13, $mircdirSpiele\picpuzzel\congra.jpg, noborder
  icon 2, 43 31 62 49
  button "Close", 3, 1 86 149 12, cancel
  edit "", 4, 3 56 36 10, read center
  text "Clicks", 5, 3 42 36 8, center
  box "", 6, 1 37 40 14
  box "", 7, 1 51 40 17
  box "", 8, 110 52 40 17
  box "", 9, 110 38 40 14
  edit "", 10, 112 57 36 10, read center
  text "Time", 11, 112 43 36 8, center
}

dialog salo {
  title "Save - Load game"
  size -1 -1 155 87
  option dbu
  icon 3, 98 4 51 51
  box "", 58, 1 -1 152 61
  text "Day", 13, 5 8 88 8, center
  edit "", 1, 5 18 88 10, disable center
  text "Time", 18, 5 35 88 8, center
  edit "", 2, 5 45 88 10, disable center
  button "save", 4, 1 63 47 10
  button "<< click one >>", 5, 53 63 47 10, disable
  button "load", 6, 106 63 47 10
  button "close", 7, 1 75 152 10, cancel
  box "", 34, 3 2 93 29
  box "", 35, 3 29 93 28
}

dialog rusure {
  title "Beware!"
  size -1 -1 116 63
  option dbu
  text "Are you sure you want to load a previous game? Clicks counting and game timer will reset!!", 1, 4 6 109 23, center
  box "", 2, 0 -1 116 32
  button "Load it!", 3, 1 34 114 12
  button "No... I changed my mind!", 4, 1 48 114 12, cancel
}

on *:dialog:scrapic:init:0: {
  set %goal.check 01-02-03-04-05-06-07-08-09-10-11-12-13-14-15-16-17-18-19-20-21-22-23-24-25-26-27-28-29-30
  set %pic.path $scriptdir $+ scrapic $+ $chr(92) $+ images $+ $chr(92)
  set %main.tok
}

on *:dialog:scrapic:sclick:1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30: {
  if (!%one.more) {
    echo 4 -a No picture or game loaded! The board is empty!
  }
  else {
    bambini
  }
}

on *:dialog:scrapic:menu:86: {
  dialog -md selpic selpic
}

on *:dialog:scrapic:menu:84: {
  unset %goal.check %pic.path %main.tok %mg %one.more %tyxaio %bt %npa %kliks %ten.less %find.keno %mone %sav3z %boubou %bibi %cntm %saloa %dayz %datez %timz 
  if ($dialog(prev)) {
    dialog -x prev prev
  }
  if ($dialog(selpic)) {
    dialog -x selpic selpic
  }
  if ($dialog(salo)) {
    dialog -x salo salo
  }
  .timergoon off
  dialog -x scrapic scrapic
  echo 12 -a Thank you for playing 4 Picture Scramble Trouble®! 
}

on *:dialog:scrapic:sclick:61: {
  unset %goal.check %pic.path %main.tok %mg %one.more %tyxaio %bt %npa %kliks %ten.less %find.keno %mone %sav3z %boubou %bibi
  if ($dialog(prev)) {
    dialog -x prev prev
  }
  if ($dialog(selpic)) {
    dialog -x selpic selpic
  }
  .timergoon off
  dialog -x scrapic scrapic
  echo 12 -a Thank you for playing 4 Picture Scramble Trouble®! 
}

on *:dialog:selpic:init:0: {
  did -g selpic 1 $chr(34) $+ %pic.path $+ 1\preview.bmp $+ $chr(34)
  did -g selpic 2 $chr(34) $+ %pic.path $+ 2\preview.bmp $+ $chr(34)
  did -g selpic 3 $chr(34) $+ %pic.path $+ 3\preview.bmp $+ $chr(34)
  did -g selpic 4 $chr(34) $+ %pic.path $+ 4\preview.bmp $+ $chr(34)
  did -g selpic 5 $chr(34) $+ %pic.path $+ 5\preview.bmp $+ $chr(34)
  did -g selpic 6 $chr(34) $+ %pic.path $+ 6\preview.bmp $+ $chr(34)
}

on *:dialog:selpic:dclick:*: {
  if ( $did == 1 ) {
    set %mg 1\
  }
  if ( $did == 2 ) {
    set %mg 2\
  }
  if ( $did == 3 ) {
    set %mg 3\
  }
  if ( $did == 4 ) {
    set %mg 4\
  }
  if ( $did == 5 ) {
    set %mg 5\
  }
  if ( $did == 6 ) {
    set %mg 6\
  }
  .timergoon off
  unset %kliks
  allwaystrue
  dialog -x selpic selpic
}

on *:dialog:scrapic:menu:87: {
  if (!%one.more) {
    echo 5 -a No picture to preview!
  }
  else {
    dialog -md prev prev
    did -g prev 1 $chr(34) $+ %pic.path $+ %mg $+ preview.bmp $+ $chr(34)
  }
}

on *:dialog:cong:init:0: {
  did -r cong 4,10
  did -a cong 4 $did(scrapic,66)
  did -a cong 10 $did(scrapic,69)
  did -g cong 2 $chr(34) $+ %npa $+ preview.bmp $+ $chr(34)
}

on *:dialog:scrapic:menu:80: {
  if (!%one.more) {
    echo 4 -a No game in progress!
    return
  }
  else {
    set %saloa 1
    dialog -md salo salo
  }
}

on *:dialog:scrapic:menu:82: {
  if (!$findfile($scriptdir,sav3.ini,1)) {
    echo 10 -a No saved game!
  }
  else {
    set %saloa 2
    dialog -md salo salo
  }
}

on *:dialog:salo:sclick:4: {
  set %dayz $day
  set %datez $date
  set %timz $time
  var %mapa = 1
  while ( %mapa <= 30 ) {
    set %sav3z $addtok(%sav3z,$left($right($did(scrapic,%mapa),6),2),45)
    inc %mapa
  }
  writeini $chr(34) $+ $scriptdir $+ sav3.ini $+ $chr(34) SAVEDGAME SlicesPlaces %sav3z
  writeini $chr(34) $+ $scriptdir $+ sav3.ini $+ $chr(34) PICPATH CurrentPath %mg
  writeini $chr(34) $+ $scriptdir $+ sav3.ini $+ $chr(34) DAYDATE Day %dayz 
  writeini $chr(34) $+ $scriptdir $+ sav3.ini $+ $chr(34) DATEDAY Date %datez 
  writeini $chr(34) $+ $scriptdir $+ sav3.ini $+ $chr(34) TIME Time %timz 
  writeini $chr(34) $+ $scriptdir $+ sav3.ini $+ $chr(34) PICTOLOAD PrePic $chr(34) $+ %pic.path $+ %mg $+ preview.bmp $+ $chr(34) 
  did -ra salo 1 %dayz %datez
  did -ra salo 2 %timz
  did -g salo 3 $chr(34) $+ %pic.path $+ %mg $+ preview.bmp $+ $chr(34)
  echo 5 -a Game saved!
}

on *:dialog:salo:sclick:6: {
  dialog -md rusure rusure
}

on *:dialog:rusure:sclick:3: {
  set %boubou $readini($scriptdir $+ sav3.ini,n,SAVEDGAME,SlicesPlaces)
  set %bibi $readini($scriptdir $+ sav3.ini,n,PICPATH,CurrentPath)
  var %wet = 1
  while ( %wet <= 30 ) {
    did -g scrapic %wet $chr(34) $+ %pic.path $+ %bibi $+ $gettok(%boubou,%wet,45) $+ .bmp $+ $chr(34)
    inc %wet
  }
  unset %goal.check %pic.path %main.tok %mg %one.more %tyxaio %bt %npa %kliks %ten.less %find.keno %mone %sav3z %boubou %bibi
  .timergoon off
  dialog -x rusure rusure
  dialog -x salo salo
  sameas
}

on *:dialog:salo:init:0: {
  if ( %saloa == 1 ) {
    did -b salo 6
  }
  elseif ( %saloa == 2 ) {
    did -b salo 4
  }
  did -ra salo 1 $readini($chr(34) $+ $scriptdir $+ sav3.ini $+ $chr(34), n,DAYDATE,Day) $readini($chr(34) $+ $scriptdir $+ sav3.ini $+ $chr(34), n,DATEDAY,Date)
  did -ra salo 2 $readini($chr(34) $+ $scriptdir $+ sav3.ini $+ $chr(34),n,TIME,Time)
  did -g salo 3 $chr(34) $+ $readini($chr(34) $+ $scriptdir $+ sav3.ini $+ $chr(34),n,PICTOLOAD,PrePic) $+ $chr(34)
}

on *:dialog:scrapic:menu:91: {
  echo 5 -a 4Picture 4Scramble 4Trouble!® 1.0.2 Handmade and homemade by StepenWolf from GrNet ( st3p3nwolf@hotmail.com ) Have Fun!
}

on *:dialog:scrapic:menu:89: {
  if (!$findfile(" $+ $scriptdir $+ ",scrapic.chm,1)) {
    echo 4 -a Help file is lost! I am sorry no help avalaible!
  }
  else {
    run scrapic.chm
  }
}

on *:load: {
  if ($version < 5.9 ) {
    echo 12 -a Sorry but this script needs mIRC version 5.9 (or higher) to run! Your version is $version ! Upgrade here http://www.mirc.com
    unload -rs scrapic.mrc
    return
  }
  else {
    echo 12 -a Please wait as the script runs for the first time....
    if (!$finddir($scriptdir,scrapic*,1)) {
      echo 4 -a Script didn't install corectly! Please retry... ( Error: The directory $chr(34) $+ $scriptdir $+ scrapic\ $+ $chr(34) is missing! )
    }
    if (!$findfile(" $+ $scriptdir $+ ",scrapic.chm,1)) {
      echo 12 -a Help file (scrapic.chm) is missing! No help will be avalaible...
    }
    if (!$findfile(" $+ $scriptdir $+ ",mainlogo.jpg,1)) {
      echo 4 -a A picture needed by the script is missing! (Error: mainlogo.jpg couldn't found in $scriptdir )
    }
    if (!$findfile(" $+ $scriptdir $+ ",congra.jpg,1)) {
      echo 4 -a A picture needed by the script is missing! (Error: congra.jpg couldn't found in $scriptdir )
    }
    echo 5 -a All checks done! If there were any errors please correct them so you can enjoy the game :-)
    echo -a 4Picture 4Scramble 4Trouble!® Loaded! Have Fun! You can find it by right clicking in any channel window and clicking on P.T.S.® 
    run scrapic.chm
  }
