mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Jan 2011
Posts: 34
O
Ameglian cow
OP Offline
Ameglian cow
O
Joined: Jan 2011
Posts: 34
i want to make a script that for example displays the phrase hi (their nickname.)

on *:TEXT:hi:#:{ msg $chan hi $nick $+ . }

but i don't always want it to activate when the person says "hi". How can i make it so it randomly displays the message when the person says "hi"? crazy

Edit: in other words sometimes i want it to activate normally and other times randomly not activate

Last edited by ohaithar; 20/01/11 12:31 PM.
Joined: Jun 2007
Posts: 933
5
Hoopy frood
Offline
Hoopy frood
5
Joined: Jun 2007
Posts: 933
The first solution that comes to mind is:
Code:
on *:TEXT:hi:#:{
  var %r = $rand(1,N)
  if (%r == 1) msg $chan hi $nick $+ .
}

Where N is the 1 in N times you want it to happen on average. E.g. 1 in 3 times.

Joined: Jul 2006
Posts: 4,145
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,145
A good way is to use the random of $read
Create a file that contain random sentence with $nick etc, for exemple :
Quote:
Hi $nick $+ .
Hello $nick $+ , how are you ?
...
Then :
Quote:
on *:TEXT:hi:#:msg $chan $read(file)

The chosen line in the file will be evaluated so be careful.


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Jan 2011
Posts: 34
O
Ameglian cow
OP Offline
Ameglian cow
O
Joined: Jan 2011
Posts: 34
Ok thanks guys smile

Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Well, you may consider adding a trigger flood protection so that malicious people can't tamper with the script to screw with the client running the code.

Joined: Jan 2011
Posts: 34
O
Ameglian cow
OP Offline
Ameglian cow
O
Joined: Jan 2011
Posts: 34
i thought about that possibility as well but i don't know where to start in making that because i am still fairly new to scripting. I could sure use that if anyone is willing to tell me how it's done. grin

Joined: Jan 2003
Posts: 64
M
Babel fish
Offline
Babel fish
M
Joined: Jan 2003
Posts: 64
For your own protection, I would recommend picking a specific channel or channels where you're going to be doing this. Let me know if you'd be interested in a version that would only trigger if you were opped on the channel.

This code will put a ten second delay between each use.

Code:
on 1:text:hi:#:{
if ((%wait.ctime !isnum) || ((%wait.ctime isnum) && (%wait.ctime < $ctime))) {
/msg $chan Hi $nick
set %wait.ctime $calc($ctime + 10)
}
}

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
That's kind of complicated for what can be done with less code.

Code:
on *:text:hi:#: {
  if (%flood) { return }
  set -u10 %flood On

  ; The rest of the script goes here
}


Notes for OP:
I strongly recommend using a variable name that is unique to avoid conflicts with other scripts. %flood is too generic. I used it here just to be clear as to what the variable represents.

Also, this same flood control can be used anywhere you want. Insert those same 2 lines above any code you want to be protected. With that in mind, if you use the same variable every time, you will have global flood protection on any scripts that have this code. That means that no matter what command is used, you'll only reply once every 10 seconds (or whatever you change the 10 to). Depending on the number of commands you allow and the amount of response text you have for each and how often those are used, this can be necessary. If 20 people all use different commands once at the same time, you will be flooded off the network if the flood protection isn't global, for example. However, if you don't need global flood protection (usually you won't), then you can use different variable names for each flood control. That will let each command have their own 10 second flood protection such that even if one person uses one command, another person can use a different command within those 10 seconds without it being ignored. In most cases, this works well.


*** There is one benefit to using $ctime as shown in the post above and that is that it cannot get messed up due to mIRC crashing or being closed before the timer expires. However, it's still more than is necessary. There's an easy "fix" to prevent any problems with the flood control variables and it lets you use the code throughout your script without having a larger set of code everywhere. Just add the following to your script and name all your variables with the same beginning (you can change the beginning of course):

Code:
on *:start: { unset %flood.* }


Now, you might have something like %flood.hi and %flood.help and %flood.rules and such. This will guarantee that regardless of crashing or closing mIRC during the timer, your variable will still be unset. Again, I recommend something other than %flood for this, but it is at least somewhat "safer" to use when you add the ".whatever" to it.

Last edited by Riamus2; 20/01/11 08:03 PM.

Invision Support
#Invision on irc.irchighway.net
Joined: Jan 2011
Posts: 34
O
Ameglian cow
OP Offline
Ameglian cow
O
Joined: Jan 2011
Posts: 34
Thanks for the flood control, initially that's why i wanted the random part for the script. I knew it wouldn't protect me from flood but it would have kept the channel from being spammed, atleast by me. Now with the flood control i won't worry about spam and not being disconnected is a huge bonus.

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
One other note of the flood protection. You can set it per-user so that if two different people use the same trigger, it will show up for both, but if the same person uses it twice, it will only show once. You can even combine the normal method and that so that you have a 10 second (or whatever) protection for everyone, but you only let a command be done once every 30 minutes (or whatever) for the same person.

Example:
Code:
on *:text:hi:#: {
  if (%flood || $+(%,flood.,$nick)) { return }
  set -u10 %flood On
  set -u1800 %flood. $+ $nick On
  msg $chan Hello, $nick $+ .
}


For this example, you will never respond to "hi" more than once every 10 seconds (the main %flood variable) and you will not respond to "hi from the same nick more than once every 30 minutes (1800 seconds = 30 minutes). A variable will be set for each nick in the form %flood.nick . You can change that the same way you'd change %flood. Just replace all "flood" with whatever you want to use.

If you do plan on using long times like the 30min in this example, I definitely recommend the on start code I showed previously.


Invision Support
#Invision on irc.irchighway.net
Joined: Jan 2011
Posts: 34
O
Ameglian cow
OP Offline
Ameglian cow
O
Joined: Jan 2011
Posts: 34
even better smile

Joined: Jun 2013
Posts: 2
P
Bowl of petunias
Offline
Bowl of petunias
P
Joined: Jun 2013
Posts: 2
Code:
on *:text:hi:#: {
  if (%flood || $+(%,flood.,$nick)) { return }
  set -u10 %flood On
  set -u1800 %flood. $+ $nick On
  msg $chan Hello, $nick $+ .
}

this script is not working by me frown it is old version of the script may be? who can correct it?
Problem in this line?:
Code:
  if (%flood || $+(%,flood.,$nick)) { return }

Last edited by PrivetVsem; 19/06/13 03:52 PM.
Joined: Jun 2007
Posts: 933
5
Hoopy frood
Offline
Hoopy frood
5
Joined: Jun 2007
Posts: 933
Change it to:
Code:
if ((%flood) || ($($+(%,flood.,$nick),2))) { return }

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Oops. smile


Invision Support
#Invision on irc.irchighway.net
Joined: Jun 2013
Posts: 2
P
Bowl of petunias
Offline
Bowl of petunias
P
Joined: Jun 2013
Posts: 2
Thx, it working now, but how can i add delay 3 seconds before sending message answer?

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
/help /timer


Invision Support
#Invision on irc.irchighway.net

Link Copied to Clipboard