mIRC Home    About    Download    Register    News    Help

Print Thread
Need help to make a user cooldown for my script #268420 30/01/21 11:03 PM
Joined: Jan 2021
Posts: 3
M
miiza Offline OP
Self-satisfied door
OP Offline
Self-satisfied door
M
Joined: Jan 2021
Posts: 3
Hello guys, I'm new to mIRC scripts, and did a "hi" script for the channels I'm in, the thing is, I want to make a user cooldown for my script, but don't know how, I tried to find something that fit my script but was unable do find it.

Here is the script:
Code
ON *:TEXT:*:#: {
  if (($1 = oi) || ($1 = oie) || ($1 = oii) || ($1 = oiie) || ($1 = oiii) || ($1 = ola) || ($1 = olá)) {
    msg # $nick Oi marsbmpHi  
  }
}


Can anyone help with this? Thanks

Re: Need help to make a user cooldown for my script [Re: miiza] #268425 03/02/21 02:50 PM
Joined: Jan 2004
Posts: 1,510
maroon Offline
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 1,510
DId you try searching the forum for the keyword cooldown? You weren't clear whether you want the cooldown to be per-user or have everyone share the same countdown. You can either put the countdown in a global %variable or in a hashtable item. You can either use /set's -uN switch that makes the variable be unset after N seconds, or use the same switch with /hadd to add a temporary item to the table. You can instead use the -z switch to set the variable/table-item to a number, which then decreases by 1 each second, then unsets rather than be <= 0.

When you create a per-user countdown, you would want to make a variable name or hashtable name that's not likely to use the same names used by someone else's script. i.e. if you're using a shared cooldown for all nicks, and you did "set -u30 %cooldown $nick" then both scripts using the %cooldown variable would be interfering with each other. If using a hashtable, you need to either create the table when mirc starts, or use the -m switch each time you add something to the table. To create a variable name, it's a little more complicated to create compound variable names containing the nick, which can be a different to create it than to check it.

For the vast majority of irc networks, they don't allow accented characters in the nick. But if there is such a network, and they view tést and tÉst as the same nick, that's not compatible with how mIRC checks %variable names and hashtable items, where those are 2 separate variables or 2 separate items. If that's the case, you'd need to always use $upper or $lower to standardize the variable name. For using a hashtable, which is easier, you can do something like this, assuming the table contains no itemnames which could collide with a nick string:

Code
if ($hget(tablename,$nick)) {
 do something when handling a cooldown that has not expired
}
else {
hadd -mu30 tablename $nick x
do something when beginning the countdown
}


The above assumes 30 seconds. If you want to have access to the remaining seconds, that number is in $hget(foobar,test).unset
If you instead did:
hadd -z tablename $nick 30
then $hget(tablename,$nick) returns the number that's the data for that table-item, which the -z switch causes to decrease each second.

To have the per-user cooldown be in a global variable, you can do like:

Code
if ( $eval( $+(%,variablename.,$nick) ,2) ) {
 do something when handling a cooldown that has not expired
}
else {
set -u30 $+(%,variablename.,$nick) x
do something when beginning the countdown
}


if using the -z switch, change the set to:
set -z $+(%,variablename.,$nick) 30

You sometimes see variables created with a different kind of compound form, where the equivalents would be like:

if ( %variablename. [ $+ [ $nick ] ] )
set -z %variablename. [ $+ [ $nick ] ] 30
set -u30 %variablename. [ $+ [ $nick ] ] x

You can change your compound if() statement with something that's easier to read and is more efficient:

if ( $istok(oi oie oii oiie oiii ola olá,$1,32) ) {

This checks if one of the tokens matches $1, and 32 is the codepoint for the space character.

Re: Need help to make a user cooldown for my script [Re: maroon] #268437 04/02/21 07:10 PM
Joined: Jan 2021
Posts: 3
M
miiza Offline OP
Self-satisfied door
OP Offline
Self-satisfied door
M
Joined: Jan 2021
Posts: 3
Thank you so much, I'm currently at work, when I arrive at home I'll try it out.

Re: Need help to make a user cooldown for my script [Re: maroon] #268438 05/02/21 12:08 AM
Joined: Jan 2021
Posts: 3
M
miiza Offline OP
Self-satisfied door
OP Offline
Self-satisfied door
M
Joined: Jan 2021
Posts: 3
I used the code for the per-user cooldown. It worked like a charm, I really appreciate the time you took to help me.

Thank you very much.