Server Help Forum Index Server Help
Community forums for Subgame, ASSS, and bots
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   StatisticsStatistics   RegisterRegister 
 ProfileProfile   Login to check your private messagesLogin to check your private messages   LoginLogin (SSL) 

Server Help | ASSS Wiki (0) | Shanky.com
guessing game.py

 
Post new topic   Reply to topic Printable version
 View previous topic  <c> Poll Post :: Post [idea] upgrade ship  View next topic  
Author Message
Chambahs
Guest


Offline

PostPosted: Sat Apr 02, 2005 3:48 pm    Post subject: guessing game.py Reply to topic Reply with quote

tried again and failed (cries) was supposed to be a present but meh...


Code: Show/Hide

#Guessing Game By Chambahs
#3-2-05

from asss import *

chat = get_interface(I_CHAT)
stats = get_interface(I_CHAT)
prng = get_interface(I_PRNG)


def count_players(arena):
    players = [ 0 ]
    def cb_count(p):
        if p.arena == arena:
       players[0] += 1
    for_each_player(cb_count)
    return players[0]

def c_start(cmd, params, p, targ):
    if int(params)> 0:
        p.arena.guess_reward = int(params)
    else:
        p.arena.guess_reward = 1000
    if players > 0:
   chat.SendArenaMessage(p.arena, "The Number Game has Started!! Pick a Number between 0 and 100")
   chat.SendArenaMessage(p.arena, "Whoever gets the number first wins " + p.arena.guess_reward + " points!")
   chat.SendArenaMessage(p.arena, "GO GO GO GO!!!!")
   p.arena.guess_number = prng.Number(1, 100)
    elif players < 0:
   chat.SendArenaMessage(arena, "There arent enough people to play this game")
    arena.guess_gameover = 0

def guess(p, mtype, sound, to, freq, text):
    if p.arena.guess_gameover == 1:
        #pass
    if mtype == MSG_PUB:
   value = 0
   try:
       value = int(text)
   except:
       pass

   if value > 0 and value < 100:
       if value > p.arena.guess_number:
      chat.SendMessage(p, "Too High")
       elif value < p.arena.guess_number:
      chat.SendMessage(p, "Too Low")
       elif value == p.arena.guess_number:
      chat.SendMessage(p, "YOU WIN!")
      chat.SendArenaMessage(p.arena, p.name + " has won the guessing game with the number of " + p.arena.guess_number + " !!!")
                chat.SendArenaMessage(p.arena, p.name + " has been rewarded with " + p.arena.guess_reward + " points")               
                stats.IncrementStat(p, STAT_FLAG_POINTS, p.arena.guess_reward)
                arena.guess_gameover = 1
               
cmd1 = add_command("gstart", c_start)
cb1 = reg_callback(CB_CHATMSG, guess)


also, i previewed it....why do the indents look all messed?
Back to top
Chambahs
Guest


Offline

PostPosted: Sat Apr 02, 2005 3:53 pm    Post subject: Reply to topic Reply with quote

sorry for the double post, just noticed that i made a typo while posting the code, line 35's #pass should be uncommented
Back to top
Mr Ekted
Movie Geek


Gender:Gender:Male
Joined: Feb 09 2004
Posts: 1379
Offline

PostPosted: Sat Apr 02, 2005 4:24 pm    Post subject: Reply to topic Reply with quote

stats = get_interface(I_CHAT) ??
_________________
4,691 irradiated haggis!
Back to top
View users profile Send private message Add User to Ignore List
Chambahs
Guest


Offline

PostPosted: Sat Apr 02, 2005 5:10 pm    Post subject: Reply to topic Reply with quote

LOL i did not see that at all, fixed it...still doesnt work
Back to top
Solo Ace
Yeah, I'm in touch with reality...we correspond from time to time.


Age:36
Gender:Gender:Male
Joined: Feb 06 2004
Posts: 2583
Location: The Netherlands
Offline

PostPosted: Sat Apr 02, 2005 5:14 pm    Post subject: Reply to topic Reply with quote

Well, yeah, what Ek said.

Also, I guess this fixed the tabs for you:

Code: Show/Hide
#Guessing Game By Chambahs
#3-2-05

from asss import *

chat = get_interface(I_CHAT)
stats = get_interface(I_CHAT) # ahem
prng = get_interface(I_PRNG)

def count_players(arena):
   players = [ 0 ]


def cb_count(p):
   if p.arena == arena:
      players[0] += 1
   for_each_player(cb_count)
   return players[0]


def c_start(cmd, params, p, targ):
   if int(params)> 0:
      p.arena.guess_reward = int(params)
   else:
      p.arena.guess_reward = 1000
   if players > 0:
      chat.SendArenaMessage(p.arena, "The Number Game has Started!! Pick a Number between 0 and 100")
      chat.SendArenaMessage(p.arena, "Whoever gets the number first wins " + p.arena.guess_reward + " points!")
      chat.SendArenaMessage(p.arena, "GO GO GO GO!!!!")
      p.arena.guess_number = prng.Number(1, 100)
   elif players < 0:
      chat.SendArenaMessage(arena, "There arent enough people to play this game")
      arena.guess_gameover = 0


