This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

im in need of a timed event

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
G
Gemster
Halfop
Posts: 51
Joined: Mon Oct 04, 2010 5:43 pm

im in need of a timed event

Post by Gemster »

Hi, im new to tcl, well been trying to learn it for like 3 days only.

Anyways, i need a simple script that when i do .starttss trigger in a channel it will start a timer and every hour it will do this command "privmsg operserv tssync"

then on trigger .stoptss it stops it. I tryed useing the timer and utimer but it failed big time :/


Thanks
Gemster
k
kenh83
Halfop
Posts: 61
Joined: Wed Sep 08, 2010 11:22 am

Post by kenh83 »

show us what you got so far.
G
Gemster
Halfop
Posts: 51
Joined: Mon Oct 04, 2010 5:43 pm

Post by Gemster »

kenh83 wrote:show us what you got so far.
What i have is this :

Code: Select all

#timer 1 pingserver
proc tssync {} {
	putquick "PRIVMSG ###1 :cool boobs111"
	timer 1 tssync
}
As you can see this fails, I also need a trigger to call this event on ".starttss" and also a tigger to stop it on "stoptss"

Thanks
Gemster
w
willyw
Revered One
Posts: 1203
Joined: Thu Jan 15, 2009 12:55 am

Re: im in need of a timed event

Post by willyw »

Gemster wrote:Hi, im new to tcl, well been trying to learn it for like 3 days only.
Congrats!
Hang in there. TCL and Eggdrops can be a lot of fun.
Anyways, i need a simple script that when i do .starttss trigger in a channel it will start a timer and every hour it will do this command "privmsg operserv tssync"

then on trigger .stoptss it stops it. I tryed useing the timer and utimer but it failed big time :/

Some things that come to mind:

I hope you are using Eggdrop version 1.6.20 . It has a few new features, and what I'm going to talk about is one of them. In other words, my idea won't work on version 1.6.19, or older.


Go here:
http://www.eggheads.org/support/egghtml ... mands.html
or, if you have a copy of tcl-commands.doc stored locally on your computer, open it for reading.
Text search it, and find information about a new bind - cron
Read that.
Hold that thought.
Go here:
http://ss64.com/bash/crontab.html
and here:
http://linux.about.com/od/commands/l/bl ... rontab.htm
and/or do some googling for instructions on how to use crontab commands.... this is what you'll need to use this bind.


Here's a rough example of what I come up with:

Code: Select all



bind pub - "!starttss" tss_start
bind pub - "!stoptss" tss_stop


proc tss_start {nick uhost handle chan text} {

        bind cron - "* * * * *"  say_it

}



proc say_it {min hour day month weekday} {

        putserv "privmsg ###1 : whatever you want to say goes here "
}


proc tss_stop {nick uhost handle chan text} {

        unbind cron - "* * * * *"  say_it

}


You can find the bind and unbind commands in tcl-commands.doc too.

Don't forget to change ###1 to whatever channel you really use.

As it is above, it will announce every minute. You dont' want that.
I think you will want:

Code: Select all

 bind cron - "0 * * * *"  say_it
but, I haven't tested that far. :) With the above mentioned reading, and some experimenting, you'll be able to determine that. Or somebody else here might comment on the use of crontabs.

I hope this helps.
w
willyw
Revered One
Posts: 1203
Joined: Thu Jan 15, 2009 12:55 am

Re: im in need of a timed event

Post by willyw »

Gemster wrote:Hi, im new to tcl, well been trying to learn it for like 3 days only.
....
You might like to check out:
http://suninet.the-demon.de/
I found it VERY helpful.
(I keep it bookmarked, and still reference it occasionally)

Next, tcl-commands.doc that I mentioned earlier. You might as well get it onscreen whenever you begin to work with TCL for Eggdrop. It is THAT good.

Last, open this page:
http://www.tcl.tk/man/tcl8.5/TclCmd/contents.htm
and keep it open when working with TCL.
It too, is THAT helpful.

I hope these three things help you get a good start with TCL for Eggdrops.
I'm not a guru at it...I just have fun with it.... but these three things sure do help me.
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

If you are on eggdrop 1.6.20 then this should do it:

Code: Select all

bind cron - {* */1 * * *} cron:sync

proc cron:sync {minute hour day month weekday} {
   putserv "PRIVMSG OperServ :tssync"
}
if not, then:

Code: Select all

bind time - "00 * * * *" time:sync

proc time:sync {min hour day month year} {
   putserv "PRIVMSG OperServ :tssync"
}
Now this will send that message every hour. I haven't quite understood the ".starttss trigger in a channel" part. The 'tssync' command sent to OperServ syncs something on that specific channel or it's something on the server side?
Once the game is over, the king and the pawn go back in the same box.
G
Gemster
Halfop
Posts: 51
Joined: Mon Oct 04, 2010 5:43 pm

Post by Gemster »

Thanks willyw, i will defo take a look at them links and bookmark as ive wanted to learn tcl for months but everytime i start i get cut off by something i cant get past.

caesar the ".starttss trigger in a channel" basically if i type .starttss in a channel this would trigger the timer on the eggdrop. And yes the tssync synizes all servers thats linked, its a anope mod thats installed.

Yes im useing eggdrop 1.6.20

Thanks
Gemster
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Just as I thought, it's something on server side.

Code: Select all

bind pub n .tssync switch:sync

proc switch:sync {nick uhost handle chan text} {
  switch -nocase -- [lindex [split $text] 0] {
    "on" {
      putserv "NOTICE $nick :TSSync turned on."
      bind cron - {* */1 * * *} cron:sync
    }
    "off" {
      putserv "NOTICE $nick :TSSync turned off."
      unbind cron - {* */1 * * *} cron:sync
    }
    default {
      putserv "NOTICE $nick :Use .tssync on/off."
    }
  }
}

