mIRC Home    About    Download    Register    News    Help

Print Thread
#273004 13/12/24 01:58 PM
Joined: May 2022
Posts: 84
F
Fernet Offline OP
Babel fish
OP Offline
Babel fish
F
Joined: May 2022
Posts: 84
Hello. This is a simple addon: just GUESS a number from 1 to 100
An user can attempt in a row, i mean after an attempt he can make another ine immediately (if wrong)
Code
on *:TEXT:!game*:#Alessandra:{
  if ($2 != $null) { set %number $rand(1,$2) | msg # Guess the number 1 to $2 | return }
  else /set %number $rand(1,100) | msg # Guess the number 1 to 100 | return
}
on *:TEXT:!number*:#Alessandra:{
  if (%number == $2) { msg # $nick $read(you.txt) you win! The number was  $+ %number $+  | unset %number | set %score $read(win.txt, s, $nick) | write -ds $+ $nick win.txt | write win.txt $nick $calc(%score + 1) | unset %score | return }
  if (%number >= $2) { msg # The number is higher than $2 | return }
  if (%number <= $2) { msg # The number is lower than $2 | return }
  else /halt
}
on *:TEXT:!score*:#Alessandra:{
  if ($2 == $null) {
    notice $nick Nick: --- Score: | play -n $nick win.txt points
  }
  else /msg # Score for  $+ $2 $+  $+ : $read(win.txt, s, $2) points
}

If the number is wrong I wish the user must wait (for example) 300sec before to can attempt again.
Thanks for help

Fernet #273005 14/12/24 11:44 AM
Joined: Jan 2012
Posts: 329
Pan-dimensional mouse
Offline
Pan-dimensional mouse
Joined: Jan 2012
Posts: 329
I reworked your script and added what you asked for. This code is not perfect and could be even better if I had more time, but it is better than the previous one.

Try using this script code:
Code
on *:TEXT:*:#Alessandra:{
  if ($1 == !game) {
    if ($2) { var %tn $2 | set %number $rand(1,%tn) }
    else { var %tn 100 | set %number $rand(1,%tn) }
    msg $chan Guess the number 1 to %tn | hfree -w number *
  }
  if ($1 == !number) {
    if (!%number) { msg $chan Come up with a new number: !game [number] | return }
    if (!$2) { notice $nick Correct syntax: !number <number> | return }
    if ($hget(number,$nick)) { notice $nick The next attempt is possible in $+(,$v1,) secs. | return }
    if ($2 > %number) { msg $chan The number is higher than $2 }
    if ($2 < %number) { msg $chan The number is lower than $2 }
    if ($2 == %number) {
      msg $chan $nick $read(you.txt) you win! The number was $+(,%number,)
      if ($read(win.txt,w,$+($nick,$chr(32),*))) {
        var %rn $readn, %score $gettok($read(win.txt,%rn),2,32)
        write $+(-l,%rn) win.txt $nick $calc(%score + 1)
      }
      else { write -i win.txt $nick 1 } | unset %number | hfree -w number * | return
    }
    hadd -mz number $nick 300 
  }
  if ($1 == !score) {
    if ($2) { 
      if ($read(win.txt,w,$+($2,$chr(32),*))) { msg $chan Score for $+(,$2,:) $read(win.txt,s,$2) points }
      else msg $chan here is no record for the player under the nickname: $+(,$2,)
    }
    else { notice $nick Nick: --- Score: | play -n $nick win.txt 1000 }
  }
}


🌐 http://forum.epicnet.ru 📜 irc.epicnet.ru 6667 #Code | mIRC scripts, help, discuss, examples
Epic #273006 14/12/24 08:17 PM
Joined: May 2022
Posts: 84
F
Fernet Offline OP
Babel fish
OP Offline
Babel fish
F
Joined: May 2022
Posts: 84
Originally Posted by Epic
I reworked your script and added what you asked for. This code is not perfect and could be even better if I had more time, but it is better than the previous one.