def guess(p, mtype, sound, to, freq, text):
   if p.arena.guess_gameover == 1:
      pass
   if mtype == MSG_PUB:
      value = 0
      try:
         value = int(text)
      except:
         pass
   if value > 0 and value < 100:
      if value > p.arena.guess_number:
         chat.SendMessage(p, "Too High")
      elif value < p.arena.guess_number:
         chat.SendMessage(p, "Too Low")
      elif value == p.arena.guess_number:
         chat.SendMessage(p, "YOU WIN!")
         chat.SendArenaMessage(p.arena, p.name + " has won the guessing game with the number of " + p.arena.guess_number + " !!!")
         chat.SendArenaMessage(p.arena, p.name + " has been rewarded with " + p.arena.guess_reward + " points")               
         stats.IncrementStat(p, STAT_FLAG_POINTS, p.arena.guess_reward)
         arena.guess_gameover = 1
      #else:
      #   chat.SendMessage(p, "Please pick a number between 0 and 100")
      # maybe add this? I don't know if prng.Number(1, 100) excludes this already though

cmd1 = add_command("gstart", c_start)
cb1 = reg_callback(CB_CHATMSG, guess)
Back to top
View users profile Send private message Add User to Ignore List
Smong
Server Help Squatter


Joined: 1043048991
Posts: 0x91E
Offline

PostPosted: Sat Apr 02, 2005 5:42 pm    Post subject: Reply to topic Reply with quote

Code: Show/Hide
if mtype == MSG_PUB:
I thought I told you that should be elif?
Back to top
View users profile Send private message Add User to Ignore List Visit posters website MSN Messenger
Chambahs
Guest


Offline

PostPosted: Sat Apr 02, 2005 6:36 pm    Post subject: Reply to topic Reply with quote

i can never make something by myself icon_sad.gif lol, anyway, smong fixed a bug or 2...

Code: Show/Hide

#Guessing Game By Chambahs and Smong
#3-2-05

from asss import *

chat = get_interface(I_CHAT)
stats = get_interface(I_STATS)
prng = get_interface(I_PRNG)


def count_players(arena):
    players = [ 0 ]
    def cb_count(p):
        if p.arena == arena:
       players[0] += 1
    for_each_player(cb_count)
    return players[0]

def c_start(cmd, params, p, targ):
    try:
   p.arena.guess_reward = int(params)
   if p.arena.guess_reward < 0:
            p.arena.guess_reward = 1000
    except:
   p.arena.guess_reward = 1000

    players = count_players(p.arena)
    if players > 1:
   chat.SendArenaMessage(p.arena, "The Number Game has started!! Pick a number between 0 and 1000.")
   chat.SendArenaMessage(p.arena, "Whoever gets the number first wins %d points!" % p.arena.guess_reward)
   chat.SendArenaSoundMessage(p.arena, SOUND_GOAL, "GO GO GO GO!!!!")
   p.arena.guess_number = prng.Number(1, 1000)
    elif players < 2:
   chat.SendArenaMessage(p.arena, "There arent enough people to play this game.")
    p.arena.guess_gameover = 0

def c_help(cmd, params, p, targ):
     """\ 
Module: <py> guess 
Args: [<reward>]
This command starts a guessing game in the current arena.
The default reward is 1000 points.
"""

cmd1 = add_command("gstart", c_start)

def chatmsg(p, mtype, sound, to, freq, text):
    try:
        if p.arena.guess_gameover == 1:
            return
    except:
        return

    if mtype == MSG_PUB:
   value = 0
   try:
       value = int(text)
   except:
       pass

   if value > 0 and value < 1000:
       if value > p.arena.guess_number:
                chat.SendMessage(p, "Too high.")
       elif value < p.arena.guess_number:
      chat.SendMessage(p, "Too low.")
       elif value == p.arena.guess_number:
      chat.SendMessage(p, "YOU WIN!")
      chat.SendArenaMessage(p.arena, p.name + " has won the guessing game with the number of %d !!!" % p.arena.guess_number)
                chat.SendArenaMessage(p.arena, p.name + " has been rewarded with %d points" % p.arena.guess_reward)
                stats.IncrementStat(p, STAT_FLAG_POINTS, p.arena.guess_reward)
                p.arena.guess_reward = 0
                p.arena.guess_gameover = 1

cb1 = reg_callback(CB_CHATMSG, chatmsg)



there, a present from us icon_smile.gif

Tested and approved by:
Chambahs® and Smong®
SSDT-A Unreal Tournament®




guess.py - 2.21 KB
File downloaded or viewed 122 time(s)
Back to top
D1st0rt
Miss Directed Wannabe


Age:36
Gender:Gender:Male
Joined: Aug 31 2003
Posts: 2247
Location: Blacksburg, VA
Offline

PostPosted: Sun Apr 03, 2005 12:02 am    Post subject: Reply to topic Reply with quote

That tested and approved by needs to go.
_________________

Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Display posts from previous:   
Post new topic   Reply to topic    Server Help Forum Index -> ASSS Custom Projects All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can 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
You can attach files in this forum
You can download files in this forum
View online users | View Statistics | View Ignored List


Software by php BB © php BB Group
Server Load: 655 page(s) served in previous 5 minutes.

phpBB Created this page in 0.541113 seconds : 35 queries executed (73.8%): GZIP compression disabled