mIRC Homepage
Posted By: FloydTheDuck Time left 'til event - script - 26/10/12 08:38 PM
I need help making a script. I'm new to the IRC language so any help is appreciated. I've tried looking online but can't figure out how to get it to work right.


Let's say an event occurs every 3 minutes. At 12:00, 12:03, 12:06, and so on recurring.

Basically what I would like is to be able to type

!timeleft
and have it say "1 min and 32 seconds until event"

or
!timealert
and have it say "I'll let you know when it's 15 seconds away" then "%name get ready, it's going to happen in 15 seconds"


I think it works with /timer and $timer... I've looked in the help section but have only figured out a way to automatically notify every 3 minutes. I don't want it to do it no matter what, only if someone says "!timeleft" I want it to tell them, and !timealert to alert them... so almost like it runs in the background unless requested, then it will actually /say that one time.

Thanks in advance. Hope this makes sense.
Floyd
Posted By: Loki12583 Re: Time left 'til event - script - 26/10/12 09:27 PM
Are you the one actually running the timer for these recurring events? If you are the solution is much simpler, you just check $timer().secs.

If you are not running the timer for these events and merely want to calculate values for people, this will do it:

Code:
on *:text:!timeleft:#:{
  var %timeleft = $timeleft($ctime(October 26 2012 17:00:00), 180)
  if (%timeleft isnum 0-) msg # $duration%timeleft) until event
}

on *:text:!timealert:#:{
  var %timeleft = $timeleft($ctime(October 26 2012 17:00:00), 180)
  var %offset = 15, %msgtime = $calc(%timeleft - %offset)
  if (%msgtime isnum 0-) .timer 1 %msgtime msg $safe(# $nick) get ready, it's going to happen in $duration(%offset)
}

alias timeleft {
  var %start = $1, %interval = $2, %timeleft

  if ($ctime <= %start) || (!%interval) { %timeleft = $calc(%start - $ctime) }
  else { %timeleft = $calc(%interval - ($ctime - %start) % %interval) }

  return %timeleft
}

alias safe return $!decode( $encode($1,m) ,m)


Only commands from channels are processed, and only channels are responded to. This can be changed easily to suit your need. The time calculation is done in $timeleft, you need to pass it the $ctime of the first event, and then the interval in seconds. If you supply a start time in the past without an interval, a negative value will be returned.

$safe is used when passing input into a timer to avoid possible exploits.
Posted By: hixxy Re: Time left 'til event - script - 26/10/12 09:32 PM
You would need to know the name of the timer that's triggering the recurring event, then you could use something like this:

Code:
alias recurring_timer_name { return recurring_timer_name }
alias reminder { 
  msg $1 %name get ready, it's going to happen in 15 seconds.
  .timereventalert off
  unset %name
}

on *:text:!timeleft:#:{ msg # $duration($timer($recurring_timer_name).secs) until event. }
on *:text:!timealert:#:{ 
  .timereventalert 1 $calc($timer($recurring_timer_name).secs - 15) reminder #
  msg # I'll let you know when it's 15 seconds away. 
  set %name $nick
}


