egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

im in need of a timed event
Goto page 1, 2  Next
 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests
View previous topic :: View next topic  
Author Message
Gemster
Halfop


Joined: 04 Oct 2010
Posts: 51

PostPosted: Mon Feb 14, 2011 5:01 pm    Post subject: im in need of a timed event Reply with quote

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
Back to top
View user's profile Send private message
kenh83
Halfop


Joined: 08 Sep 2010
Posts: 61

PostPosted: Tue Feb 15, 2011 1:24 am    Post subject: Reply with quote

show us what you got so far.
Back to top
View user's profile Send private message
Gemster
Halfop


Joined: 04 Oct 2010
Posts: 51

PostPosted: Tue Feb 15, 2011 3:56 am    Post subject: Reply with quote

kenh83 wrote:
show us what you got so far.


What i have is this :

Code:
#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
Back to top
View user's profile Send private message
willyw
Revered One


Joined: 15 Jan 2009
Posts: 1175

PostPosted: Tue Feb 15, 2011 10:49 am    Post subject: Re: im in need of a timed event Reply with quote

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.

Quote:

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/1.6.20/tcl-commands.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/blcmdl5_crontab.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:



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:

 bind cron - "0 * * * *"  say_it

but, I haven't tested that far. Smile 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.
Back to top
View user's profile Send private message
willyw
Revered One


Joined: 15 Jan 2009
Posts: 1175

PostPosted: Tue Feb 15, 2011 10:54 am    Post subject: Re: im in need of a timed event Reply with quote

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.
Back to top
View user's profile Send private message
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3741
Location: Mint Factory

PostPosted: Tue Feb 15, 2011 1:32 pm    Post subject: Reply with quote

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

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

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

if not, then:
Code:

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.
Back to top
View user's profile Send private message
Gemster
Halfop


Joined: 04 Oct 2010
Posts: 51

PostPosted: Tue Feb 15, 2011 4:06 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3741
Location: Mint Factory

PostPosted: Tue Feb 15, 2011 4:16 pm    Post subject: Reply with quote

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

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. Embarassed
_________________
Once the game is over, the king and the pawn go back in the same box.


Last edited by caesar on Thu Feb 17, 2011 1:40 am; edited 2 times in total
Back to top
View user's profile Send private message
Gemster
Halfop


Joined: 04 Oct 2010
Posts: 51

PostPosted: Tue Feb 15, 2011 4:37 pm    Post subject: Reply with quote

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 Very Happy

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

Thanks
Gemster
Back to top
View user's profile Send private message
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3741
Location: Mint Factory

PostPosted: Tue Feb 15, 2011 4:47 pm    Post subject: Reply with quote

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:

bind cron - "* * * * *"  say_it
unbind cron - "* * * * *"  say_it

with:
Code:

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

The:
Code:

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.
Back to top
View user's profile Send private message
Gemster
Halfop


Joined: 04 Oct 2010
Posts: 51

PostPosted: Tue Feb 15, 2011 5:03 pm    Post subject: Reply with quote

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:
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 Very Happy If u never try u will never succeed.

Thanks
Gemster

Edit: sorry just seen your correction with the 0.
Back to top
View user's profile Send private message
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3741
Location: Mint Factory

PostPosted: Tue Feb 15, 2011 5:11 pm    Post subject: Reply with quote

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.. Smile

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

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.
Back to top
View user's profile Send private message
Gemster
Halfop


Joined: 04 Oct 2010
Posts: 51

PostPosted: Tue Feb 15, 2011 5:30 pm    Post subject: Reply with quote

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 Very Happy

And the if statements makes the "switch" a lot more easyer to understand now Very Happy

Well now im going to make another "bindcron" and try to use your code caesar Very Happy

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

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

Thanks
Gemster
Back to top
View user's profile Send private message
willyw
Revered One


Joined: 15 Jan 2009
Posts: 1175

PostPosted: Tue Feb 15, 2011 8:36 pm    Post subject: Reply with quote

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.
Smile

Quote:

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. Smile
Back to top
View user's profile Send private message
Gemster
Halfop


Joined: 04 Oct 2010
Posts: 51

PostPosted: Tue Feb 15, 2011 8:45 pm    Post subject: Reply with quote

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 Very Happy
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests All times are GMT - 4 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber