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.

Define script

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
F
Football
Master
Posts: 205
Joined: Fri Dec 26, 2008 3:08 pm
Location: Quakenet, #Football

Define script

Post by Football »

A script request.

a Script that will have a define trigger (!Team), so that when you type !team <nick> team it will define that nick's team.
example:

<Xabriel> !Team Xabriel Tottenham
[11:29:03] -EPL- Xabriel's favourite team is now 'Tottenham'

and then when you type !Sum on the channel it will announce how many users are defined, and out of the defined users how many supports which teams (in percent)

Example:
<Xabriel> !Sum
<EPL> There are 18 defined users. 9 Support Tottenham (50%), 9 Support Arsenal (50%)
Idling at #Football, Quakenet.
User avatar
TCL_no_TK
Owner
Posts: 509
Joined: Fri Aug 25, 2006 7:05 pm
Location: England, Yorkshire

SCRIPT

Post by TCL_no_TK »

Here's the example of the some of the output

Code: Select all

[23:15:13] <@Me> !sum
[23:15:15] <+bot> ======= TEAMS =======
[23:15:17] <+bot> [1] England   (2 Supporters)
[23:15:19] <+bot> [2] Brazil   (1 Supporters)
[23:15:21] <+bot> [3] Leafs   (1 Supporters)
[23:15:23] <+bot> [4] Manchester United   (1 Supporters)
[23:15:25] <+bot>  
[23:15:27] <+bot>  Total Players: 5
[23:15:29] <+bot> =====================
It was alot of fun testing it so i hope ur channel will enjoy it alot :D

rewrote almost the whole thing again! and got alot of code and points from the tcl wiki' so look out for the credits in the script :) hope it works great for you! but if not just let make an other post n i'll see what i can do :wink:

