Resource:Votemanager
This script manages any kind of poll with multiple options. votemap, votekick, votekill and voteban are built in.
Built-in polls
votemap (starts a vote between a random list of up to 9 maps compatible with the current gamemode, if one is running)
votemap gamemode (starts a vote between a random list of up to 9 maps compatible with the specified gamemode)
votemap gamemode map (starts a vote to launch the specified gamemode with the specified map)
votemap map (starts a vote to change to another map for the current gamemode, if one is running)
votekick player (starts a vote to kick the specified player)
votekill player (starts a vote to kill the specified player)
voteban player (starts a vote to ban the specified player)
Functions
startPoll
bool, int startPoll ( table pollData )
Creates a poll. Returns true if the poll was created successfully, false and an error code otherwise (see the source for error codes).
- pollData is a table containing poll settings and an array of at least two options. Each option comes in the form:
{string optionName, function functionToExecute, [ default=bool isDefault, arguments... ] }
The chosen option will be executed as functionToExecute(arguments...) when the poll ends. If there's not enough votes, the default option will be executed if there's one.
Example:
startPoll { --start settings (dictionary part) title="Kill "..playername.."?", --required percentage=75, --optional timeout=30, --optional allowchange=false, --optional maxnominations=3, --optional visibleTo=getRootElement(), --this can be either a parent element or a table of players --start options (array part) [1]={"Yes",killPlayer,player}, [2]={"No",outputChatBox,"votekill: Not enough votes to kill "..playername..".",getRootElement(),vR,vG,vB; default=true}, }
- percentage: percentage of votes needed to pass
- timeout: timeout in seconds
- allowchange: specifies if changing your vote is allowed
- maxnominations: specifies the max number of renominations after a draw
- visibleTo: a table or players that can see the poll, or an element that contains the players
You can use call to call any functions belonging to any other resource. Also, the syntax gets a bit more complicated if we want to evaluate code when the poll ends:
{"myOption",loadstring("killPlayer(getRandomPlayer())") }
voteconfig.xml defaults will be used for missing optional settings.
stopPoll
bool stopPoll ( )
Stops the running poll. Returns true if the current poll was stopped successfully, false if there wasn't one.
voteMap
bool, int voteMap ( string mapName )
Starts a votemap. Returns true if it was successfully started, false and an error code otherwise.
voteBetweenMaps
bool, int voteBetweenMaps ( resource map1, resource map2, [ resource map3, ... ] )
Starts a poll to choose a map. Returns true if it was successfully started, false and an error code otherwise.
voteKick
bool, int voteKick ( player thePlayer )
Starts a votekick. Returns true if it was successfully started, false and an error code otherwise.
voteKill
bool, int voteKill ( player thePlayer )
Starts a votekill. Returns true if it was successfully started, false and an error code otherwise.
voteBan
bool, int voteBan ( player thePlayer )
Starts a voteban. Returns true if it was successfully started, false and an error code otherwise.
Events
onPollStart
void onPollStart ( void )
Fired before a poll starts.
onPollDraw
void onPollDraw ( void )
Fired when a poll ends in a draw.
onClientSendVote
void onClientSendVote ( int vote )
Fired when a vote is sent to the server.
Configs
voteconfig.xml: default settings for a poll
managerconfig.xml: votemap/kick/ban state, command block interval and individual percent.