Votelib

From EventScripts Community Encyclopedia


Module: votelib

Module Overview

EventScripts version: 2.0 or greater

Table of Contents

Contents


Description

Creates an easymenu vote menu that allows easy vote creation and handling.

Quick Example

Creating a simple vote:

# Create a new vote
myVote = votelib.create('example_vote', 'myscript/vote_end', 'myscript/vote_submit')
# Set question and add some options
myVote.setquestion('Does votelib rock?')
myVote.addoption('Yes!')
myVote.addoption('No.')
myVote.addoption('Wtf?')
# Start the vote for 90 seconds and send the menu to everyone on the server
myVote.start(90)

Module Content

Classes

Methods

votelib.create(votename, end-function, submit-function)
Creates a new vote object with the specified name and returns a reference to the newly created vote class object of type votelib.Vote_vote.
The vote can be later referred to by the name given here by other functions shown here or with the vote console command.
Parameters:
  • votename -- the global vote name that identifies this vote
  • end-function -- a Python function or script block that will run at the end of the vote
Function will be called with the variables votename, win, winname, winvotes, winpercent, total, tie, cancelled
  • submit-function -- a Python function or script block that will run everytime a user submits a vote
Example:
# Create a new vote
myVote = votelib.create('example_vote', 'myscript/vote_end', 'myscript/vote_submit')
votelib.delete(votename)
Deletes a vote with the given name if it exists.
Raises ValueError if the vote does not exist
Example:
try:
    votelib.delete('example_vote')
except ValueError:
    es.dbgmsg(0, 'example_vote did not exist...')
votelib.exists(votename)
Returns True or False depending on if the named vote exists
Example:
if votelib.exists('example_vote'):
    votelib.delete('example_vote')
votelib.isrunning(votename)
Returns True or False depending on if the named vote is running or not
Example:
if votelib.isrunning('example_vote'):
    votelib.stop('example_vote')
votelib.find(votename)
Find the named vote object and returns the class object reference. If the named vote was not found, None is returned.
Example:
myVote = votelib.find('example_vote')
if myVote:
    myVote.stop()
votelib.send(votename, users, force = False, prio = False)
Sends the specified vote to selected users. As with most other functions, users can be either a single userid or a list of users.
If the named vote is not found, this function raises ValueError
force is an optional parameter that allows you to send the vote to the user if he already voted.
prio is an optional parameter that allows you to send the vote to the top of the users popup queue.
Example:
votelib.send('example_vote', es.getUseridList())

See Also

blog comments powered by Disqus