Resource:Votemanager

From Multi Theft Auto: Wiki
Jump to navigation Jump to search

This script manages any kind of poll with multiple options. Votemap, votekick and voteban are built in.

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 ( void )

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.

  • Note: It won't change the map yet as there's no map manager.

voteBetweenMaps

bool, int voteBetweenMaps ( string mapName1, string mapName2, [ string mapName3, ... ] )

Starts a poll to choose a map. Returns true if it was successfully started, false and an error code otherwise.

  • Note: It won't change the map yet as there's no map manager.

voteKick

bool, int voteKick ( string playerName )

Starts a votekick. Returns true if it was successfully started, false and an error code otherwise.

voteBan

bool, int voteBan ( string playerName )

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. Cancelling it will abort the poll.

onPollDraw

void onPollDraw ( void )

Fired when a poll ends in a draw. Cancelling it will abort renominations.

onClientSendVote

void onClientSendVote ( int vote )

Fired when a vote is sent to the server. Cancelling it will discard the vote.

Configs

voteconfig.xml: default settings for a poll

managerconfig.xml: votemap/kick/ban state, command block interval and individual percent.