0

This piece of code is meant to create a variable when a person joins a channel. Then it is supposed to increase that variable every second that a person remains in the channel. Then it should check to see if that variable reaches 15, which would mean the person has remained in the channel for 15 seconds. If true, it should do a conglomerate of different actions. But that's where the code stops working. The 15-second code is never triggered and I don't know why.

on *:JOIN:*: {
        inc -c %timeinchan. $+ $nick
        if (%timeinchan. $+ $nick == 15) {
          set %tempstats. $+ $nick $read(scores.fil, nr, $lower($nick))
          set %temppoints. $+ $nick $gettok(%tempstats. $+ $nick,2,59)
          set %newpoints. $+ $nick $calc(%temppoints. $+ $nick + 5)
          set %newstats $replace(%tempstats. $+ $nick, %temppoints $+ $nick, %newpoints. $+ $nick)
          write -s $+ $nick scorestest.fil %newstats
          msg $chan $Nick has been awarded 5 points for staying in the channel for 15 seconds. }
      }

Today, I thought of using a while loop as a possible solution. Something like this:

on *:JOIN:*: {
  while ($nick ison $chan) && ($nick != $me) { 
    inc -c %timeinchan. $+ $nick
    if (%timeinchan. $+ $nick == 15) {
      set %tempstats. $+ $nick $read(scores.fil, nr, $lower($nick))
      set %temppoints. $+ $nick $gettok(%tempstats. $+ $nick,2,59)
      set %newpoints. $+ $nick $calc(%temppoints. $+ $nick + 5)
      set %newstats $replace(%tempstats. $+ $nick, %temppoints $+ $nick, %newpoints. $+ $nick)
      write -s $+ $nick scorestest.fil %newstats
      msg $chan $Nick has been awarded 5 points for staying in the channel for 15 seconds. }
  }

But this doesn't work either. In fact, once someone joins a channel, the script makes mIRC stall, freeze and then crash.

So...

Any suggestions?

2 Answers2

0

first, you dont need a "*" on on join event, since on join events will only happens in a channel

by the way, events wont happen on on join event, if no one joins, thats why it is not working
why dont you use timers?

replace the version you have with this one

on *:JOIN:#: {
.timer $+ $nick 0 15 checknick $nick $chan
}

alias checknick {
if ($1 ison $2) {
set %tempstats. $+ $1 $read(scores.fil, nr, $lower($1))
set %temppoints. $+ $1 $gettok(%tempstats. $+ $1,2,59)
set %newpoints. $+ $1 $calc(%temppoints. $+ $1 + 5)
set %newstats $replace(%tempstats. $+ $1, %temppoints $+ $1, %newpoints. $+ $1)
write $+(-,w,*,$1,*) scorestest.fil %newstats
msg $2 $1 has been awarded 5 points for staying in the channel for 15 seconds. }
}

so, everytime someone joins in a channel, it will activate a timer with their name after 15 seconds, it will check if nick is on channel, and then will apply the points on their nick

while conditions needs variables to work, so

while ($nick ison $chan) && ($nick != $me) { 

since $nick will always be on channel on on join event, it will always be true

tell me if its that what you want

Sirius_Black
  • 471
  • 3
  • 11
  • Ah, timers! I should've thought of that! I'll get back to you after I apply it. Thank you! This seems like it will work. Going to try it right now... – Ricardo Pomalaza Jul 10 '14 at 04:18
  • Alright, it worked! Although, the variables with the $+ $1 used in the $read() and $gettok() and $calc() segments weren't working, so I had to use the entire piece of code instead of the variable. Made the whole process much more complex and time-consuming but at least it works now. Thanks! If you could, explain why $gettok(%tempstats. $+ $1,2,59) didn't work. It was suppose to give me the same result as $gettok($read(scores.fil, nr, $lower($1)),2,59) but it didn't, it gave me nothing. $read(scores.fil, nr, $lower($1)) did work though so I had to copy and paste that entire segment instead. :/ – Ricardo Pomalaza Jul 10 '14 at 14:35
  • you can use another timer to set the other variabels, since this event will happen at the same time, %tempstats. $+ $1 = 0, and the other variables set %temppoints. $+ $1 $gettok(%tempstats. $+ $1,2,59) are too, by the way, you can use $+(%tempstats,.,$1) instead – Sirius_Black Jul 10 '14 at 23:28
0

I haven't programmed in mIRC for many years, but here's a problem at a glance:

set %tempstats. [ $+ [ $1 ] ] Value

The []-brackets attach $1 to the variable.

Nic
  • 12,220
  • 20
  • 77
  • 105
baudsmoke
  • 99
  • 1
  • 9