aquarius Posted February 2, 2008 Report Posted February 2, 2008 This will be posted in public as a tutorial, so be as informative as you can. I want to create my own module, preferably python. I want someone who knows how, to explain to me each step of the way how this module is written: Theres three bases. At the beginning of a game, I want to send out an arena message saying "Next game will begin in a moment" "Which base do you want to use? Vote 1, 2, or 3 (in public chat)" Then it needs to read public chat and see which number was said the most, one vote per person, and if they change their vote, the module will consider their latest vote and ignore the previous votes from that player. Once the module determines which base to use, it will close the other two doors on the map, closing off the other two base. Then warp everyone to center and start the game. Off the top of my head I suppose I need the 'interface' "chat" to record what players vote, and I need the 'interface' "game" to control doors and warp players. Is that correct? And do I need more?import ASSS chat = ASSS.getInterface(!@#$%^&*s.I_CHAT) game = ASSS.getInterface(!@#$%^&*s.I_GAME) Now what? I'm a noob. Quote
Smong Posted February 2, 2008 Report Posted February 2, 2008 You'll need cfg/I_CONFIG to change the doors via settings. For vote code you can look at elim in py or sgm_vote in C. Despite its name, sgm_vote is intended to swap between different game types, such as ctf and turf, so will need editing. The C version only counts the first number the player typed, I didn't double check the py version. One major thing you didn't mention is what defines the beginning/end of a game. Can't really make the module without knowing that. Commands could be used if you haven't decided yet (it can be changed later). Quote
aquarius Posted February 3, 2008 Author Report Posted February 3, 2008 import ASSS chat = ASSS.getInterface(!@#$%^&*s.I_CHAT) game = ASSS.getInterface(!@#$%^&*s.I_GAME) cfg = ASSS.getInterface(!@#$%^&*s.I_CONFIG) # vote # allows players to say any positive number into pub chat and it will get # recorded as a vote. def vote_chatmsg(p, mtype, sound, to, freq, text): if mtype == MSG_PUB: value = 0 try: value = int(text) except: p!@#$%^&* if value > 0: p.vote_value = value def vote_make_timer(arena, maxoption, timelimit, callback): def vote_timer(): # stop allowing votes arena.vote_ref1 = None arena.vote_ref2 = None # initialise the array sums = [] for i in range(maxoption): sums.append(0) # count the votes def cb_count_votes(p): if p.arena == arena and \ p.vote_value > 0 and \ p.vote_value <= maxoption: sums[p.vote_value - 1] += 1 for_each_player(cb_count_votes) # find the most popular vote besti = -1 best = 0 for i in range(maxoption): if sums[i] > best: best = sums[i] besti = i callback(arena, best, besti + 1) #arena.vote_ref3 = None return 0 return set_timer(vote_timer, timelimit, 1000) def vote_paction(p, action, arena): if action == PA_ENTERARENA: p.vote_value = 0 def vote_start(arena, question, maxoption, timelimit, callback): # reset all votes for this arena def cb_reset_votes(p): if p.arena == arena: p.vote_value = 0 for_each_player(cb_reset_votes) chat.SendArenaMessage(arena, "%s" % question) arena.vote_ref1 = reg_callback(CB_CHATMSG, vote_chatmsg, arena) arena.vote_ref2 = reg_callback(CB_PLAYERACTION, vote_paction, arena) arena.vote_ref3 = vote_make_timer(arena, maxoption, timelimit, callback) # stops the voting process def vote_stop(arena): arena.vote_ref1 = None arena.vote_ref2 = None arena.vote_ref3 = None Is that all the code I need? Also, can you explain these 'function parameters'? Example: def vote_chatmsg(p, mtype, sound, to, freq, text) Quote
Smong Posted February 3, 2008 Report Posted February 3, 2008 All that code will handle the voting. I doubt it will work without reformatting, it looks like it is using a mixture of tabs and spaces for indenting, and the forum coverted tabs to spaces, so copy/pasting it now will just break it. For the parameters, that function is actually the CB_CHATMSG callback, so you could check chat.h but I will explain it here:p - playermtype - message type (pub, team, etc, check the .h files for the constants)sound - optional bong, 0=no sound, check defs.h for the sound constantsto - I didn't check this but it's probably a player object, only valid if mtype is a priv messagefreq - same as above but for team messagestext - the typed message Quote
aquarius Posted February 3, 2008 Author Report Posted February 3, 2008 gotcha ok, now i need to know how the function parameters are 'utilized' below the declaration of them, highlighted in red just explain exactly what each value does and how it all interacts with eachother, in other words, where is the logic? Quote
Smong Posted February 5, 2008 Report Posted February 5, 2008 First the indenting needs fixing. I've done this for you, just download the latest version again. http://img150.imageshack.us/img150/2747/cbchatbv6.png Quote
Russky Posted February 24, 2008 Report Posted February 24, 2008 you p!@#$%^&* it into the function whenever person casts a vote i guess i didn't look that carefully, and it would be a pretty big pain to make a vote bot that counts several votes and not double votes Quote
Samapico Posted February 25, 2008 Report Posted February 25, 2008 For a mervbot plugin, it would be pretty simple... just need a linkedlist of the players who already voted. But in python, I have no idea Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.