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 

Help to modify game stone-paper-scissors

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


Joined: 15 Mar 2015
Posts: 317

PostPosted: Mon Jun 06, 2016 3:49 am    Post subject: Help to modify game stone-paper-scissors Reply with quote

I found this game of stone-paper-scissors and want to improve it ...
How I can do to saved the scores for each user who plays on each channel and, at the same time if one of the users win 5 times end the game?

Code:
####################################################
# Author : TALES 24-08-2003                        #
# File name: ssp.tcl                               #
# version script : v1                              #
# Script info : This is a little game for channel  #
#               hope you like the game.            #
#               cmd like: !choose scissor          #
#                         !choose stone            #
#                         !choose paper            #
####################################################
#         if you got any questions you             #
#         can find me @ irc.chatcity.nl            #
#         http://www.cb3rob.net/~tales/            #
####################################################
#     this script is made for eggdrop 1.6.13       #
#      but should work on al 1.6.* versions        #
#    use of this script is for your own risk!      #
####################################################
# Credits : Fr33man_, Ace^                         #
####################################################

bind pub - !choose msg_ssp

set ssp_list {
 "scissor"
 "stone"
 "paper"
}

proc msg_ssp {nick uhost hand chan rest} {
  global botnick ssp_list
  set ssp [lindex $ssp_list [rand [llength $ssp_list]]]
  set cmd [string tolower [lindex $rest 0]]
  if { ($cmd == $ssp) } {
     putserv "PRIVMSG $chan :You have \0037$cmd\003 and i have \0037$ssp\003 game \00312-draw-\003"
     return 0
     }
  if {$cmd == "stone"} {
    if {$ssp == "paper"} {
       putserv "PRIVMSG $chan :You have \0037Stone\003 and i have \0037Paper\003 you \0034-lose-\003"
       return 0
       }
    if {$ssp == "scissor"} {
       putserv "PRIVMSG $chan :You have \0037Stone\003 and i have \0037Scissor\003 you \0033-won-\003"
       return 0
       }
      }
  if {$cmd == "paper"} {
    if {$ssp == "stone"} {
       putserv "PRIVMSG $chan :You have \0037Paper\003 and i have \0037Stone\003 you \0033-won-\003"
       return 0
       }
    if {$ssp == "scissor"} {
       putserv "PRIVMSG $chan :You have \0037Paper\003 and i have \0037Scissor\003 you \0034-lose-\003"
       return 0
       }
      }
  if {$cmd == "scissor"} {
    if {$ssp == "stone"} {
       putserv "PRIVMSG $chan :You have \0037Scissor\003 and i have \0037Stone\003 you \0034-lose-\003"
       return 0
       }
    if {$ssp == "paper"} {
       putserv "PRIVMSG $chan :You have \0037Scissor\003 and i have \0037Paper\003 you have \0033-won-\003"
       return 0
       }
      }
}

putlog "ssp.tcl v1 made by TALES loaded succesfully."

_________________
If you do not understand my ideas is because I can not think in English, I help me with Google Translate. I only speak Spanish. Bear with me. Thanks Smile
Back to top
View user's profile Send private message
caesar
Ass Kicker


Joined: 14 Oct 2001
Posts: 3403
Location: Area 51

PostPosted: Tue Jun 07, 2016 9:13 am    Post subject: Reply with quote

Code:

namespace eval ssp {

   variable maxScore 5
   variable ssp [list "scissor" "stone" "paper"]

   bind pub - !choose [namespace current]::choose
   bind pub o|o !reset [namespace current]::reset

