mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Jan 2006
Posts: 1
A
Mostly harmless
OP Offline
Mostly harmless
A
Joined: Jan 2006
Posts: 1
Well see, I've been working on a Hot Potato script for a while now. I've got it up and working, except for one problem - sometimes it explodes with the 'Everybody is idle!' message, even when everybody is not over the designated idle time (60 secs). Could someone take a look at it and tell me what I'm doing wrong?

Code:
; Hot Potato script.
; xx Written by Kentoukurai. xx

on *:start:{
  hmake hphof
  hload hphof hphof.txt
}

on *:text:!hotpotato*:#:{
  if (!$hget(hotpotato)) {
    hpstart $chan $nick
  }
}

on *:text:!pass*:#:{
  if ($chan == $hget(hotpotato, channel)) {
    hppass $nick $iif($2, $2)
  }
}

alias hpstart {
  if ($hget(hotpotato)) { hfree hotpotato }
  hmake hotpotato 100
  hadd hotpotato username $2
  msg $1 Hot Potato has been enabled by $hget(hotpotato, username) $+ ! Game starts in 10 seconds, get ready!
  .timer 1 10 hprlstrt $1
}

alias hprlstrt {
  hadd hotpotato channel $1
  .timer1 1 $rand(15, 60) hpend
  msg $hget(hotpotato, channel)  $+ $hget(hotpotato, username) $+  has the potato! Type !pass to pass!
}

alias hppass {
  if ($1 == $hget(hotpotato, username)) {
    hadd hotpotato users $nick($hget(hotpotato, channel), 0)
    unset %hpi
    :passtorand
    if (!%hpi) { %hpi = 0 }
    inc %hpi
    if (%hpi >= $hget(hotpotato, users)) { 
      unset %hpi
      hpend x
      .timer1 off
    }
    else { goto isidle }
    :isidle
    %hpnktmp = $nick($hget(hotpotato, channel), $rand(1, $hget(hotpotato, users)))
    if ($nick($hget(hotpotato, channel), %hpnktmp).idle > 60) { goto passtorand }
    elseif (%hpnktmp == $me) || (%hpnktmp == $1) { goto passtorand }
    else {
      hdel hotpotato username
      hadd hotpotato username %hpnktmp
      msg $hget(hotpotato, channel)  $+ $1 $+  passed the potato to  $+ $hget(hotpotato, username) $+ !
    }
  }
}

alias hpend {
  %hplosar = $hget(hotpotato, username)
  hadd hphof %hplosar $calc($hget(hphof, %hplosar) + 1)
  if ($1 == x) { msg $hget(hotpotato, channel) Everybody is idle! }
  msg $hget(hotpotato, channel) The potato exploded on  $+ %hplosar $+ ! %hplosar has been hit with the potato  $+ $hget(hphof, %hplosar) time $+ $iif($hget(hphof, %hplosar) != 1, s) $+ !
  hfree hotpotato
  hsave hphof hphof.txt
}

Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
You're using both 'named' and unnamed timers, since the unnamed timers increase in a sequential manner, your "named" timer (which you call 1) might be getting set/unset/reset at the wrong times. Try changing the name of your named timers to a word, rather than a number.

There are a number of programming tips and tricks that you could or should be using, that you aren't, however, I'm too tired to recode your script at this time. Maybe after I've gotten a few hours of rest.

Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Code:
    hadd hotpotato users $nick($hget(hotpotato, channel), 0)
    unset %hpi
    :passtorand
    if (!%hpi) { %hpi = 0 }
    inc %hpi
    if (%hpi >= $hget(hotpotato, users)) { 
      unset %hpi
      hpend x
      .timer1 off
    }
    else { goto isidle }
    :isidle
    %hpnktmp = $nick($hget(hotpotato, channel), $rand(1, $hget(hotpotato, users)))
    if ($nick($hget(hotpotato, channel), %hpnktmp).idle > 60) { goto passtorand }
    elseif (%hpnktmp == $me) || (%hpnktmp == $1) { goto passtorand }


The fault lies in here, your incrementing %hpi once for each time around, and if it goes over the total number of users in channel it trips out saying all idle.
However after incrementing it by one, you then randomly choose a nick, and if that nick is idle you go back and choose another (also if its the bot or the current nick), this menas you a prone to randomly choosing the same nick again which would misslead the count on total nicks checked, example 7 nicks in channel "bot current a b c d e" c d e are all idle, but in 7 attempts the following nicks are chosen "d e d bot d c current" this then trips the ALL IDLE.

You well have to insert some method, of ensuring you do not select the same nick twice.
A simple method would be to add all the nicks to a string then use $numtok( ) , $gettok( ) and $deltok( ) etc to select a nick at random from thos still unselected. However strings are limited to 930 or so characters so this might be to small.
or you could create a hidden window and write each nick into it, then use $line() & /dline to ensire no nick is repeated
or even a hashtable, writing each nick in to a numbered item, then using $hget().item, $hget() & hdel


Link Copied to Clipboard