Resource:Votemanager: Difference between revisions
m (→Settings) |
(Updated) |
||
Line 102: | Line 102: | ||
Fired when a vote is sent to the server. Cancelling it has no effect. | Fired when a vote is sent to the server. Cancelling it has no effect. | ||
== | ==Default settings== | ||
<syntaxhighlight lang="xml"> | <syntaxhighlight lang="xml"> | ||
<settings> | <settings> | ||
<setting name="*default.timeout" value="[30]"/> | |||
<setting name="*default.allowchange" value="[false]"/> | |||
<setting name="*default.percentage" value="[75]"/> | |||
<setting name="*default.maxnominations" value="[3]"/> | |||
<setting name="*votemap.enabled" value="[true]"/> | |||
<setting name="*votemap.timeout" value="[30]"/> | |||
<setting name="*votemap.locktime" value="[60]"/> | |||
<setting name="*votemap.percentage" value="[70]"/> | |||
<setting name="*votemap.allowchange" value="[true]"/> | |||
<setting name="*votekick.enabled" value="[true]"/> | |||
<setting name="*votekick.timeout" value="[30]"/> | |||
<setting name="*votekick.locktime" value="[120]"/> | |||
<setting name="*votekick.percentage" value="[75]"/> | |||
<setting name="*votekick.allowchange" value="[true]"/> | |||
<setting name="*voteban.enabled" value="[false]"/> | |||
<setting name="*voteban.timeout" value="[30]"/> | |||
<setting name="*voteban.locktime" value="[120]"/> | |||
<setting name="*voteban.percentage" value="[85]"/> | |||
<setting name="*voteban.allowchange" value="[true]"/> | |||
<setting name="*votekill.enabled" value="[true]"/> | |||
<setting name="*votekill.timeout" value="[30]"/> | |||
<setting name="*votekill.locktime" value="[120]"/> | |||
<setting name="*votekill.percentage" value="[75]"/> | |||
<setting name="*votekill.allowchange" value="[true]"/> | |||
</settings> | </settings> | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Revision as of 02:04, 21 November 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 gamemode (same as previous one)
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)
Serverside 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:
local playerToKill = getRandomPlayer() local notEnoughVotesMessage = "Not enough votes to kill "..getPlayerName(playerToKill).."." startPoll { --start settings (dictionary part) title="Kill "..getPlayerName(playerToKill).."?", percentage=75, timeout=30, allowchange=false, maxnominations=3, visibleTo=getRootElement(), --start options (array part) [1]={"Yes", killPlayer, playerToKill}, [2]={"No", outputChatBox, notEnoughVotesMessage, getRootElement(), vR, vG, vB; default=true}, }
- title (required): the poll title which will be seen by clients on the manager GUI
- percentage (optional, defaults to 75%): percentage needed for an option to pass
- timeout (optional, defaults to 30s): poll timeout in seconds
- allowchange (optional, defaults to false): specifies if changing your vote is allowed
- maxnominations (optional, defaults to 3): specifies the max number of nominations in case there's a draw
- visibleTo (optional, defaults to getRootElement()): a table or players that will be able to see the poll, OR an element that contains the players.
If it is root, new players joining the server will be able to vote.
You can use call as the functionToExecute 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, int stopPoll ( )
Stops the running poll. Returns true if the current poll was stopped successfully, false and an error code otherwise.
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.
Serverside events
onPollStart
void onPollStart ( )
Fired before a poll starts. Cancelling it aborts the poll.
onPollStop
void onPollStop ( )
Fired before a poll is halted. Cancelling it prevents the poll from being halted.
onPollEnd
void onPollStop ( )
Fired after a poll finished. Cancelling it has no effect.
onPollDraw
void onPollDraw ( )
Fired when a poll ends in a draw. Cancelling it aborts renominations.
onClientSendVote
void onClientSendVote ( int vote )
Fired when a vote is sent to the server. Cancelling it has no effect.
Default settings
<settings> <setting name="*default.timeout" value="[30]"/> <setting name="*default.allowchange" value="[false]"/> <setting name="*default.percentage" value="[75]"/> <setting name="*default.maxnominations" value="[3]"/> <setting name="*votemap.enabled" value="[true]"/> <setting name="*votemap.timeout" value="[30]"/> <setting name="*votemap.locktime" value="[60]"/> <setting name="*votemap.percentage" value="[70]"/> <setting name="*votemap.allowchange" value="[true]"/> <setting name="*votekick.enabled" value="[true]"/> <setting name="*votekick.timeout" value="[30]"/> <setting name="*votekick.locktime" value="[120]"/> <setting name="*votekick.percentage" value="[75]"/> <setting name="*votekick.allowchange" value="[true]"/> <setting name="*voteban.enabled" value="[false]"/> <setting name="*voteban.timeout" value="[30]"/> <setting name="*voteban.locktime" value="[120]"/> <setting name="*voteban.percentage" value="[85]"/> <setting name="*voteban.allowchange" value="[true]"/> <setting name="*votekill.enabled" value="[true]"/> <setting name="*votekill.timeout" value="[30]"/> <setting name="*votekill.locktime" value="[120]"/> <setting name="*votekill.percentage" value="[75]"/> <setting name="*votekill.allowchange" value="[true]"/> </settings>