   proc choose {nick uhost hand chan text} {
      variable ssp
      variable diceScore
      set random [lindex $ssp [rand [llength $ssp]]]
      if {[scan $text {%s} pick] != 1} {
         putserv "PRIVMSG $chan :To play the game choose one from \"[join $random]\" and make your choose like: !choose $random"
         return
      }
      set pick [string tolower $pick]
      set won 0
      if {[string equal $random $pick]} {
         putserv "PRIVMSG $chan :You have \0037$pick\003 and i have \0037$random\003 game \00312-draw-\003"
      } else {
         switch -- $pick {
            "stone" {
               if {[string equal $random "paper"]} {
                  putserv "PRIVMSG $chan :You have \0037Stone\003 and i have \0037Paper\003 you \0034-lose-\003"
               } elseif {$random eq "scissor"} {
                  putserv "PRIVMSG $chan :You have \0037Stone\003 and i have \0037Scissor\003 you \0033-won-\003"
                  incr won
               }
            }
            "paper" {
               if {[string equal $random "scissor"]} {
                  putserv "PRIVMSG $chan :You have \0037Paper\003 and i have \0037Scissor\003 you \0034-lose-\003"
               } elseif {$random eq "stone"} {
                  putserv "PRIVMSG $chan :You have \0037Paper\003 and i have \0037Stone\003 you \0033-won-\003"
                  incr won
               }
            }
            "scissor" {
               if {[string equal $random "stone"]} {
                  putserv "PRIVMSG $chan :You have \0037Scissor\003 and i have \0037Stone\003 you \0034-lose-\003"
               } elseif {$random eq "paper"} {
                  putserv "PRIVMSG $chan :You have \0037Scissor\003 and i have \0037Paper\003 you have \0033-won-\003"
                  incr won
               }
            }
            default {
               putserv "PRIVMSG $chan :Sorry, your pick is not valid. You must choose one from: [join $ssp]"
            }
         }
      }
      if {$won} {
         set pos [getPos $chan $nick]
         set score [expr $pos != -1 ? [getScore $chan $nick] : 0]
         set newScore [incr score]
         if {$pos != -1} {
            set diceScore($chan) [lreplace $diceScore($chan) $pos $pos [list $nick $newScore]]
         } else {
            lappend diceScore($chan) [list $nick 1]
         }
      }
      if {[checkScore $chan]} {
         array unset diceScore $chan
         putserv "PRIVMSG $chan :Congrats to $nick! He won this round!"
      }
      
   }
   
   proc reset {nick uhost hand chan text} {
      variable diceScore
      array unset diceScore $chan
   }
   
   proc checkScore {chan} {
      variable diceScore
      variable maxScore
      set x 0
      if {[info exists diceScore($chan)]} {
         foreach {player score} [join $diceScore($chan)] {
            if {$score < $maxScore} continue
            incr x
            break
         }
      }
      return $x
   }
   
   proc getPos {chan nick} {
      set pos -1
      set match 0
      variable diceScore
      if {[info exists diceScore($chan)]} {
         foreach {player score} [join $diceScore($chan)] {
            incr pos
            if {![string equal -nocase $player $nick]} continue
            incr match
            break
         }
      }
      return [expr $match ? "$pos" : "-1"]
   }
   
   proc getScore {chan nick} {
      set x 0
      variable diceScore
      if {[info exists diceScore($chan)]} {
         foreach {player score} [join $diceScore($chan)] {
            if {![string equal -nocase $player $nick]} continue
            incr x $score
            break
         }
      }
      return $x
   }
}

Quote:

<cez> !choose bla
<@bot> Sorry, your pick is not valid. You must choose one from: scissor stone paper
<cez> !choose stone
<@bot> You have Stone and i have Scissor you -won-
<cez> !choose stone
<@bot> You have stone and i have stone game -draw-
<cez> !choose stone
<@bot> You have Stone and i have Scissor you -won-
<cez> !choose stone
<@bot> You have Stone and i have Scissor you -won-
<cez> !choose stone
<@bot> You have Stone and i have Paper you -lose-
<cez> !choose stone
<@bot> You have Stone and i have Scissor you -won-
<cez> !choose stone
<@bot> You have Stone and i have Paper you -lose-
<cez> !choose stone
<@bot> You have Stone and i have Scissor you -won-
<@bot> Congrats to cez! He won this round!

This should be extended to monitor nick change, kick, part and quit and also do some resets every 30 minutes, 1 hour or whatever. I added a !reset in case something goes wrong, but you can remove it.
_________________
You may say anything about me, but don't misspell my name.
Back to top
View user's profile Send private message
juanamores
Master


Joined: 15 Mar 2015
Posts: 317

PostPosted: Tue Jun 07, 2016 4:09 pm    Post subject: Reply with quote

Work perfectly!!! Smile
Thank you caesar !

Then I 'll see if I can add something in order to that a nick can not play until his turn comes .
Sometimes , they play more than once out of turn.
Example:
If nicks A, B , C , D and E playing..
After playing A, you should expect to play B and then C ... and so on...
_________________
If you do not understand my ideas is because I can not think in English, I help me with Google Translate. I only speak Spanish. Bear with me. Thanks Smile
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