mIRC Homepage
Posted By: Fattyshow [Twitch] Guessing numbers - 02/03/16 07:18 PM
How would I be able to make this script?
Currently I use this script that takes chat input and places it in a .txt file. Then I see who guessed the closest.

Code:
on *:TEXT:*:#: {
  if ($strip($1) == !guess) {
      write guesses.txt $2 $+  :  $+ $nick
  }
}


But I can't figure out how to get it so when a person uses it twice, it overwrites his last input.

I tried but this somehow only checks the last line of the text file.
Code:
write -dl $+ $readn(guesses.txt, w, *$nick*) guesses.txt


Then I also need an admin only command like !result x which then checks in all the entries who guessed the closest to the x given with the !result command.
Posted By: Dazuz Re: [Twitch] Guessing numbers - 02/03/16 09:47 PM
Whenever storing/reading/whatever data, hash tables are highly recommended. They're fast and easy to use.

Code:
on *:text:!guess *:#:if ($hget(guess)) && ($2 isnum) hadd guess $nick $2

on *:text:!result *:#: {
  if ($nick !isop #) noop
  elseif ($2 !isnum) .notice $nick Invalid input. Use as: !result <number>
  else {
    var %x = 1,%a $2,%b 99999999,%n n/a n/a
    while ($hget(guess,%x).item) {
      tokenize 32 $v1 $hget(guess,$v1)
      if ($abs($calc($2 -%a)) < %b) var %b = $v1,%n $1 $2
      inc %x
    }
    tokenize 32 %b %n
    .notice $nick Closest guess was $qt($3) by $2 (Difference: $1 $+ )
  }
}

on *:text:!start:#:if ($nick isop #) hfree -w guess | hmake guess | .notice $nick Started!

on *:text:!stop:#:if ($nick isop #) hfree -w guess | .notice $nick Stopped!


No idea how admins are identified, but currently only operators can use the !result, !start and !stop commands.

"!start" starts the thing, "!stop" stops it and "!result <number>" gives you the best answer.
© mIRC Discussion Forums