mIRC Home    About    Download    Register    News    Help

Print Thread
[Twitch] Guessing numbers #256943 02/03/16 07:18 PM
Joined: Jul 2015
Posts: 9
F
Fattyshow Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
F
Joined: Jul 2015
Posts: 9
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.

Last edited by Fattyshow; 02/03/16 07:19 PM.

Digital Rocker on Twitch TV - Bassist
Re: [Twitch] Guessing numbers [Re: Fattyshow] #256945 02/03/16 09:47 PM
Joined: Dec 2015
Posts: 146
Dazuz Offline
Vogon poet
Offline
Vogon poet
Joined: Dec 2015
Posts: 146
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.

Last edited by Dazuz; 02/03/16 10:08 PM.