Just replace recurring_timer_name with the name of your event timer.
Posted By: FloydTheDuck Re: Time left 'til event - script - 26/10/12 09:40 PM
I want to host the script so that others can use !timeleft and be notified. It should only run in one specific channel. Is that what you provided Loki? Reading thru it (I can read but can't write ;-) ) it looks to be that way.
Posted By: FloydTheDuck Re: Time left 'til event - script - 26/10/12 09:44 PM
So, just to be clear. I want to provide the ability for others to say !timeleft and it turn how much time is left. This isn't only for me to run, it's for others in the channel.

I tried using the whole block that Loki posted and I ran !timeleft and nothing returned.


Oh, and I run this in the 'Remote' scripts, right?
Posted By: hixxy Re: Time left 'til event - script - 26/10/12 10:14 PM
The one I gave you will do that. You just need to change the name of the timer in my script.

It runs in remotes.

Just change the '#' in the two 'on text' events to a specific channel name to have it only run in that channel.
Posted By: FloydTheDuck Re: Time left 'til event - script - 26/10/12 10:26 PM
I must be doing something wrong.

I pasted your script into 'remotes' and changed the rename_script... to 'test' (3 occurrences)

I tried typing !timealert and !timeleft and neither returned any values.
What am I missing?
Posted By: hixxy Re: Time left 'til event - script - 26/10/12 10:36 PM
Do you have a timer called 'test' running?

And you should change this:

alias recurring_timer_name { return recurring_timer_name }

To this:

alias recurring_timer_name { return test }
Posted By: FloydTheDuck Re: Time left 'til event - script - 26/10/12 10:41 PM
Yeh I tried /timertest 18:27 0 180 /say its going to happen

The timer ran every 3 minutes, but if I ran !timealert nothing happened.

I just tried copying/pasting what you had before (to undo what I had changed) and only change the {return recurring...} to {return test }

It still didn't work.

I also tried just doing /timertest but it wouldn't activate.

Sorry, must be frustrating working with someone like me smile
Posted By: hixxy Re: Time left 'til event - script - 26/10/12 11:05 PM
The bracket shouldn't be touching 'return' - not sure if that was just a typo on your part.

I typed /timertest 0 30 /say its going to happen, then I tried this:

Quote:
(00:01:10) <hixxy> !timeleft
(00:01:10) <hixxy_> 15secs until event.
(00:01:14) <hixxy> !timeleft
(00:01:14) <hixxy_> 12secs until event.
(00:01:17) <hixxy> !timeleft
(00:01:17) <hixxy_> 9secs until event.
(00:01:20) <hixxy> !timeleft
(00:01:20) <hixxy_> 6secs until event.
(00:01:26) <hixxy_> its going to happen
(00:01:27) <hixxy> !timeleft
(00:01:27) <hixxy_> 29secs until event.
(00:01:41) <hixxy> !timealert
(00:01:41) <hixxy_> I'll let you know when it's 15 seconds away.
(00:01:41) <hixxy_> hixxy get ready, it's going to happen in 15 seconds.
(00:01:56) <hixxy_> its going to happen
(00:02:01) <hixxy> !timealert
(00:02:01) <hixxy_> I'll let you know when it's 15 seconds away.
(00:02:10) <hixxy_> hixxy get ready, it's going to happen in 15 seconds.
(00:02:26) <hixxy_> its going to happen
(00:02:56) <hixxy_> its going to happen


Seems to be working okay!

If you didn't, please paste this into a new remote script file, as other on text events in any existing scripts you have loaded can affect this script's ability to run.
Posted By: FloydTheDuck Re: Time left 'til event - script - 27/10/12 01:48 PM
Originally Posted By: hixxy
The bracket shouldn't be touching 'return' - not sure if that was just a typo on your part.

I typed /timertest 0 30 /say its going to happen, then I tried this:

Seems to be working okay!

If you didn't, please paste this into a new remote script file, as other on text events in any existing scripts you have loaded can affect this script's ability to run.


The bracket touching was just a typo on my part. The script was exactly as you posted it. All I changed was what you said to change (which was only the 1 thing).
I tried running the exact timer you did.
But when I do !timeleft, etc. it doesn't work. So I must have something else off...

Do I need to do anything like run mIRC as administrator (windows 7)? I opened the location of the ini files and it saved the script to scripts.ini. Remote.ini has different info in it (my username and password to login).

There must be something about running scripts that I need to turn on or did wrong.
Posted By: hixxy Re: Time left 'til event - script - 27/10/12 05:48 PM
I just thought - are you trying to type the commands yourself?

The commands need to be used by other users and not the bot itself. See my example above; I connected as a second user (hixxy_) so that I could try it out.
Posted By: FloydTheDuck Re: Time left 'til event - script - 27/10/12 06:15 PM
Originally Posted By: hixxy
I just thought - are you trying to type the commands yourself?

The commands need to be used by other users and not the bot itself. See my example above; I connected as a second user (hixxy_) so that I could try it out.


That's what I was missing smile I never knew you couldn't run the commands yourself. I logged in as a second user and that worked.

How can I set the timer without it performing a command? (Such as, /timer 0 30 /say something). I don't want to flood the channel with unnecessary posts.

Also, how can I set the time of the event? The event occurs every 3 minutes beginning at the top of the hour, 12:03, 12:06, etc.

Loki had something that looked like that in his script, but I'm not sure how to add it to yours.

Thanks so much for your help!
Posted By: hixxy Re: Time left 'til event - script - 27/10/12 09:43 PM
You can use the /noop command which literally does nothing.

/timertest 12:00 0 180 noop
Posted By: FloydTheDuck Re: Time left 'til event - script - 28/10/12 01:55 PM
Thanks hixxy

Only problems I have are it doesn't respond with how much time is left, and it reminds you that the event will happen in 15 seconds whether its 15 seconds away or 2 minutes away.

[09:54] <mib_ukw4kd> !timeleft
[09:54] <FloydTheDuck> until event.
[09:54] <mib_ukw4kd> !timealert
[09:54] <FloydTheDuck> I'll let you know when it's 15 seconds away.
[09:54] <FloydTheDuck> mib_ukw4kd get ready, it's going to happen in 15 seconds.
Posted By: hixxy Re: Time left 'til event - script - 31/10/12 08:42 PM
Make sure you've spelt the timer name correctly in the $recurring_timer_name identifier.

The reason it's not saying how long is left is because the timer you're supplying doesn't exist.
Posted By: FloydTheDuck Re: Time left 'til event - script - 01/11/12 03:21 AM
I'm a dummy... First I had a typo, then when I went to correct the typo I accidentally took out 'return' before the timer name. It's working great now! Thanks smile
© mIRC Discussion Forums