mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Aug 2012
Posts: 59
Maelish Offline OP
Babel fish
OP Offline
Babel fish
Joined: Aug 2012
Posts: 59
How would I write an IF statement that detects if I have said something over a period of time?

For example, if I have said Good Morning in the last 30 minutes. Or if I have not said Good Morning in the last 30 minutes.


Find Gamers, my player finder for tabletop RPGers and Wargamers.
Joined: Dec 2008
Posts: 1,515
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2008
Posts: 1,515
Try use this code:

Php Code:

ON *:INPUT:#: {
  if ($left($1,1) !== $comchar) && (!$ctrlenter) {
	if ($1- == Good morning) { set %last_good_morning $fulldate }
  }
}

alias last_good_morning {
  if (!%last_good_morning) { echo -a You did NOT said 'Good morning' yet! }
  elseif (%last_good_morning) { echo -a You said 'Good morning' in %last_good_morning . }
}
 


Use /last_good_morning to see when you said last time the 'good morning' phrase.


Need Online mIRC help or an mIRC Scripting Freelancer? -> https://irc.chathub.org <-
Joined: Aug 2012
Posts: 59
Maelish Offline OP
Babel fish
OP Offline
Babel fish
Joined: Aug 2012
Posts: 59
Very nice but how do you check if it was in the last 30 minutes?


Find Gamers, my player finder for tabletop RPGers and Wargamers.
Joined: Dec 2008
Posts: 1,515
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2008
Posts: 1,515
Try use this code:

Code:
ON *:INPUT:#: {
  if ($left($1,1) !== $comchar) && (!$ctrlenter) {
    if ($1- == Good morning) { set %last_good_morning $ctime $fulldate }
  }
}

alias last_good_morning {
  if (!%last_good_morning) { echo -a You did NOT said 'Good morning' yet! }
  elseif (%last_good_morning) { echo -a You said 'Good morning' on $gettok(%last_good_morning,2-,32) in $timeago($calc($ctime - $gettok(%last_good_morning,1,32))) . }
}

alias timeago { ; by SReject
  if (!$1) { return 0 }
  if ($1 !isnum) { return 0 }
  var %i = 31557600year, 2592000month, 604800week, 86400day, 3600hour, 60min, 1sec
  set -e %_tas $1
  var %r = $regsubex($regsubex(%i,/(\d+)([a-z]+)/g, $timeago_temp(\1,\2)),^(?:\b0\D+)+,)
  unset %_tas
  if ($prop !== all) { var %r = $gettok(%r,1-2,44) }
  var %ret = $regsubex(%r,/(?:^|\x2c )\b0[^\x2c]+/g,)
  var %ret = $replacex(%ret,years,$chr(32) years,year,$chr(32) year,months,$chr(32) months,month,$chr(32) month,weeks,$chr(32) weeks,week,$chr(32) week,days,$chr(32) days,day,$chr(32) day,hours,$chr(32) hours,hour,$chr(32) hour,mins,$chr(32) minutes,min,$chr(32) minute,secs,$chr(32) seconds,sec,$chr(32) second)
  return $iif(%ret,%ret ago,0)
}
alias timeago_temp { ; by SReject
  var %r = $floor($calc(%_tas / $1))
  dec %_tas $calc(%r * $1)
  return %r $+ $iif(%r == 1, $2, $2s)
}


Need Online mIRC help or an mIRC Scripting Freelancer? -> https://irc.chathub.org <-
Joined: Aug 2012
Posts: 59
Maelish Offline OP
Babel fish
OP Offline
Babel fish
Joined: Aug 2012
Posts: 59
Whoa, that turned out far more complicated than I expected!


Find Gamers, my player finder for tabletop RPGers and Wargamers.
Joined: Dec 2015
Posts: 148
Vogon poet
Offline
Vogon poet
Joined: Dec 2015
Posts: 148
Simplified version of it:
Code:
on *:input:#:if ($1- == Good morning) set -eu1800 %last_good_morning $ctime