Code: Select all

 proc matchxtra {xtra} {
  set matches ""
  foreach i [userlist] {
   append matches " [getuser $i XTRA $xtra]"
  }
   return $matches
 }

 proc footyplayers {} {
  return [llength [matchxtra "TEAM"]]
 }

 proc footyteams {channel {output ""} {queue ""}} {
  if {$output == ""} {
   set output "PRIVMSG"
  }
  if {$queue == ""} {
   set queue "puthelp"
  }

  set contents [matchxtra "TEAM"]

  #-- Credit http://wiki.tcl.tk/20508

  #
  # Count the words
  #
  foreach word $contents {
   if { [info exists count($word)] } {
    incr count($word)
   } else {
    set count($word) 1
   }
  }

  #
  # Convert the data into a form easily sorted
  #
  set frequencies {}
  foreach word [array names count] {
	 lappend frequencies [list $word $count($word)]
  }
  set sorted [lsort -index 1 -integer -decreasing \
	   [lsort -index 0 $frequencies]]

  $queue "$output $channel :======= TEAMS ======="
  set nO 0
  foreach frequency $sorted {
   set nO [expr {$nO+1}]
   $queue "$output $channel :\[$nO\] [regsub -all "_" [lrange $frequency 0 end-1] " "]   ([lrange $frequency end end] Supporters)"
  }
  $queue "$output $channel : "
  $queue "$output $channel : Total Players: [footyplayers]"
  $queue "$output $channel :====================="
  return
 }

 #since the script adds users to eggdrop's userfile, its very important to
 #make sure this setting isn't used to give them any flags!
 set default-flags "-"
 #please dont remove the above line

 proc addplayer {nick {channel ""} hostmask team} {
  if {[validuser $nick] || [validuser [nick2hand $nick]]} {
   return 3
  }
  if {($channel == "") && (![onchan $nick])} {
   return 4
  }
  if {[adduser "$nick" "[maskhost $hostmask]"]} {
   putlog "football_teams.tcl: Added new user $nick \[$hostmask\] with TEAM: $team to userfile"
   setuser $nick XTRA TEAM "$team"
   setuser $nick COMMENT "added by football_teams.tcl"
   return 1
  } else {
   return 2
  }
 }

 proc getteam {handle} {
  if {[validuser $handle]} {
   return [getuser $handle XTRA TEAM]
  }
  return
 }

 proc clearteam {handle} {
  if {[validuser $handle]} {
   setuser $handle XTRA TEAM ""
   return 1
  }
   return 0
 }

 proc setteam {handle team} {
  if {[validuser $handle]} {
   setuser $handle XTRA TEAM "$team"
   return 1
  } elseif {[validuser [nick2hand $handle]]} {
   setuser [nick2hand $handle] XTRA TEAM "$team"
   return 2
  } else {
   return 3
  }
 }

 bind pub -|- !team pub:team
 bind pub -|- !sum pub:sum
 
 proc pub:team {nick host hand chan text} {
  if {[llength $text] == 0} {
   set team [getteam $hand]
   if {$team != ""} {
    puthelp "PRIVMSG $chan :$nick's favourite team is \002$team\002!!!"
   }
   return
  }
  set string [lindex [split $text] 0]

  if {[validuser "$string"]} {
   # first string is a <handle>
   set team [join [lrange [split $text] 1 end]]

   #check we've been given a team
   if {$team == ""} {return}

   regsub -all " " $team "_" teamname

   switch [setteam "$string" "$teamname"] {
    "3" {
         #again, shouldn't happen
         return
        }
    "2" {
         #just means they were added, but nick2hand was used
         puthelp "NOTICE $nick :$string's faviourite team is '$team'"
         return 1
        }
    "1" {
         #all good baby!
         puthelp "NOTICE $nick :$string's faviourite team is '$team'"
         return 1
        }
   }
   
  } elseif {[validuser [nick2hand "$string"]]} {
   # first string is a <handle>

   set team [join [lrange [split $text] 1 end]]

   #check we've been given a team
   if {$team == ""} {return}

   regsub -all " " $team "_" teamname

   # we dont need an other 'nick2hand' here since the 'setteam' already dose it
   switch [setteam "$string" "$teamname"] {
    "3" {
         #again, shouldn't happen
         return
        }
    "2" {
         #just means they were added, but nick2hand was used
         puthelp "NOTICE $nick :$string's faviourite team is '$team'"
         return 1
        }
    "1" {
         #all good baby!
         puthelp "NOTICE $nick :$string's faviourite team is '$team'"
         return 1
        }
   }

  } elseif {[onchan "$string" "$chan"]} {
   # first string is a <nickname>

    #set the team
    set team [join [lrange [split $text] 1 end]]
    #check a team was given
    if {$team == ""} {return}
    #we remove spaces here, and replace them with '_'
    #since spaces in team names will cause trouble with the output
    regsub -all " " $team "_" teamname
    set addy "$string![getchanhost $string $chan]"

    switch [addplayer "$string" "$chan" "$addy" "$teamname"] {
     "3" {
          setteam "$string" "$teamname"
          puthelp "NOTICE $nick :$string's favourite team is '$team'"
          return 1
         }
     "4" {
          #i very much doubt this will even be returned by this proc but just incase
          #its here
          return
         }
     "1" {
          puthelp "NOTICE $nick :$string's favourite team is '$team'"
           return 1
         }
     "2" {
          puthelp "NOTICE $nick :Sorry, i was unable to add '$string' with team '$team' Please try again late."
           return 0
         }
    }

  } else {
   # first string is a <team>
   # validate user
   if {[validuser "$hand"]} {

    set team [join [lrange [split $text] 0 end]]
    regsub -all " " $team "_" teamname

    switch [setteam "$nick" "$teamname"] {
     "3" {
          #again, shouldn't happen
          return
         }
     "2" {
          #just means they were added, but nick2hand was used
          puthelp "NOTICE $nick :Youre faviourite team is '$team'"
          return 1
         }
     "1" {
          #all good baby!
          puthelp "NOTICE $nick :You're faviourite team is '$team'"
          return 1
         }
    }

   } else {
    #set the team
    set team [join [lrange [split $text] 0 end]]
    #we remove spaces here, and replace them with '_'
    #since spaces in team names will cause trouble with the output
    regsub -all " " $team "_" teamname
    set addy "$nick!$host"

    switch [addplayer "$nick" "$chan" "$addy" "$teamname"] {
     "3" {
          #dont panic, this just means they are already a user *sigh*
          #so its safe to assume that we can just use 'setteam' rite?
          # -- should of been caught by [validuser $hand] thou? >_<
          setteam "$nick" "$teamname"
          puthelp "NOTICE $nick :You're favourite team is '$team'"
          return 1
         }
     "4" {
          #i very much doubt this will even be returned by this proc but just incase
          #its here
          return
         }
     "1" {
          puthelp "NOTICE $nick :You're favourite team is '$team'"
           return 1
         }
     "2" {
          puthelp "NOTICE $nick :Sorry, i was unable to add u with team '$team' Please try again late."
           return 0
         }
    }
    #think thats it for dis bit :>

   }
  }
 }

 proc pub:sum {nick host hand chan text} {

  if {[footyplayers] == 0} {

   puthelp "NOTICE $nick :noone has set there faviourite team yet!"
   return 0

  }

  footyteams "$chan" "" ""
  return 1

 }

 putlog "loaded football_teams.tcl by TCL_no_TK"
 return
