mIRC Home    About    Download    Register    News    Help

Print Thread
random winner script #242360 08/07/13 12:18 AM
Joined: Jun 2013
Posts: 2
T
tupen Offline OP
Bowl of petunias
OP Offline
Bowl of petunias
T
Joined: Jun 2013
Posts: 2
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!
}

Re: random winner script [Re: tupen] #242363 08/07/13 10:18 AM
Joined: Oct 2004
Posts: 8,327
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,327
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.


Invision Support
#Invision on irc.irchighway.net
Re: random winner script [Re: Riamus2] #242364 08/07/13 02:32 PM
Joined: Mar 2010
Posts: 144
Masoud Offline
Vogon poet
Offline
Vogon poet
Joined: Mar 2010
Posts: 144
Originally Posted By: Riamus2

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



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




Nothing...
Re: random winner script [Re: tupen] #242365 08/07/13 02:58 PM
Joined: Oct 2012
Posts: 164
D
Deega Offline
Vogon poet
Offline
Vogon poet
D
Joined: Oct 2012
Posts: 164
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!
}

Re: random winner script [Re: Riamus2] #242370 08/07/13 04:26 PM
Joined: Jul 2006
Posts: 3,568
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,568
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.


Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: random winner script [Re: Masoud] #242378 09/07/13 12:28 AM
Joined: Oct 2004
Posts: 8,327
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,327
Oops. Missed my comma. Thanks, Masoud. And thanks, Wims, for mentioning /unset.


Invision Support
#Invision on irc.irchighway.net