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)