mIRC Homepage
Posted By: Vengeance random song player help? - 17/10/06 07:17 PM
I made this script to play random songs or random songs by a keyword... I got confused while making it.
any help would be nice, or if theres a better way to do it would be nice.
(cant get it to play by keyword, dunno what I did wrong)

Code:
on *:text:.random*:#:{
  if (!$2) {
    timers off
    randsong1
  }
  elseif ($2) {
    timers off
    randsong2
  }
}
alias randsong1 {
  set %play.num $rand(1,$findfile(C:\My\Music\File, * ,*))
  set %song.loc $findfile(C:\My\Music\File, * ,%play.num)
  set %song $remove(%song.loc,C:\My\Music\File,.mp3)
  splay %song.loc
  msg $chan 12[14 Playing  $+ %song 12][14 $asctime($round($calc( $insong.length / 1000),0),nn:ss) 12]
  timerRAND 1 $round($calc( $insong.length / 1000),0) randsong1
}
alias randsong2 {
  set %part $2-
  set %play.num $rand(1,$findfile(C:\My\Music\File, * $+ $replace(%part,$chr(32),$chr(42)) $+ * ,*))
  set %song.loc $findfile(C:\My\Music\File, * %part * ,%play.num)
  set %song $remove(%song.loc,C:\My\Music\File,.mp3)
  splay %song.loc
  msg $chan 12[14 Playing  $+ %song 12][14 $asctime($round($calc( $insong.length / 1000),0),nn:ss) 12]
  timerRAND 1 $round($calc( $insong.length / 1000),0) randsong2
}
Posted By: Vengeance Re: random song player help? - 17/10/06 11:10 PM
not sure if this is the best way but I
fixed it or atleast keywords work now.

Code:
on *:text:.random*:#:{
  if (!$2) {
    timers off
    randsong1
  }
  elseif ($2) {
    timers off
    set %part $replace($2-,$chr(32),$chr(42))
    randsong2
  }
}
alias randsong1 {
  set %play.num $rand(1,$findfile(C:\My\Music\File\, * ,*))
  set %song.loc $findfile(C:\My\Music\File\, * ,%play.num)
  set %song $remove(%song.loc,C:\My\Music\File\,.mp3)
  splay %song.loc
  msg $chan 12[14 Playing  $+ %song 12][14 $asctime($round($calc( $insong.length / 1000),0),nn:ss) 12]
  timerRAND 1 $round($calc( $insong.length / 1000),0) randsong1
}
alias randsong2 {
  set %play.num $rand(1,$findfile(C:\My\Music\File\, * $+ $replace(%part,$chr(32),$chr(42)) $+ * ,*))
  set %song.loc $findfile(C:\My\Music\File\, * $+ %part $+ * ,%play.num)
  set %song $remove(%song.loc,C:\My\Music\File\,.mp3)
  splay %song.loc
  msg $chan 12[14 Playing  $+ %song 12][14 $asctime($round($calc( $insong.length / 1000),0),nn:ss) 12]
  timerRAND 1 $round($calc( $insong.length / 1000),0) randsong2
}
Posted By: RusselB Re: random song player help? - 18/10/06 03:47 AM
Glad to hear you got it working by yourself.

Here's an alternative suggestion
Code:
 on *:text:.random*:#:{
  .timers off
  randsong $+ $iif(!$2,1,2)
}
alias randsong1 {
  set %song.loc $findfile(C:\My\Music\File,*.mp3,$r(1,$findfile(C:\My\Music\File,*.mp3 ,0)))
  set %song $nopath(%song.loc)
  splay %song.loc
  msg $chan 12[14 Playing  $+ %song 12][14 $asctime($round($calc( $insong.length / 1000),0),nn:ss) 12]
  timerRAND 1 $round($calc( $insong.length / 1000),0) randsong1
}
alias randsong2 {
  set %part $replace($2-,$chr(32),$chr(42))
  set %play.num $r(1,$findfile(C:\My\Music\File, $+(*,%part,*.mp3),0))
  set %song.loc $findfile(C:\My\Music\File, * %part * ,%play.num)
  set %song $nopath(%song.loc)
  splay %song.loc
  msg $chan 12[14 Playing  $+ %song 12][14 $asctime($round($calc( $insong.length / 1000),0),nn:ss) 12]
  timerRAND 1 $round($calc( $insong.length / 1000),0) randsong2
}
 
Posted By: Vengeance Re: random song player help? - 18/10/06 02:20 PM
yikes, tried that one and it went crazy lol
dont know if i pasted or edited it right.

**edited it again and it works good :tongue:
just need to add a $remove to get rid of .mp3 or is there another way to do that too :tongue:
Posted By: RusselB Re: random song player help? - 18/10/06 07:47 PM
If there is another way, then I'm not aware of it. Sorry I forgot about removing the file extension.
Posted By: Lpfix5 Re: random song player help? - 19/10/06 07:34 PM
theres several methods...

1 of the 2 is

$left($nopath(path/filename.mp3),-4)

$left command or $right command either only shows you the Nth requested or erases the Nth requested.

Then $remove($nopath(Path/Filename.mp3),.mp3)

:P Theres even about 7 more ways to do it $regex being another method.
Posted By: Lpfix5 Re: random song player help? - 19/10/06 08:10 PM
Also im not sure if you want a new song to start all the time everytime someone types .random so I created a small if $insong return statement else play a random song + I added a menu to the channel where you right click in a channel and select your MP3 Dir for more flexibility

smile

Code:
menu Channel {
  Rand Set:{ %r.dir = $sdir($mircdir,Select Mp3 Dir) | %r.xam = $findfile(%r.dir,*.mp3,0)  }
}

On *:TEXT:.random*:#:{
  if ($insong) { return }
  else { %r.play = $findfile(%r.dir,*.mp3,$rand(1,%r.xam)) | splay %r.play  | msg $chan I am currently playing $left($nopath(%r.play),-4) - $+(Lenght:,$asctime($round($calc($insong.length /1000),0),n:ss)) }
}


try that.
© mIRC Discussion Forums