mIRC Homepage

The ever growing thirst for knowledge and help!

Posted By: Feyl0rd

The ever growing thirst for knowledge and help! - 11/03/15 08:09 PM

Alright. I'm back again with another idea and would like some insight / guidance. I'm looking to create a script that stores a Youtube link into (maybe a hashtable?) and has on text command that pulls the top one out of the table and then deletes it. So maybe something like:
Code:
;Song playLIST
on *:text:!songrequest*:#:{
  if %pl = on {
    /hadd -a 1 $$2 playlist
  }
  if %pl = off {
    /hmake playlist
    var %pl = on
    /hadd -a 1 $$2 playlist
  }
}

on *:text:!nextsong:#:{
  if ($nick == bubbernaut_cce) {
    msg $chan $hget(playlist, 1)
  }
  else { msg $chan only bubbernaut_cce can run this command. }
}
Posted By: Loki12583

Re: The ever growing thirst for knowledge and help! - 11/03/15 08:41 PM

Hash tables don't have a top. I suggest adding actual entries as numerical indices and have some other keys (current, next, last) which point to the indices.

Code:
on *:text:!songrequest*:#:{
  hinc playlist last
  hadd playlist $hget(playlist,last) $2
}

on *:text:!nextsong:#:{
  if ($hget(playlist,current)) hdel playlist $v1
  hinc playlist current

  echo -ag current song is $hget(playlist,$hget(playlist,current))
}


All that said, appending to a plain text file then reading and deleting the first line would not be a terrible implementation for this either.
Posted By: Feyl0rd

Re: The ever growing thirst for knowledge and help! - 11/03/15 08:42 PM

Thanks for the reply. I actually might try the txt file idea. Seems pretty straight forward... I think.
Posted By: Feyl0rd

Re: The ever growing thirst for knowledge and help! - 11/03/15 09:10 PM

Using the example you've posted it spits out numbers in order instead of the link that's supposed to be associated with the number it spits out. I tried fiddling with it but I can't get it to spit out the link instead of the number.
Posted By: Loki12583

Re: The ever growing thirst for knowledge and help! - 11/03/15 10:03 PM

Yep my bad, just need to wrap that index in another $hget - I've edited the original post
Posted By: Feyl0rd

Re: The ever growing thirst for knowledge and help! - 11/03/15 10:23 PM

Yep, that fixed it, haha.
I was working on the txt varient of this. But I couldn't get it to work. It would read line 2 (because it would delete line 1 before it could read it and spit it out I guess.)
Code:
on *:text:!songrequest*:#:{
  write playlist.txt $2
}
on *:text:!next:#:{
  if ($nick == feyl0rd) || if ($nick == bubbernaut_cce) {
    msg $chan The next song is: $read(playlist.txt,.,1)
    .timer 1 4 write -dl 1 playlist.txt
  }
  else { msg $chan only bubbernaut_cce can run this command. }
}
Posted By: Feyl0rd

Re: The ever growing thirst for knowledge and help! - 14/03/15 07:23 PM

After some more testing with your post. It seems that it just continues on down a list. Example:
User1: !songrequest X
User2: !songrequest Y
User3: !songrequest Z
Mod: !nextsong
Bot: Song: Z
Mod: !nextsong
Bot: Song:
Mod: !nextsong
Bot: Song:
Posted By: Feyl0rd

Re: The ever growing thirst for knowledge and help! - 14/03/15 07:30 PM

I'm thinking maybe a while loop would fix this? I'll look into it a bit more.
© 2019 mIRC Discussion Forums