|
Joined: May 2022
Posts: 84
Babel fish
|
OP
Babel fish
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)
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
|
|
|
|
Joined: Jan 2012
Posts: 329
Pan-dimensional mouse
|
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:
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 }
}
}
|
|
|
|
Joined: May 2022
Posts: 84
Babel fish
|
OP
Babel fish
Joined: May 2022
Posts: 84 |
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:
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
|
|
|
|
Joined: Jan 2012
Posts: 329
Pan-dimensional mouse
|
Pan-dimensional mouse
Joined: Jan 2012
Posts: 329 |
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:
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 *
}
|
|
|
|
Joined: May 2022
Posts: 84
Babel fish
|
OP
Babel fish
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.
|
|
|
|
Joined: Jan 2012
Posts: 329
Pan-dimensional mouse
|
Pan-dimensional mouse
Joined: Jan 2012
Posts: 329 |
Ok. I made additional corrections to the 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 }
}
}
|
|
|
|
Joined: May 2022
Posts: 84
Babel fish
|
OP
Babel fish
Joined: May 2022
Posts: 84 |
This one perfectly work sir. Just 2 thing: 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 TUNEDBut 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 TUNEDI 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 TUNEDThanks for help
Last edited by Fernet; 15/12/24 06:28 PM.
|
|
|
|
Joined: Jan 2012
Posts: 329
Pan-dimensional mouse
|
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?
|
|
|
|
Joined: May 2022
Posts: 84
Babel fish
|
OP
Babel fish
Joined: May 2022
Posts: 84 |
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 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 TUNEDAnd... 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.
|
|
|
|
Joined: Jan 2012
Posts: 329
Pan-dimensional mouse
|
Pan-dimensional mouse
Joined: Jan 2012
Posts: 329 |
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.
|
|
|
|
|