mIRC Home    About    Download    Register    News    Help

Topic Options
#242360 - 08/07/13 01:18 AM random winner script
tupen Offline
Bowl of petunias

Registered: 17/06/13
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!
}

Top
#242363 - 08/07/13 11:18 AM Re: random winner script [Re: tupen]
Riamus2 Offline
Planetary brain

Registered: 13/10/04
Posts: 8327
Loc: NC, USA
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

Top
#242364 - 08/07/13 03:32 PM Re: random winner script [Re: Riamus2]
Masoud Offline
Vogon poet

Registered: 01/03/10
Posts: 142
Loc: London, UK
Originally Posted By: Riamus2

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



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


_________________________
Nothing...

Top
#242365 - 08/07/13 03:58 PM Re: random winner script [Re: tupen]
Deega Offline
Vogon poet

Registered: 30/10/12
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!
}

Top
#242370 - 08/07/13 05:26 PM Re: random winner script [Re: Riamus2]
Wims Offline
Planetary brain

Registered: 31/07/06
Posts: 3438
Loc: France
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

Top
#242378 - 09/07/13 01:28 AM Re: random winner script [Re: Masoud]
Riamus2 Offline
Planetary brain

Registered: 13/10/04
Posts: 8327
Loc: NC, USA
Oops. Missed my comma. Thanks, Masoud. And thanks, Wims, for mentioning /unset.
_________________________
Invision Support
#Invision on irc.irchighway.net

Top