alias last_good_morning echo $iif(%last_good_morning,You said it $duration($calc($ctime -$v1)) ago at $asctime($v1,HH:nn:ss) $+ .,You haven't said it in the last 30 minutes.)



EDIT:
Since I'm bored, I might as well do this:
Code:
;Input event that specifically triggers when you say something in a channel.
on *:input:#: {

  ;Check if the input matches the trigger (change the operator from "==" to "===" if you want it to be case sensitive).
  ;If you want, you could add checks here for $comchar & $ctrlenter.
  ;$comchar to check if the line is a command or not.
  ;$ctrlenter to check if it was sent by pressing CTRL+Enter. It's used to send /commands as normal text, so lines beginning with with the command character won't trigger.
  if ($1- == Good morning) {
  
    ;Sets "%last_good_morning" variable to the current $ctime, and makes mIRC unset the variable after 1800 seconds (30 minutes) or when you exit mIRC.
    set -eu1800 %last_good_morning $ctime
  }
}

;/last_good_morning alias
alias last_good_morning {

  ;Check if "%last_good_morning" variable contains something, it should always be $ctime or $null.
  ;If it does, the script tells you how long ago the $ctime was set to the variable and when, if not it says "You haven't said it in the last 30 minutes.".
  echo $iif(%last_good_morning,You said it $duration($calc($ctime -$v1)) ago at $asctime($v1,HH:nn:ss) $+ .,You haven't said it in the last 30 minutes.)
}

Also: /help



EDIT #2:
Instead of having an alias, you could just make the script whine at (and stop) you automatically when you're trying to say it again, or even both.
Code:
on *:input:#: {
  if ($1- == Good morning) {
    if (%last_good_morning) { echo You've already said it in the last 30 minutes! $duration($calc($ctime -$v1)) ago at $asctime($v1,HH:nn:ss) to be specific. | haltdef }
    else set -eu1800 %last_good_morning $ctime
  }
}

Here the $ctrlenter check would be useful, you could force the "good morning" text through the script even if it hasn't been 30 minutes.

If you want the alias too, take it from the the first or second code.

Last edited by Dazuz; 05/02/16 05:20 AM.
Joined: Aug 2012
Posts: 59
Maelish Offline OP
Babel fish
OP Offline
Babel fish
Joined: Aug 2012
Posts: 59
I have a script that says random responses to Good Morning or similar wording between 5am-10am. There is only a 1 in 20 chance of a response from the script. But it'll sometimes respond with it's version of Good Morning too close together timewise.

My goal was to make sure it didn't respond within a time period. So I picked 30 minutes for my original question at the top of this thread. But had no idea how lengthy the response would be.

@Dazuz: I had a good laugh because we both use rabbits as Avatars.

But...Your simplified version is much shorter, amazingly so! How hard would it be to make the the detection into an Alias that could be used in an if statement, because I think that is what your Edit does - or am I wrong?

Last edited by Maelish; 05/02/16 02:30 PM.

Find Gamers, my player finder for tabletop RPGers and Wargamers.
Joined: Dec 2015
Posts: 148
Vogon poet
Offline
Vogon poet
Joined: Dec 2015
Posts: 148
In that case the answer gets even easier. You can just use a variable in the text event to stop it from replying.

As an example:
Code:
on *:text:good morning:#: {
  if (!%staph) && ($asctime(HH) isnum 5-10) && ($rand(0,19)) {
    set -eu1800 %staph 1
    var %r = Response #1|Awesome response #2|Random response #3|Weird response #4|Something something #5
    msg # $gettok(%r,$rand(1,$numtok(%r,124)),124)
  }
}


With comments:
Code:
;Whenever someone says "good morning" the text event triggers.
on *:text:good morning:#: {

  ;Checks if %staph variable is empty, if current hour is between 5 and 10 and if $rand(1,20) equals to 1 (technically 1 in 20 chance).
  if (!%staph) && ($asctime(HH) isnum 5-10) && ($rand(1,20) == 1) {

    ;Sets %staph to 1 and makes mIRC unset it after 30 minutes or when you exit mIRC
    set -eu1800 %staph 1

    ;List of possible responses separated by | character
    var %r = Response #1|Awesome response #2|Random response #3|Weird response #4|Something something #5

    ;/msg to the channel with a random response.
    msg # $gettok(%r,$rand(1,$numtok(%r,124)),124)
  }
}

Joined: Aug 2012
Posts: 59
Maelish Offline OP
Babel fish
OP Offline
Babel fish
Joined: Aug 2012
Posts: 59
Oh nice, I think that is going to be a useful thing to experiment with. The comments are very useful, too bad more people don't think to do that. I'll learn more that way.

Thanks guys!

Last edited by Maelish; 09/02/16 03:23 PM.

Find Gamers, my player finder for tabletop RPGers and Wargamers.

Link Copied to Clipboard