mIRC Homepage
Posted By: ohaithar on *:text: script (random option) - 20/01/11 11:47 AM
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
Posted By: 5618 Re: on *:text: script (random option) - 20/01/11 01:28 PM
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.
Posted By: Wims Re: on *:text: script (random option) - 20/01/11 04:17 PM
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.
Posted By: ohaithar Re: on *:text: script (random option) - 20/01/11 05:32 PM
Ok thanks guys smile
Posted By: Tomao Re: on *:text: script (random option) - 20/01/11 06:28 PM
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.
Posted By: ohaithar Re: on *:text: script (random option) - 20/01/11 07:00 PM
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
Posted By: MegaZeroX Re: on *:text: script (random option) - 20/01/11 07:33 PM
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)
}
}
Posted By: Riamus2 Re: on *:text: script (random option) - 20/01/11 07:50 PM
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.
Posted By: ohaithar Re: on *:text: script (random option) - 20/01/11 10:01 PM
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.
Posted By: Riamus2 Re: on *:text: script (random option) - 20/01/11 10:12 PM
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.
Posted By: ohaithar Re: on *:text: script (random option) - 20/01/11 10:15 PM
even better smile
Posted By: PrivetVsem Re: on *:text: script (random option) - 19/06/13 02:58 PM
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 }
Posted By: 5618 Re: on *:text: script (random option) - 19/06/13 05:26 PM
Change it to:
Code:
if ((%flood) || ($($+(%,flood.,$nick),2))) { return }
Posted By: Riamus2 Re: on *:text: script (random option) - 19/06/13 10:42 PM
Oops. smile
Posted By: PrivetVsem Re: on *:text: script (random option) - 19/06/13 10:55 PM
Thx, it working now, but how can i add delay 3 seconds before sending message answer?
Posted By: Riamus2 Re: on *:text: script (random option) - 19/06/13 11:07 PM
/help /timer
© mIRC Discussion Forums