proc cron:sync {minute hour day month weekday} {
  putserv "PRIVMSG OperServ :tssync"
}
Just .tssync on/off.

Edits:
1. Added '-nocase' to switch to make it 'case-insensitive'.
2. Fixed the switch. Thanks thommey. :oops:
Last edited by caesar on Thu Feb 17, 2011 1:40 am, edited 2 times in total.
Once the game is over, the king and the pawn go back in the same box.
G
Gemster
Halfop
Posts: 51
Joined: Mon Oct 04, 2010 5:43 pm

Post by Gemster »

Thanks caesar,

Im useing willyw post atm as that was the first 1 i have tested and works but i do love the concept of using ".tssync on/off" as this would make things a lot easyer but there are a few things i dont understand atm with your post like:

bind pub n
switch:
lindex
split

If you could be so kind to explain these maybe i can combine both posts together to work how i need it :D

yes i could just copy and paste and use it but that wont help me to learn it.

Thanks
Gemster
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

You don't need to join anything, either use mine or stick willyw's if you are happy with it.

Have you checked the second link willyw mentioned?

Apart from 'bind pub' (that you can find in tcl-commands.doc and 'n' is a flag) all is explained in there. Here's some direct links to what you wanted: lindex, switch and split.

Basically the two codes do the same thing, the difference is the 'switch' with that I used 1 'proc' instead of two to start/stop the 3rd bind. His 'cron' bind is incorrect, as right now it will trigger (execute) the 'say_it' every minute. If you want to stick with his then replace:

Code: Select all

bind cron - "* * * * *"  say_it
unbind cron - "* * * * *"  say_it
with:

Code: Select all

bind cron - {* */1 * * *}  say_it
unbind cron - {* */1 * * *}  say_it
The:

Code: Select all

bind cron - "0 * * * *"  say_it 
is correct, as it will trigger (execute) when the minute is 0, meaning every hour.
Once the game is over, the king and the pawn go back in the same box.
G
Gemster
Halfop
Posts: 51
Joined: Mon Oct 04, 2010 5:43 pm

Post by Gemster »

Well you see this is where i get confused as i read a bit about the bind "cron" and it says u cant use flags.

Then i see you use "n" for global owners that i would change to m as i have no users on the bot at all and dont think there ever will be but i could use the "if {isop" to allow chan ops to access some commands that i make in the future.
also you sed his 3rd bind

Code: Select all

bind cron - "0 * * * *"  say_it
would do "say_it" every minute, atm i have it runnning with the 0 and as off yet it hasent done anything as its hasent been an hour yet.

I understand that all types of coding is confussing at first, i know this as i self taught myself mirc scripting, php, html, java and some OPP and all coding is different in many ways but some does look simler in most cases like the if staments.

Im sure ill get there in the end :D If u never try u will never succeed.

Thanks
Gemster

Edit: sorry just seen your correction with the 0.
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

I used the 'n' flag on the 'pub' bind, not on cron. You can change the flag to whatever you wish, or replace it with '*' and add an if statement in the proc to allow channel operators to use it for instance.

I'm not 100% sure about that "0 * * * *" mask, theoretically it should execute at minute 0, and since there's only 1 minute 0 at every hour.. :)

The 'switch' statement can be translated in 3 simple 'if' statements:

Code: Select all

if {user input after the .tssync is on} {
  #do this
}
if {user input after the .tssync is off} {
  #do this
}
if {user input after the .tssync is not on nor off} {
  #do this
}
Once the game is over, the king and the pawn go back in the same box.
G
Gemster
Halfop
Posts: 51
Joined: Mon Oct 04, 2010 5:43 pm

Post by Gemster »

Thanks a lot guys,

Just a reply to the "0 * * * *" mask, after testing it i see that it does run at ever :00 past the hour :D

And the if statements makes the "switch" a lot more easyer to understand now :D

Well now im going to make another "bindcron" and try to use your code caesar :D

Just 1 question tho, what if i want it to run every 2 hours ?

Like this: {* */2 * * *}

Thanks
Gemster
w
willyw
Revered One
Posts: 1203
Joined: Thu Jan 15, 2009 12:55 am

Post by willyw »

Gemster wrote:Thanks willyw, i will defo take a look at them links and bookmark as ive wanted to learn tcl for months but everytime i start i get cut off by something i cant get past.
...
Keep reading, keep experimenting, and keep coming here when you get stuck.
:)
but there are a few things i dont understand ...

bind pub n
switch:
lindex
split
Seeing the above, makes me highly recommend that you visit the Suninet TCL guide that I mentioned previously.
Here's the link again:
http://suninet.the-demon.de/
Three out of those four, are covered there.

That site is the kind that you can start at the beginning, and read everything, step-by-step, through to the end.
You can use that site for reference,... picking out what you want.... but for beginners, it really is a help to start at the beginning there, and let it guide you through.

Try it. :)
G
Gemster
Halfop
Posts: 51
Joined: Mon Oct 04, 2010 5:43 pm

Post by Gemster »

Ya willyw, i already have them book marked
my way of learning is from the top to the bottom and making scripts as i go, but this timer thing i needed asap among a few other little events that i managed on my own with. The rest is learning and building to what ive already got.

Thanks for both u and caesar, its always good to get a starting point to work from, in my case it was timers lol

Thanks again
Gemster

P.S - hopefully u will see me here in the future helping others :D
Post Reply