Last edited by TCL_no_TK on Sun Aug 02, 2009 6:20 pm, edited 1 time in total.
F
Football
Master
Posts: 205
Joined: Fri Dec 26, 2008 3:08 pm
Location: Quakenet, #Football

Post by Football »

Thanks for helping out.

I have two errors though.

the !team <nick> team-here works
but the eggy writes me the error
[13:30:42] <EPL> [12:30] Tcl error [ft:team:pub]: invalid command name "mashost"

even though when I type !Team, it shows me the team I've set.

Second error, after I added the 'Sum' part:

[13:32:05] <EPL> [12:31] Tcl error [ft:sum:pub]: can't read "footyteams": variable is array
Idling at #Football, Quakenet.
User avatar
TCL_no_TK
Owner
Posts: 509
Joined: Fri Aug 25, 2006 7:05 pm
Location: England, Yorkshire

Post by TCL_no_TK »

Code: Select all

  if {[onchan "$nick"]} { 
   if {[adduser "$nick" "[mashost [getchanhost $nick]]"]} {
Error was a spelling mistake, change the above line to

Code: Select all

  if {[onchan "$nick"]} { 
   if {[adduser "$nick" "[maskhost [getchanhost $nick]]"]} {
:)
Second part, lost track of what i was doing! change

Code: Select all

 set footyteams(teams) [lsort -unique [lsort -command compare "$tmp"]] 
 foreach teams $footyteams { 
  set footyteam($teams) 
 }
to this

Code: Select all

 set footyteams(teams) [lsort -unique [lsort -command compare "$tmp"]] 
 foreach teams $footyteams(teams) { 
  set footyteam($teams) 
 }
:D

One thingy i didn't mention, the following settings

Code: Select all

#change these if required 
set footyteams(needop) "1"
Setting this to 1 will only allow Channel Operators to change someone else's fave team, setting this to -1 will only allow people who are voiced on the channel to change someone else's fave team. :!:
F
Football
Master
Posts: 205
Joined: Fri Dec 26, 2008 3:08 pm
Location: Quakenet, #Football

Post by Football »

Thanks a lot, it works good now

only problem I guess is with the sum

Tcl error [ft:sum:pub]: can't read "footyteam(BarcelonaDinamo)": no such variable
Idling at #Football, Quakenet.
User avatar
TCL_no_TK
Owner
Posts: 509
Joined: Fri Aug 25, 2006 7:05 pm
Location: England, Yorkshire

Post by TCL_no_TK »

Code: Select all

 foreach team $tmp { 
  set footyteam($team) [expr {$footyteam($team) +1}] 
 }
changing this to

Code: Select all

 foreach team $tmp { 
  if {[info exists footyteam($team)]} {
   set footyteam($team) [expr {$footyteam($team) +1}] 
  }
 }
should fix that with a bit of luck :)
F
Football
Master
Posts: 205
Joined: Fri Dec 26, 2008 3:08 pm
Location: Quakenet, #Football

Post by Football »

Same error :(
Idling at #Football, Quakenet.
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

The error lies within these three lines:

Code: Select all

 foreach teams $footyteams {
  set footyteam($teams)
 }
Using set with no value argument is equivalent as reading the variable (set will return the current value of the variable, or throw an error if the variable is not set).
NML_375
F
Football
Master
Posts: 205
Joined: Fri Dec 26, 2008 3:08 pm
Location: Quakenet, #Football

Post by Football »

any solution for how it should look like, nml375?
Idling at #Football, Quakenet.
User avatar
TCL_no_TK
Owner
Posts: 509
Joined: Fri Aug 25, 2006 7:05 pm
Location: England, Yorkshire

Post by TCL_no_TK »

Code: Select all

 foreach teams $footyteams { 
  set footyteam($teams) 0
 }
:P
F
Football
Master
Posts: 205
Joined: Fri Dec 26, 2008 3:08 pm
Location: Quakenet, #Football

Post by Football »

still doesn't work :/
Idling at #Football, Quakenet.
User avatar
TCL_no_TK
Owner
Posts: 509
Joined: Fri Aug 25, 2006 7:05 pm
Location: England, Yorkshire

Post by TCL_no_TK »

Am currently doing more testing on it, for now i'll reply/edit and post anything i find here soon :)

EDIT: :!: Fixed see this post for the script! :D
Post Reply