mIRC Home    About    Download    Register    News    Help

Print Thread
on *:text: script (random option) #229059 20/01/11 11:47 AM
Joined: Jan 2011
Posts: 34
O
ohaithar Offline OP
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.
Re: on *:text: script (random option) [Re: ohaithar] #229063 20/01/11 01:28 PM
Joined: Jun 2007
Posts: 933
5
5618 Offline
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.

Re: on *:text: script (random option) [Re: ohaithar] #229068 20/01/11 04:17 PM
Joined: Jul 2006
Posts: 3,726
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,726
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.


Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: on *:text: script (random option) [Re: Wims] #229070 20/01/11 05:32 PM
Joined: Jan 2011
Posts: 34
O
ohaithar Offline OP
Ameglian cow
OP Offline
Ameglian cow
O
Joined: Jan 2011
Posts: 34
Ok thanks guys smile

Re: on *:text: script (random option) [Re: Wims] #229073 20/01/11 06:28 PM
Joined: Jul 2007
Posts: 1,129
T
Tomao Offline
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.

Re: on *:text: script (random option) [Re: Tomao] #229074 20/01/11 07:00 PM
Joined: Jan 2011
Posts: 34
O
ohaithar Offline OP
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

Re: on *:text: script (random option) [Re: ohaithar] #229076 20/01/11 07:33 PM
Joined: Jan 2003
Posts: 64
M
MegaZeroX Offline
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)
}
}

Re: on *:text: script (random option) [Re: MegaZeroX] #229078 20/01/11 07:50 PM
Joined: Oct 2004
Posts: 8,330
Riamus2 Offline
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
Re: on *:text: script (random option) [Re: Riamus2] #229083 20/01/11 10:01 PM
Joined: Jan 2011
Posts: 34
O
ohaithar Offline OP
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.

Re: on *:text: script (random option) [Re: ohaithar] #229085 20/01/11 10:12 PM
Joined: Oct 2004
Posts: 8,330
Riamus2 Offline
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
Re: on *:text: script (random option) [Re: Riamus2] #229087 20/01/11 10:15 PM
Joined: Jan 2011
Posts: 34
O
ohaithar Offline OP
Ameglian cow
OP Offline
Ameglian cow
O
Joined: Jan 2011
Posts: 34
even better smile

Re: on *:text: script (random option) [Re: Riamus2] #242147 19/06/13 02:58 PM
Joined: Jun 2013
Posts: 2
P
PrivetVsem Offline
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.
Re: on *:text: script (random option) [Re: PrivetVsem] #242148 19/06/13 05:26 PM
Joined: Jun 2007
Posts: 933
5
5618 Offline
Hoopy frood
Offline
Hoopy frood
5
Joined: Jun 2007
Posts: 933
Change it to:
Code:
if ((%flood) || ($($+(%,flood.,$nick),2))) { return }

Re: on *:text: script (random option) [Re: 5618] #242153 19/06/13 10:42 PM
Joined: Oct 2004
Posts: 8,330
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Oops. smile


Invision Support
#Invision on irc.irchighway.net
Re: on *:text: script (random option) [Re: 5618] #242155 19/06/13 10:55 PM
Joined: Jun 2013
Posts: 2
P
PrivetVsem Offline
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?

Re: on *:text: script (random option) [Re: PrivetVsem] #242158 19/06/13 11:07 PM
Joined: Oct 2004
Posts: 8,330
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
/help /timer


Invision Support
#Invision on irc.irchighway.net