mIRC Home    About    Download    Register    News    Help

Print Thread
Page 1 of 2 1 2
#250978 05/02/15 08:32 AM
Joined: Feb 2015
Posts: 11
M
Malko Offline OP
Pikka bird
OP Offline
Pikka bird
M
Joined: Feb 2015
Posts: 11
Hey guys i've been trying to learn programming lately and have set up a points system and some other smaller features for my twitch stream. I've been working on a random lottery feature so every few mins it selects a random viewer and says you have won the random lottery you win 50 points (random number out of selected few) and writes it to the points.ini file. this is what i got so far

Code:
on *:text:!startlottery:#:{
  $+(.timerlottery.,#,.,$nick) 0 60 add.pts $+(#,.,$nick)
  if ($nick isop #) { msg # [Lottery]: $nick(#,$rand(1,$nick(#,0))) You have just won the random lottery }
  else 
  on !*:part:#:$+(.timerlottery.,#,.,$nick) off
  alias -l add.pts {
    writeini -n Points.ini $1 Points $calc($readini(Points.ini,$1,Points /set %rand $rand(1,10) { if (%rand == 1) { /msg $chan You win 5 points } 
      elseif (%rand == 2) { /msg $chan You win 10 points } 
      elseif (%rand == 3) { /msg $chan You win 20 points } 
      elseif (%rand == 4) { /msg $chan You win 30 points } 
      elseif (%rand == 5) { /msg $chan You win 40 points } 
      elseif (%rand == 6) { /msg $chan You win 50 points } 
      elseif (%rand == 7) { /msg $chan You win 60 points } 
      elseif (%rand == 8) { /msg $chan You win 70 points } 
      elseif (%rand == 9) { /msg $chan You win 80 points } 
      elseif (%rand == 10) { /msg $chan You win 90 points } 
  else { /msg $chan You win 150 points } } } 


}


Would rather the lottery start when the bot starts but not sure how to do that.
Thanks malko

Malko #250980 05/02/15 10:51 AM
Joined: Jun 2014
Posts: 248
B
Fjord artisan
Offline
Fjord artisan
B
Joined: Jun 2014
Posts: 248
on me:*:JOIN:#: { do stuff }

Malko #250982 05/02/15 12:36 PM
Joined: Feb 2003
Posts: 2,812
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,812
This line cannot exist. You have a bunch of lines all cobbled into one in no way that makes sense.

writeini -n Points.ini $1 Points $calc($readini(Points.ini,$1,Points /set %rand $rand(1,10) { if (%rand == 1) { /msg $chan You win 5 points }

Overall your code has a dozen glaring syntactic errors that makes it look like you just copied chunks of code from other people's scripts and pasted them in randomly.

But if you'd like to learn some logic, check this out:

Originally Posted By: Malko
/set %rand $rand(1,10)
if (%rand == 1) { /msg $chan You win 5 points }
elseif (%rand == 2) { /msg $chan You win 10 points }
elseif (%rand == 3) { /msg $chan You win 20 points }
elseif (%rand == 4) { /msg $chan You win 30 points }
elseif (%rand == 5) { /msg $chan You win 40 points }
elseif (%rand == 6) { /msg $chan You win 50 points }
elseif (%rand == 7) { /msg $chan You win 60 points }
elseif (%rand == 8) { /msg $chan You win 70 points }
elseif (%rand == 9) { /msg $chan You win 80 points }
elseif (%rand == 10) { /msg $chan You win 90 points }
else { /msg $chan You win 150 points }


becomes

Code:
var %rand = $rand(1,10)
var %pointlist = 5,10,20,30,40,50,60,70,80,150
var %points = $gettok(%pointlist,%rand,44)
msg $chan $nick wins %points points!


You might notice in your code that if %rand can be a number 1 through 10, there's no possible way for "else" to arrive at 150 points... so I replaced 90 with 150.

Anyway, good luck.

I highly recommend writing your own code from scratch and avoid any copy/pasting from other people's scripts you don't fully understand letter for letter.


Well. At least I won lunch.
Good philosophy, see good in bad, I like!
Joined: Feb 2015
Posts: 11
M
Malko Offline OP
Pikka bird
OP Offline
Pikka bird
M
Joined: Feb 2015
Posts: 11
Thanks for the help! i did some coding a while ago late last year and then its been a while since that so I've been going over what i already done and trying to use the code i used for my points system in this. I'm just struggling to get my head around the part where it picks someone random and gives them a amount of points and tells them how many. I can't find many good places to learn how to program in this language.

Malko #251025 07/02/15 01:17 AM
Joined: Feb 2015
Posts: 11
M
Malko Offline OP
Pikka bird
OP Offline
Pikka bird
M
Joined: Feb 2015
Posts: 11
So i have got it down to this, but its not excuting anything, i feel like i'm missing something important, can anyone see whats wrong?
Code:
on me:*:JOIN:#: {
  $+(.timerlottery.,#,.,$nick) 0 60 add.pts $+(#,.,$nick)
  if ($nick isop #) { msg # [Lottery]: $nick(#,$rand(1,$nick(#,0))) You have just won the random lottery }
  else 
  on !*:part:#:$+(.timerlottery.,#,.,$nick) off
  alias -l add.pts {
    writeini -n Points.ini $1 Points $calc($readini(Points.ini,$1,Points /set %rand $rand(1,10) { if (%rand == 1) { /msg $chan You win 5 points } 
      var %rand = $rand(1,10)
      var %pointlist = 5,10,20,30,40,50,60,70,80,150
      var %points = $gettok(%pointlist,%rand,44)
  msg $chan $nick wins %points points! } } 

Malko #251026 07/02/15 01:53 AM
Joined: Jul 2006
Posts: 4,149
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,149
Why do you have an on part event and the alias add.pts inside the on join event? That would be the important things you would be missing wink which was pointed out by Raccoon, basically, but not explicitely

Last edited by Wims; 07/02/15 01:54 AM.

#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Wims #251027 07/02/15 02:31 AM
Joined: Feb 2015
Posts: 11
M
Malko Offline OP
Pikka bird
OP Offline
Pikka bird
M
Joined: Feb 2015
Posts: 11
Oh yeah i see that now! so should i have something there instead? because i've taken it out and nothing has changed, i feel like the timer isn't working properly

Malko #251028 07/02/15 02:39 AM
Joined: Jul 2006
Posts: 4,149
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,149
It's impossible to tell without seeing the code, and I couldn't really tell what you really wanted to do so I didn't assume anything.
Btw, /timer can be dangerous, as it is right now you can be exploited, read this page http://en.wikichip.org/wiki/mirc/msl_injection


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Wims #251029 07/02/15 02:42 AM
Joined: Feb 2015
Posts: 11
M
Malko Offline OP
Pikka bird
OP Offline
Pikka bird
M
Joined: Feb 2015
Posts: 11
Do you have a safer way of doing it?
Code:
on me:*:JOIN:#: {
  $+(.timerlottery.,#,.,$nick) 0 60 add.pts $+(#,.,$nick)
  if ($nick isop #) { msg # [Lottery]: $nick(#,$rand(1,$nick(#,0))) You have just won the random lottery }
  else 
  {
    writeini -n Points.ini $1 Points $calc($readini(Points.ini,$1,Points /set %rand $rand(1,10) { if (%rand == 1) { /msg $chan You win 5 points } 
      var %rand = $rand(1,10)
      var %pointlist = 5,10,20,30,40,50,60,70,80,150
      var %points = $gettok(%pointlist,%rand,44)
  msg $chan $nick wins %points points! } } 


}

Malko #251031 07/02/15 03:11 AM
Joined: Jul 2006
Posts: 4,149
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,149
Well this script is non sense, it's triggering only for when you (your bot) join the channel.
Can you explain clearly what you want the script to do?


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Wims #251032 07/02/15 03:17 AM
Joined: Feb 2015
Posts: 11
M
Malko Offline OP
Pikka bird
OP Offline
Pikka bird
M
Joined: Feb 2015
Posts: 11
Ok, So what i want it to do is when the bot joins the stream it starts a loop with a timer so like every 5 mins it will select a random viewer and send them a message "you won the lottery you get ** points" and give them a randomized amount of points. Does that make sense? thanks for helping

Malko #251033 07/02/15 03:40 AM
Joined: Jul 2006
Posts: 4,149
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,149
Yes, however, you cannot check if you are op in an on join event because you're never op when you join a channel, the technical correct way to do this is to set a variable to 1 when you join, and then use an on op event, checking if you are the one getting the op and then you check if the variable is set (unset that variable whenever you get opped anyway). From that point, start the timer:

$+(.timerlottery.,#) 0 300 lottery $safe(#)

Then, make the alias lottery:

Code:
alias lottery {
 var %winner $nick($1,$r(1,$nick($1,0)))
 var %point $gettok(5,10,20,30,40,50,60,70,80,150,$r(1,10),44)
 var %inisection $+($1,.,%winner)
 writeini -n Points.ini %inisection Points $calc($readini(Points.ini,%inisection,Points) + %point)
 msg $1 %winner wins %point points!
}


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Wims #251037 07/02/15 04:25 AM
Joined: Feb 2015
Posts: 11
M
Malko Offline OP
Pikka bird
OP Offline
Pikka bird
M
Joined: Feb 2015
Posts: 11
So when the bot joins this should start, and run the code where it picks a random person, but it doesn't do anything.
Code:
on me:*:JOIN:#: {
  $+(.timerlottery.,#) 0 60 lottery $safe(#)
  {
    alias lottery {
      var %winner $nick($1,$r(1,$nick($1,0)))
      var %point $gettok(5,10,20,30,40,50,60,70,80,150,$r(1,10),44)
      var %inisection $+($1,.,%winner)
      writeini -n Points.ini %inisection Points $calc($readini(Points.ini,%inisection,Points) + %point)
      msg $1 %winner wins %point points!
    }
  }
}

Malko #251038 07/02/15 04:36 AM
Joined: Jul 2006
Posts: 4,149
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,149
We just went over how you cannot have a an alias inside an event...
And I just went over how you should be setting a variable on join and waiting for the on op event to trigger etc.


Code:
on me:*:join:#:set %justjoined $addtok(%justjoined,$chan,32)
on me:*:part:#:set %justjoined $remtok(%justjoined,$chan,32) | .timerlottery. $+ $chan off
on *:disconnect unset %justjoined | .timerlottery.* off
on *:op:#:{
 if ($opnick == $me) {
   if ($istok(%justjoined,$chan,32)) {
     $+(.timerlottery.,$chan) 0 60 lottery $safe($chan)
   }
   set %justjoined $remtok(%justjoined,$chan,32)
 }
}
alias lottery {
 var %winner $nick($1,$r(1,$nick($1,0)))
 var %point $gettok(5 10 20 30 40 50 60 70 80 150,$r(1,10),32)
 var %inisection $+($1,.,%winner)
 writeini -n Points.ini %inisection Points $calc($readini(Points.ini,%inisection,Points) + %point)
 msg $1 %winner wins %point points!
}
alias safe return $!decode( $encode($1-, m) ,m)
The $safe alias is required to prevent the /timer command from double evaluating the $chan value, which could result in an exploit (the value of $chan is not known since it can be any channel), read more here http://en.wikichip.org/wiki/mirc/msl_injection

This is untested but should work


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Wims #251039 07/02/15 05:12 AM
Joined: Feb 2015
Posts: 11
M
Malko Offline OP
Pikka bird
OP Offline
Pikka bird
M
Joined: Feb 2015
Posts: 11
Sorry i'm having trouble learning this language, its hard. I see what you meant by setting another variable though.
I read about the $safe and that's interesting. But i tested it and still didn't work, not outputting anything, its got the %justjoined in the variables though.

Malko #251040 07/02/15 05:27 AM
Joined: Jul 2006
Posts: 4,149
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,149
I edited my previous post, it had an error with the list of different number of points (I blame Raccoon and his commas for this grin )
The line to update is the one with $gettok, change to:
Code:
 var %point $gettok(5 10 20 30 40 50 60 70 80 150,$r(1,10),32)


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Wims #251041 07/02/15 05:39 AM
Joined: Feb 2015
Posts: 11
M
Malko Offline OP
Pikka bird
OP Offline
Pikka bird
M
Joined: Feb 2015
Posts: 11
Whoops! ok changed that! but still not outputting anything, so it should pick a random user every 60 seconds right?

Malko #251049 07/02/15 11:51 AM
Joined: May 2013
Posts: 140
R
Vogon poet
Offline
Vogon poet
R
Joined: May 2013
Posts: 140
maybe post your full script, updated with the suggestions already made to you. That way maybe you will get better advise on the whole script

Malko #251055 07/02/15 04:29 PM
Joined: Jul 2006
Posts: 4,149
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,149
I just tested the script, which works as expected, you may have conflicting scripts, I suggest putting this new one on a new remote file


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Wims #251068 07/02/15 09:53 PM
Joined: Feb 2015
Posts: 11
M
Malko Offline OP
Pikka bird
OP Offline
Pikka bird
M
Joined: Feb 2015
Posts: 11
Ok i went through and made some changes to the other script, here is the whole thing, lottery at the end. http://pastebin.com/KsHZmRfY
Thanks for helping

Page 1 of 2 1 2

Link Copied to Clipboard