mIRC Homepage

random winner script

Posted By: tupen

random winner script - 08/07/13 12:18 AM

I need help with this script. I have one that someone pasted to me but can't get it to work. If someone can give me a copy of a script that does work or tell me how to get this one to work I'd really appreciate it.

on +3:text:!winner:#: {

set %nick1 $nick($chan,$rand(0,$nick($chan,0)))
if (%nick1 == $me) { set %nick1 $nick($chan,$rand(0,$nick($chan,0))) }
else
msg $chan Randomly selecting a winner........
timerlawl 1 5 msg $chan The winner is %nick1 $+ ! Congratulations $nick1 smile You win... %prize. [ $+ [ $network ] $+ ] . [ $+ [ $chan ] ]
}

on +3:text:!addprize *:#: {
set %prize. [ $+ [ $network ] $+ ] . [ $+ [ $chan ] ] $2-
msg $chan New prize set!
}

on +3:text:!clprize:#: {
set %prize. [ $+ [ $network ] $+ ] . [ $+ [ $chan ] ] Nothing
msg $chan Prize cleared!
}
Posted By: Riamus2

Re: random winner script - 08/07/13 10:18 AM

It would help if you say what you expect it to be doing and what it is doing instead. Basically, what isn't working?

The one thing that stands out is that you are avoiding picking yourself as the nick, but only one time. It's not in a loop, so if you end up randomly selecting yourself twice, you'll be the winner. It won't keep trying for someone else without a loop. Of course, if you have many people in the channel, that's not likely to happen often, but if you're going to avoid your nick, you should avoid it completely.

And I'm not sure what's with the ELSE. From looking at it, I'd say that everything after the ELSE should always happen, so you should probably remove that.

Oh, and you don't have to do an evaluation when setting a dynamic variable...

This works fine when setting the variable:
Code:
set %var $+ . $+ $network $+ . $+ $chan


or:

Code:
set $+(%var,.,$network,.,$chan)


It only needs evaluated (brackets or $eval()/$() ) when being read.
Posted By: Masoud

Re: random winner script - 08/07/13 02:32 PM

Originally Posted By: Riamus2

Code:
set $+(%var,.,$network,.,$chan)



Should be:
Code:
set $+(%,var.,$network,.,$chan)


Posted By: Deega

Re: random winner script - 08/07/13 02:58 PM

In addition to what Riamus said, the $rand function should be seeking a number between 1 and $nick(#,0) = $nick($chan,$rand(1,$nick($chan,0)))

Code:
on +3:text:!winner:#:{
  var %nick1 = $nick(#,$rand(1,$nick(#,0)))
  while (%nick1 == $me) { %nick1 = $nick(#,$r(1,$nick(#,0))) }
  msg # Randomly selected winner is %nick1 $+ ! Congratulations %nick1 you win... $eval($+(%,prize.,$network,.,#),2)
}


And the other 2 events.
Code:
on +3:text:!addprize *:#:{
  set $+(%,prize.,$network,.,#) $2-
  msg $chan New prize set!
}
on +3:text:!clprize:#: {
  unset $+(%,prize.,$network,.,#)
  msg $chan Prize cleared!
}
Posted By: Wims

Re: random winner script - 08/07/13 04:26 PM

Originally Posted By: Riamus2
It only needs evaluated (brackets or $eval()/$() ) when being read.
You also need the bracket (only) when using /unset in some situations, because of the 'limit' of /unset.
Posted By: Riamus2

Re: random winner script - 09/07/13 12:28 AM

Oops. Missed my comma. Thanks, Masoud. And thanks, Wims, for mentioning /unset.
© 2019 mIRC Discussion Forums