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 

[Solved] Run Command Once an Hour Only

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests
View previous topic :: View next topic  
Author Message
MIODude
Voice


Joined: 09 Oct 2006
Posts: 32

PostPosted: Thu Aug 06, 2009 7:42 pm    Post subject: [Solved] Run Command Once an Hour Only Reply with quote

hi - I'm using a game script.. really fun called FishingAndHunting. You type !cast or !hunt, and it does the little command.. But - people keep running it over and over until they get the top score.. so I want to limit it to once per hour per nick.

I have the code that i found searching here.. but, it appears that it resets everytime they run the command.. i'd rather it not reset the counter, and instead tell them how many seconds left.

Here is the full code with teh changes I made.. I've removed some of the random events to cut down on the code

I used Throttled and Throttled2 procs so that the timer would be different for each command (!cast and !hunt). What can i do so that

1) It doesn't keep resetting the timer
2) it tells each person how much time they have left
3) Optional: Would be cool if could allow 3 per hour? Then on 4th attempt it locks user out for 1 hour duration


Code:

bind pub - !hunt hunt
bind pub - !cast fish
bind pub - !trophy trophy
bind msg o newmonth newmonth

set hunttargets {
"bear"
}

set fish {
"Salmon"
}

set huntplaces {
"in some bushes"
}

set fishplaces {
"Stream"
}