Try using this script code:
Code
on *:TEXT:*:#Alessandra:{
  if ($1 == !game) {
    if ($2) { var %tn $2 | set %number $rand(1,%tn) }
    else { var %tn 100 | set %number $rand(1,%tn) }
    msg $chan Guess the number 1 to %tn | hfree -w number *
  }
  if ($1 == !number) {
    if (!%number) { msg $chan Come up with a new number: !game [number] | return }
    if (!$2) { notice $nick Correct syntax: !number <number> | return }
    if ($hget(number,$nick)) { notice $nick The next attempt is possible in $+(,$v1,) secs. | return }
    if ($2 > %number) { msg $chan The number is higher than $2 }
    if ($2 < %number) { msg $chan The number is lower than $2 }
    if ($2 == %number) {
      msg $chan $nick $read(you.txt) you win! The number was $+(,%number,)
      if ($read(win.txt,w,$+($nick,$chr(32),*))) {
        var %rn $readn, %score $gettok($read(win.txt,%rn),2,32)
        write $+(-l,%rn) win.txt $nick $calc(%score + 1)
      }
      else { write -i win.txt $nick 1 } | unset %number | hfree -w number * | return
    }
    hadd -mz number $nick 300 
  }
  if ($1 == !score) {
    if ($2) { 
      if ($read(win.txt,w,$+($2,$chr(32),*))) { msg $chan Score for $+(,$2,:) $read(win.txt,s,$2) points }
      else msg $chan here is no record for the player under the nickname: $+(,$2,)
    }
    else { notice $nick Nick: --- Score: | play -n $nick win.txt 1000 }
  }
}

It looks it works. What if I want only owner can start it?
Thanks sir

Fernet #273007 14/12/24 09:45 PM
Joined: Jan 2012
Posts: 329
Pan-dimensional mouse
Offline
Pan-dimensional mouse
Joined: Jan 2012
Posts: 329
Originally Posted by Fernet
What if I want only owner can start it?

You can add an identifier to the conditional expression to check the status of a nick on a channel: $nick($chan,$nick,~)


Change the code part to this code fragment:
Code
if ($1 == !game && $nick($chan,$nick,~)) {
  if ($2) var %tn $2 | else var %tn 100 | set %number $rand(1,%tn)
  msg $chan Guess the number 1 to %tn | hfree -w number *
}


🌐 http://forum.epicnet.ru 📜 irc.epicnet.ru 6667 #Code | mIRC scripts, help, discuss, examples
Fernet #273008 15/12/24 08:09 AM
Joined: May 2022
Posts: 84
F
Fernet Offline OP
Babel fish
OP Offline
Babel fish
F
Joined: May 2022
Posts: 84
[10:44:40] <~`Chandra> !game
[10:44:40] <@noemi> Guess the number 1 to 100
[10:44:57] <@`BoToLa> !number 2000
[10:44:57] <@noemi> The number is higher than 2000

Last edited by Fernet; 15/12/24 09:47 AM.
Fernet #273009 15/12/24 10:03 AM
Joined: Jan 2012
Posts: 329
Pan-dimensional mouse
Offline
Pan-dimensional mouse
Joined: Jan 2012
Posts: 329
Ok. I made additional corrections to the code:
Code
on *:TEXT:*:#Alessandra:{
  if ($1 == !game && $nick($chan,$nick,~@)) {
    set %topnum $iif($2,$2,100) | set %number $rand(1,%topnum)
    msg $chan Guess the number 1 to %topnum | hfree -w number *
  }
  if ($1 == !number) {
    if (!%number) { msg $chan Come up with a new number: !game [number] | return }
    if (!$2) { notice $nick Correct syntax: !number <number> | return }
    if ($2 !isnum $+(1-,%topnum)) { notice $nick Possible range: !number $v2 | return }
    if ($hget(number,$nick)) { notice $nick The next attempt is possible in $v1 secs. | return }
    if ($2 > %number) { msg $chan The number $2 is greater than the hidden number. }
    if ($2 < %number) { msg $chan The number $2 is less than the hidden number. }
    if ($2 == %number) {
      msg $chan $nick $read(you.txt,nt) you win! The number was %number
      if ($read(win.txt,ntw,$nick *)) {
        var %rn $readn, %score $gettok($read(win.txt,nt,%rn),2,32)
        write $+(-l,%rn) win.txt $nick $calc(%score + 1)
      }
      else { write -i win.txt $nick 1 } | unset %number | hfree -w number * | return
    }
    hadd -mz number $nick 300
  }
  if ($1 == !score) {
    if ($2) { 
      if ($read(win.txt,ntw,$2 *)) { msg $chan Score for $+(,$2,:) $read(win.txt,nts,$2) points }
      else msg $chan There is no record in the database for a player with the nickname: $2
    }
    else { notice $nick Nick: --- Score: | play -nx $nick win.txt 1000 }
  }
}


🌐 http://forum.epicnet.ru 📜 irc.epicnet.ru 6667 #Code | mIRC scripts, help, discuss, examples
Epic #273010 15/12/24 01:48 PM
Joined: May 2022
Posts: 84
F
Fernet Offline OP
Babel fish
OP Offline
Babel fish
F
Joined: May 2022
Posts: 84
This one perfectly work sir. Just 2 thing:
Code
  if ($1 == !game && $nick($chan,$nick,~@)) {
Is ok if I set ($chan,$nick,~) so only owner can decide when to start a manche?
And...when a manche is finished, I wish the game go off.
I set a message:
Come up with a new number:STAY TUNED
But if I write !number X again, I got ALSO a message The next attempt is possible in XXX sec mentioning again the last manche, instead of only Come up with a new number:STAY TUNED

I wish (if possible) , when a manche is finished and someone write !number X , to receive only one warn : Come up with a new number:STAY TUNED

Thanks for help

Last edited by Fernet; 15/12/24 06:28 PM.
Fernet #273012 15/12/24 06:40 PM
Joined: Jan 2012
Posts: 329
Pan-dimensional mouse
Offline
Pan-dimensional mouse
Joined: Jan 2012
Posts: 329
The additional numeric parameter in the "!game [number]" command will help you set the upper limit of the range yourself, otherwise it will always be equal to the number 100, and the guessed number will be from 1 to 100. The secret number you are trying to guess is chosen randomly within the specified range and stored in the %number variable.

After all, that's what was intended in your code that you attached in the very first post? Or was this code not created by you?


🌐 http://forum.epicnet.ru 📜 irc.epicnet.ru 6667 #Code | mIRC scripts, help, discuss, examples
Epic #273013 16/12/24 03:17 PM
Joined: May 2022
Posts: 84
F
Fernet Offline OP
Babel fish
OP Offline
Babel fish
F
Joined: May 2022
Posts: 84
Originally Posted by Epic
The additional numeric parameter in the "!game [number]" command will help you set the upper limit of the range yourself, otherwise it will always be equal to the number 100, and the guessed number will be from 1 to 100. The secret number you are trying to guess is chosen randomly within the specified range and stored in the %number variable.

Yes sorry. I got it late and I couldn't remove my stupid question. Sorry again

Originally Posted by Epic
After all, that's what was intended in your code that you attached in the very first post? Or was this code not created by you?

Of course I started with a ground, with a template. Honestly I'm not able yet to give born to such difficult addon (I'm a violinmaker, not a programmer! This is just kinda hobby for me). And believe that I read Your forum...

My only problem is that message The next attempt is possible in XXX sec, when the game is unset. Shoud be enough just to have message Come up with a new number:STAY TUNED
And...

if ($1 == !game && $nick($chan,$nick,~@)) {

Is ok if I set ($chan,$nick,~) so only owner can decide when to start a manche?

Thanks

Last edited by Fernet; 16/12/24 05:23 PM.
Fernet #273014 16/12/24 05:20 PM
Joined: Jan 2012
Posts: 329
Pan-dimensional mouse
Offline
Pan-dimensional mouse
Joined: Jan 2012
Posts: 329
Originally Posted by Fernet
My only problem is that message The next attempt is possible in XXX sec, when the game is unset. Shoud be enough just to have message Come up with a new number:STAY TUNED
I don't quite understand the essence of your request due to poor translation, which can distort the meaning of the question, but I will try to guess and answer correctly...

The message "The next attempt is possible in XXX secs" is sent only to those users who have executed the command "!number <number>" once.
Then they should wait 300 seconds, as written in this command: hadd -mz number $nick 300
If someone guesses the secret number, the game resets all data, including hashes about the number of seconds to wait until the next attempt.

That is, if the bot is missing the variable %number, you will not be able to execute the command "!number", because this line will prevent it:
if (!%number) { msg $chan Come up with a new number: !game [number] | return }


If you want to hide the timeout before the next attempt from users and not write anything, then change this line:
if ($hget(number,$nick)) { notice $nick The next attempt is possible in $v1 secs. | return }

to: if ($hget(number,$nick)) { return }


In any case, from my modest testing, this message should not be visible to users when the game is stopped or has not yet been launched.


🌐 http://forum.epicnet.ru 📜 irc.epicnet.ru 6667 #Code | mIRC scripts, help, discuss, examples

Link Copied to Clipboard