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.

set commands

Old posts that have not been replied to for several years.
Locked
S
Storm
Voice
Posts: 36
Joined: Fri Apr 25, 2003 12:59 am
Location: Vancouver, Canada

set commands

Post by Storm »

Hey! :)
Allright, I finally decided to make this topic. I was thinking to post this topic or not. For users who use GamesNet Server will be easy to understand me, but I hope everyone will understand :) :) :).
There is a list of commands in @commands: players, server, rules, help...
I know this is possible to make this script, but I have no idea how. The script allows u to set each command for each channel through IRC, not by editing TCL script in text editor. So it will be like in #chan1: !set players Players Names and in #chan1 by using @players the bot will display !set players Players Names and in other channels commands can be different. I hope everyone understood my point. Just give me 1 example of how to do this please :D .Thanks :) :D
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Code: Select all

bind pub o "!set" pub:set

proc pub:set {nick host handle chan arg} {
global players
  switch -- [lindex $arg 0] {
    "players" {
      array set players "[strlwr $chan] [list [lrange $arg 1 end]]"
      putserv "PRIVMSG $chan :added [llength [lrange $arg 1 end]] players: [lrange $arg 1 end]"
    }
  }
}

bind pub o "@players" pub:get:players

proc pub:get:players {nick host handle chan arg} {
  global players
  foreach channel [array names players] {
    if {![string match [strlwr $chan] [strlwr $chan]]} {
      array set players "[strlwr $chan] 0"
    }
  }
  putserv "PRIVMSG $chan :$players([strlwr $chan])"
}
Once the game is over, the king and the pawn go back in the same box.
S
Storm
Voice
Posts: 36
Joined: Fri Apr 25, 2003 12:59 am
Location: Vancouver, Canada

Post by Storm »

hey. Thanks, it works, but it does not save, so when I do rehash / restart, it removes. Can u pls edit it so it will auto save :D
S
Storm
Voice
Posts: 36
Joined: Fri Apr 25, 2003 12:59 am
Location: Vancouver, Canada

Post by Storm »

anyone knows how to do it?
S
Storm
Voice
Posts: 36
Joined: Fri Apr 25, 2003 12:59 am
Location: Vancouver, Canada

Post by Storm »

Caesar could u plz help me?
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

This sems to be your lucky day! :)

Code: Select all

set playersfile "players.txt"

bind pub o "!set" pub:set
bind pub o "@players" get:players 

if {![file exists $playersfile]} {close [open $playersfile w]} 
set file [open $playersfile r] 
while {![eof $file]} {
  gets $file line 
  if {[string trim $line] == ""} { continue } 
  foreach chan [channels] {
    if {![string match -nocase [strlwr $chan] [lindex $line 0]]} { continue }
    array set players "[strlwr $chan] [lrange $line 1 end]"
    putlog "[strlwr $chan] [lrange $line 1 end]"
  } 
}
close $file

proc pub:set {nick host handle chan arg} {
  global players
  switch -- [lindex $arg 0] {
    "players" {
      array set players "[strlwr $chan] [list [lrange $arg 1 end]]"
      set file [open "$::playersfile" w]
      foreach ch [channels] {
        puts $file "$ch $players([strlwr $ch])"
      }
      catch {close $file}
      putserv "PRIVMSG $chan :Added [llength [lrange $arg 1 end]] players: [lrange $arg 1 end]."
    }
  }
}

proc get:players {nick host handle channel arg} { 
  global players 
  if {![info exists players([strlwr $channel])]} { 
    array set players "[strlwr $channel] 0" 
  } 
  putserv "PRIVMSG $channel :Players: $players([strlwr $channel])"
}
Let me know if something is not working propertly..
Once the game is over, the king and the pawn go back in the same box.
S
Storm
Voice
Posts: 36
Joined: Fri Apr 25, 2003 12:59 am
Location: Vancouver, Canada

Post by Storm »

it does not work properly. first part: setting works !set players players. When I do restart and then !players the bot responds Players: 0
:D
User avatar
ReaLz
Op
Posts: 121
Joined: Sat Oct 19, 2002 5:33 am
Location: Athens, Greece

Post by ReaLz »

I'm not sure but I think that this happens because the .restart command makes the bot <<forget>> the arrays, to solve this problem you can use other ways to make it remember the players.
Like adding a flag to the users that play and when you execute the !players command will check all the users in its userlist and will return the ones with the given flag.
«A fantastic spaghetti is a spaghetti that does not exist»
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Actualy ReaLz you should read the manual about the arrays first then say something about them. The array are erased upon a .die not a .restart or even a .rehash. Anywway, I'll have a look on it, I have a hint where that buggy may be. :)
Once the game is over, the king and the pawn go back in the same box.
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

First remove this line

Code: Select all

putlog "[strlwr $chan] [lrange $line 1 end]"
and add this line

Code: Select all

if {[info exists players([strlwr $chan])]} { continue }
before the
if {![string match -nocase [strlwr $chan] [lindex $line 0]]} { continue }
and should do fine..

PS: ReaLz: after I've restarted it:
(10:06:27) ::: <caesar> .tcl array get players
(10:06:27) ::: <looser> Tcl: #bla moo
Once the game is over, the king and the pawn go back in the same box.
Locked