Resource:Votemanager: Difference between revisions
m (Updated) |
No edit summary |
||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
This script manages any kind of poll with multiple options. '''votemap''', '''votekick''' and '''voteban''' are built in. | 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== | ==Functions== | ||
===startPoll=== | ===startPoll=== | ||
Line 36: | Line 51: | ||
===stopPoll=== | ===stopPoll=== | ||
<syntaxhighlight lang="lua">bool stopPoll ( | <syntaxhighlight lang="lua">bool stopPoll ( )</syntaxhighlight> | ||
Stops the running poll. Returns ''true'' if the current poll was stopped successfully, ''false'' if there wasn't one. | Stops the running poll. Returns ''true'' if the current poll was stopped successfully, ''false'' if there wasn't one. | ||
Line 44: | Line 59: | ||
===voteBetweenMaps=== | ===voteBetweenMaps=== | ||
<syntaxhighlight lang="lua">bool, int voteBetweenMaps ( | <syntaxhighlight lang="lua">bool, int voteBetweenMaps ( resource map1, resource map2, [ resource map3, ... ] )</syntaxhighlight> | ||
Starts a poll to choose a map. Returns ''true'' if it was successfully started, ''false'' and an error code otherwise. | Starts a poll to choose a map. Returns ''true'' if it was successfully started, ''false'' and an error code otherwise. | ||
===voteKick=== | ===voteKick=== | ||
<syntaxhighlight lang="lua">bool, int voteKick ( | <syntaxhighlight lang="lua">bool, int voteKick ( player thePlayer )</syntaxhighlight> | ||
Starts a votekick. Returns ''true'' if it was successfully started, ''false'' and an error code otherwise. | Starts a votekick. Returns ''true'' if it was successfully started, ''false'' and an error code otherwise. | ||
===voteKill=== | |||
<syntaxhighlight lang="lua">bool, int voteKill ( player thePlayer )</syntaxhighlight> | |||
Starts a votekill. Returns ''true'' if it was successfully started, ''false'' and an error code otherwise. | |||
===voteBan=== | ===voteBan=== | ||
<syntaxhighlight lang="lua">bool, int voteBan ( | <syntaxhighlight lang="lua">bool, int voteBan ( player thePlayer )</syntaxhighlight> | ||
Starts a voteban. Returns ''true'' if it was successfully started, ''false'' and an error code otherwise. | Starts a voteban. Returns ''true'' if it was successfully started, ''false'' and an error code otherwise. | ||
Line 58: | Line 77: | ||
===onPollStart=== | ===onPollStart=== | ||
<syntaxhighlight lang="lua">void onPollStart ( void )</syntaxhighlight> | <syntaxhighlight lang="lua">void onPollStart ( void )</syntaxhighlight> | ||
Fired before a poll starts | Fired before a poll starts. | ||
===onPollDraw=== | ===onPollDraw=== | ||
<syntaxhighlight lang="lua">void onPollDraw ( void )</syntaxhighlight> | <syntaxhighlight lang="lua">void onPollDraw ( void )</syntaxhighlight> | ||
Fired when a poll ends in a draw | Fired when a poll ends in a draw. | ||
===onClientSendVote=== | ===onClientSendVote=== | ||
<syntaxhighlight lang="lua">void onClientSendVote ( int vote )</syntaxhighlight> | <syntaxhighlight lang="lua">void onClientSendVote ( int vote )</syntaxhighlight> | ||
Fired when a vote is sent to the server | Fired when a vote is sent to the server. | ||
==Configs== | ==Configs== |
Revision as of 19:35, 9 September 2007
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.