proc hunt {nick uhost hand chan args} {
 if {![throttled $uhost:#CHANNEL 3600]} {
global hunttargets fish fishplaces huntplaces
   set huntplace [lindex $huntplaces [rand [llength $huntplaces]]]
   set critter [lindex $hunttargets [rand [llength $hunttargets]]]
      if ![file exists "hunttrophy"] {
       set f [open "hunttrophy" w]
       puts $f "Nerfbendr 5 Ant"
       close $f
      }
   set f [open "hunttrophy" r]
   gets $f huntrecord
   close $f
   set maxweight [lindex $huntrecord 1]
      set maxweight [expr $maxweight + 100]
   set weightnumber [rand $maxweight]
   putserv "PRIVMSG #CHANNEL :You hide $huntplace and wait for something to wander by..."
   putserv "privmsg #CHANNEL :You think you hear something and fire wildly in that direction..."
   if [rand 2] {
      putserv "privmsg #CHANNEL :Congratulations, $nick! You just bagged yourself a $weightnumber pound $critter!"
   } else {
      putserv "privmsg #CHANNEL :Rats...you missed it, $nick! Better luck next time!"
      return 1
   }
set f [open "hunttrophy" r]
gets $f huntrecord
close $f
if { $weightnumber > [lindex $huntrecord 1] } {
   putserv "privmsg #CHANNEL:Wow!!! That's a new record! Way to go, $nick! Type !trophy to see it!"
   putserv "privmsg $chan :$nick just bagged a $weightnumber pound $critter and set a new record!"
   set f [open "hunttrophy" w]
   puts $f "$nick $weightnumber $critter"
   close $f
   return 1
} else {
   putserv "privmsg #CHANNEL :Sorry $nick...that's not a new record! Good try, though!"
   return 1
}
}
       putserv "privmsg #CHANNEL :Sorry $nick - You need to wait 60 minutes between attempts!"
}

proc fish {nick uhost hand chan args} {
   if {![throttled2 $uhost:#CHANNEL 3600]} {
global hunttargets fish fishplaces huntplaces
   set fishplace [lindex $fishplaces [rand [llength $fishplaces]]]
   set fishtocatch [lindex $fish [rand [llength $fish]]]
      if ![file exists "fishtrophy"] {
       set f [open "fishtrophy" w]
       puts $f "Nerfbendr 5 Guppie"
       close $f
      }
   set f [open "fishtrophy" r]
   gets $f fishrecord
   close $f
   set maxweight [lindex $fishrecord 1]
   set maxweight [expr $maxweight + 100]
   set weightnumber [rand $maxweight]
   putserv "PRIVMSG #CHANNEL :You cast your line into a $fishplace and wait for a bite..."
   putserv "privmsg #CHANNEL :You feel a tug on your line and reel it in..."
   if [rand 2] {
      putserv "privmsg #CHANNEL :Congratulations, $nick! You just caught yourself a $weightnumber pound $fishtocatch!"
   } else {
      putserv "privmsg #CHANNEL :Rats...it got away, $nick! Better luck next time!"
      return 1
   }
set f [open "fishtrophy" r]
gets $f fishrecord
close $f
if { $weightnumber > [lindex $fishrecord 1] } {
   putserv "privmsg #CHANNEL :Wow!!! That's a new record! Way to go, $nick! Type !trophy to see it!"
   putserv "privmsg $chan :$nick just caught a $weightnumber pound $fishtocatch and set a new record!"
   set f [open "fishtrophy" w]
   puts $f "$nick $weightnumber $fishtocatch"
   close $f
   return 1
} else {
   putserv "privmsg #CHANNEL :Sorry $nick...that's not a new record! Good try, though!"
   return 1
}

}
       putserv "privmsg #CHANNEL :Sorry $nick - You need to wait 60 minutes between attempts!"

}

proc newmonth {nick uhost hand chan args} {
global hunttargets fish fishplaces huntplaces
set f [open "fishtrophy" w]
puts $f "Nerfbendr 5 Guppie"
close $f
set f [open "hunttrophy" w]
puts $f "Nerfbendr 5 Ant"
close $f
putserv "privmsg $chan :Online hunting and fishing scores have been reset! Type !cast or !hunt to play!"
return 1
}

proc trophy {nick uhost hand chan args} {
global hunttargets fish fishplaces huntplaces

if ![file exists "fishtrophy"] {
set f [open "fishtrophy" w]
puts $f "Nerfbendr 5 Guppie"
close $f
}
if ![file exists "hunttrophy"] {
set f [open "hunttrophy" w]
puts $f "Nerfbendr 5 Ant"
close $f
}
set f [open "fishtrophy" r]
gets $f fishrecord
close $f
set f [open "hunttrophy" r]
gets $f huntrecord
close $f
putserv "privmsg $chan :[lindex $fishrecord 0] holds the fishing record when they caught a [lindex $fishrecord 1] pound [lrange $fishrecord 2 end]!"
putserv "privmsg $chan :[lindex $huntrecord 0] holds the hunting record when they bagged a [lindex $huntrecord 1] pound [lrange $huntrecord 2 end]!"
return 1
}


proc throttled {id time} {
   global throttled
   if {[info exists throttled($id)]} {
      putserv "privmsg #CHANNEL :You have $time left before next hunting attempt!"
      return 1
   } {
      set throttled($id) [utimer $time [list unset throttled($id)]]
   
      return 0
   }
}

proc throttled2 {id time} {
   global throttled2
   if {[info exists throttled2($id)]} {
     putserv "privmsg #CHANNEL :You have $time left before next fishing attempt!"
      return 1
   } {
      set throttled2($id) [utimer $time [list unset throttled2($id)]]
      return 0
   }
}



Props to Shawn Roles (Nerfbendr) for a great and fun script Smile


Last edited by MIODude on Sat Aug 08, 2009 3:22 pm; edited 1 time in total
Back to top
View user's profile Send private message
MIODude
Voice


Joined: 09 Oct 2006
Posts: 32

PostPosted: Sat Aug 08, 2009 12:50 pm    Post subject: Reply with quote

ok - so.. i was actually wrong - it doesn't reset the timer each time.. its just that i was posting the wrong variable..

How can I output to the channel how much time is left for that one user? $time is total time (which i've set to 20 mins now)..

Code:

proc throttled2 {id time} {
   global throttled2
   if {[info exists throttled2($id)]} {
     putserv "privmsg #CHANNEL :You have $time left before next fishing attempt!"
      return 1
   } {
      set throttled2($id) [utimer $time [list unset throttled2($id)]]
      return 0
   }
}
Back to top
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Sat Aug 08, 2009 1:32 pm    Post subject: Reply with quote

since throttled($id) contains the timer's name, you can use it to get the remaining time of that timer.
Code:
proc throttled2 {id time} {
   global throttled2
   if {[info exists throttled2($id)]} {
      set left 0
      foreach t [utimers] {
         if {[string equal $throttled2($id) [lindex $t 2]]} {
            set left [lindex $t 0]
            break
         }
      }
      putserv "privmsg #CHANNEL :You have $left left before next fishing attempt!"
      return 1
   } {
      set throttled2($id) [utimer $time [list unset throttled2($id)]]
      return 0
   }
}

_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
MIODude
Voice


Joined: 09 Oct 2006
Posts: 32

PostPosted: Sat Aug 08, 2009 3:22 pm    Post subject: Reply with quote

Thanks! that worked
Back to top
View user's profile Send private message
Dreamxtreme
Voice


Joined: 27 May 2010
Posts: 4

PostPosted: Fri Sep 10, 2010 11:31 am    Post subject: Reply with quote

Can someone tell why the hunt game isnt telling i have 30mins to wait and how many seconds i have left. It just doesnt display a thing yet the fish one works fine

Code:
bind pub - !hunt hunt
bind pub - !fish fish
bind pub - !trophy trophy
bind msg - newmonth newmonth

set hunttargets {
"bear"
"gopher"
"rabbit"
"hunter"
"deer"
"fox"
"duck"
"moose"
"pokemon named Pikachu"
"park ranger"
"Yogi Bear"
"Boo Boo Bear"
"dog named Benji"
"cow"
"raccoon"
"koala bear"
"camper"
"channel lamer"
}

set fish {
"Salmon"
"Herring"
"Yellowfin Tuna"
"Pink Salmon"
"Chub"
"Barbel"
"Perch"
"Nothern Pike"
"Brown Trout"
"Arctic Char"
"Roach"
"Brayling"
"Bleak"
"Cat Fish"
"Sun Fish"
"Old Tire"
"Rusty Tin Can"
"Genie Lamp"
"Love Message In A Bottle"
"Old Log"
"Rubber Boot"
"Dead Body"
"Loch Ness Monster"
"Old Fishing Lure"
"Piece of the Titanic"
"Chunk of Atlantis"
"Squid"
"Whale"
"Dolphin"
"Porpise"
"Stingray"
"Submarine"
"Seal"
"Seahorse"
"Jellyfish"
"Starfish"
"Electric Eel"
"Great White Shark"
"Scuba Diver"
"X"
"Lag Monster"
"Virus"
"Soggy Pack of Smokes"
"Weed"
"Boat Anchor"
"Pair Of Floaties"
"Mermaid"
"Merman"
"Halibut"
"Used Johhny"
"Old Rubber Boot"

}

set huntplaces {
"in some bushes"
"in a hunting blind"
"in a hole"
"up in a tree"
"in a hiding place"
"out in the open"
"in the middle of a field"
"downtown"
"on a street corner"
"at the local mall"
"in some [censored] up bar"

}

set fishplaces {
"Stream"
"Lake"
"River"
"Pond"
"Ocean"
"Bathtub"
"Kiddie's Swimming Pool"
"Toilet"
"Pile of Vomit"
"Pool of Urine"
"Kitchen Sink"
"Bathroom Sink"
"Mud Puddle"
"Pail of Water"
"Bowl of Jell-O (tm)"
"Wash Basin"
"Rain Barrel"
"Aquarium"
"SnowBank"
"WaterFall"
"Cup of Coffee"
"Glass of Milk"

}

proc hunt {nick uhost hand chan args} {
if {![throttled $uhost:#Xtreme 1800]} {
global hunttargets fish fishplaces huntplaces
    set huntplace [lindex $huntplaces [rand [llength $huntplaces]]]
    set critter [lindex $hunttargets [rand [llength $hunttargets]]]
      if ![file exists "hunttrophy"] {
       set f [open "hunttrophy" w]
       puts $f "Nerfbendr 5 Ant"
       close $f
      }
    set f [open "hunttrophy" r]
    gets $f huntrecord
    close $f
    set maxweight [lindex $huntrecord 1]
      set maxweight [expr $maxweight + 100]
    set weightnumber [rand $maxweight]
    putserv "privmsg $chan :$nick hides $huntplace and wait for something to wander by..."
    putserv "privmsg $chan $nick :You think you hear something and fire wildly in that direction..."
    if [rand 2] {
        putserv "privmsg $chan :Congratulations, $nick! You just bagged yourself a $weightnumber pound $critter!"
    } else {
        putserv "privmsg $chan :Bollocks! $nick missed the little sod, Better luck next time!"
        return 1
    }
set f [open "hunttrophy" r]
gets $f huntrecord
close $f
if { $weightnumber > [lindex $huntrecord 1] } {
    putserv "privmsg $chan :Wow!!! That's a new record! Way to go, $nick! Type !trophy to see it!"
    putserv "privmsg $chan :$nick just bagged a $weightnumber pound $critter and set a new record!"
    set f [open "hunttrophy" w]
    puts $f "$nick $weightnumber $critter"
    close $f
    return 1
} else {
    putserv "privmsg $chan :Sorry $nick...that's not a new record! Good try, though!"
    return 1
}
}
       
       putserv "privmsg #xtreme :Sorry $nick - You need to wait 30 minutes between attempts!"
}


proc fish {nick uhost hand chan args} {
if {![throttled2 $uhost:#xtreme 1200]} {
global hunttargets fish fishplaces huntplaces
    set fishplace [lindex $fishplaces [rand [llength $fishplaces]]]
    set fishtocatch [lindex $fish [rand [llength $fish]]]
      if ![file exists "fishtrophy"] {
       set f [open "fishtrophy" w]
       puts $f "Nerfbendr 5 Guppie"
       close $f
      }
    set f [open "fishtrophy" r]
    gets $f fishrecord
    close $f
    set maxweight [lindex $fishrecord 1]
    set maxweight [expr $maxweight + 100]
    set weightnumber [rand $maxweight]
    putserv "privmsg $chan  :$nick you cast your line into a $fishplace and wait for a bite..."
    putserv "privmsg $chan  :$nick feels a tug on the line and reels this bad boy in..."
    if [rand 2] {
        putserv "privmsg $chan :Congratulations, $nick! just caught yourself a $weightnumber pound $fishtocatch!"
    } else {
        putserv "privmsg $chan :Bollocks!...the slippery little bugger got away, Better luck next time! $nick"
        return 1
    }
set f [open "fishtrophy" r]
gets $f fishrecord
close $f
if { $weightnumber > [lindex $fishrecord 1] } {
    putserv "privmsg $chan :Wow!!! That's a new record! Way to go, $nick! Type !trophy to see it!"
    putserv "privmsg $chan :$nick just caught a $weightnumber pound $fishtocatch and set a new record!"
    set f [open "fishtrophy" w]
    puts $f "$nick $weightnumber $fishtocatch"
    close $f
    return 1
} else {
    putserv "privmsg $chan :Sorry $nick...that's not a new record! Good try, though!"
    return 1
}
}

    putserv "privmsg #xtreme :Sorry $nick - You need to wait 20 minutes between attempts!"
}

proc newmonth {nick uhost hand chan args} {
global hunttargets fish fishplaces huntplaces
set f [open "fishtrophy" w]
puts $f "Nerfbendr 5 Guppie"
close $f
set f [open "hunttrophy" w]
puts $f "Nerfbendr 5 Ant"
close $f
putserv "privmsg $chan :Online hunting and fishing scores have been reset! Type !cast or !hunt to play!"
return 1
}

proc trophy {nick uhost hand chan args} {
global hunttargets fish fishplaces huntplaces

if ![file exists "fishtrophy"] {
set f [open "fishtrophy" w]
puts $f "Nerfbendr 5 Guppie"
close $f
}
if ![file exists "hunttrophy"] {
set f [open "hunttrophy" w]
puts $f "Nerfbendr 5 Ant"
close $f
}
set f [open "fishtrophy" r]
gets $f fishrecord
close $f
set f [open "hunttrophy" r]
gets $f huntrecord
close $f
putserv "privmsg $chan :[lindex $fishrecord 0] holds the fishing record when they caught a [lindex $fishrecord 1] pound [lrange $fishrecord 2 end]!"
putserv "privmsg $chan :[lindex $huntrecord 0] holds the hunting record when they bagged a [lindex $huntrecord 1] pound [lrange $huntrecord 2 end]!"
return 1
}

proc throttled {id time} {
   global throttled
   if {[info exists throttled($id)]} {
      set left 0
      foreach t [utimers] {
         if {[string equal $throttled2($id) [lindex $t 2]]} {
            set left [lindex $t 0]
            break
         }
      }
      putserv "privmsg #xtreme :You have $left left before next hunting attempt!"
      return 1
   } {
      set throttled($id) [utimer $time [list unset throttled2($id)]]
      return 0
   }
}

proc throttled2 {id time} {
   global throttled2
   if {[info exists throttled2($id)]} {
      set left 0
      foreach t [utimers] {
         if {[string equal $throttled2($id) [lindex $t 2]]} {
            set left [lindex $t 0]
            break
         }
      }
      putserv "privmsg #xtreme :You have $left left before next fishing attempt!"
      return 1
   } {
      set throttled2($id) [utimer $time [list unset throttled2($id)]]
      return 0
   }
}
Back to top
View user's profile Send private message
MIODude
Voice


Joined: 09 Oct 2006
Posts: 32

PostPosted: Fri Sep 10, 2010 12:33 pm    Post subject: Reply with quote

Not sure if this is the reason, but you have mixed up your throttled and throttled2 variables.. in proc throttled they should all just be throttled, not throttled2

Code:

proc throttled {id time} {
   global throttled
   if {[info exists throttled($id)]} {
      set left 0
      foreach t [utimers] {
         if {[string equal $throttled2($id) [lindex $t 2]]} {
            set left [lindex $t 0]
            break
         }
      }
      putserv "privmsg #xtreme :You have $left left before next hunting attempt!"
      return 1
   } {
      set throttled($id) [utimer $time [list unset throttled2($id)]]
      return 0
   }
}
Back to top
View user's profile Send private message
Dreamxtreme
Voice


Joined: 27 May 2010
Posts: 4

PostPosted: Fri Sep 10, 2010 1:19 pm    Post subject: Reply with quote

Ah yes okie dokie then im a idiot

Laughing
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
Page 1 of 1

 
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