Resource:Votemanager: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
(Updated)
Line 7: Line 7:


'''votemap gamemode map''' (starts a vote to launch the specified gamemode with the specified map)
'''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)
'''votemap map''' (starts a vote to change to another map for the current gamemode, if one is running)
Line 16: Line 18:
'''voteban player''' (starts a vote to ban the specified player)
'''voteban player''' (starts a vote to ban the specified player)


==Functions==
==Serverside functions==
===startPoll===
===startPoll===
<syntaxhighlight lang="lua">bool, int startPoll ( table pollData )</syntaxhighlight>
<syntaxhighlight lang="lua">bool, int startPoll ( table pollData )</syntaxhighlight>
Line 27: Line 29:
Example:
Example:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
local playerToKill = getRandomPlayer()
local notEnoughVotesMessage = "Not enough votes to kill "..getPlayerName(playerToKill).."."
startPoll {
startPoll {
--start settings (dictionary part)
  --start settings (dictionary part)
title="Kill "..playername.."?", --required
  title="Kill "..getPlayerName(playerToKill).."?",
percentage=75, --optional
  percentage=75,
timeout=30, --optional
  timeout=30,
allowchange=false, --optional
  allowchange=false,
maxnominations=3, --optional
  maxnominations=3,
visibleTo=getRootElement(), --this can be either a parent element or a table of players
  visibleTo=getRootElement(),
--start options (array part)
  --start options (array part)
[1]={"Yes",killPlayer,player},
  [1]={"Yes", killPlayer, playerToKill},
[2]={"No",outputChatBox,"votekill: Not enough votes to kill "..playername..".",getRootElement(),vR,vG,vB; default=true},
  [2]={"No", outputChatBox, notEnoughVotesMessage, getRootElement(), vR, vG, vB; default=true},
}</syntaxhighlight>
}
*'''percentage''': percentage of votes needed to pass
</syntaxhighlight>
*'''timeout''': timeout in seconds
*'''title''' (required): the poll title which will be seen by clients on the manager GUI
*'''allowchange''': specifies if changing your vote is allowed
*'''percentage''' (optional, defaults to 75%): percentage needed for an option to pass
*'''maxnominations''': specifies the max number of renominations after a draw
*'''timeout''' (optional, defaults to 30s): poll timeout in seconds
*'''visibleTo''': a table or players that can see the poll, or an element that contains the players
*'''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'' 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:
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:
<syntaxhighlight lang="lua">{"myOption",loadstring("killPlayer(getRandomPlayer())") }</syntaxhighlight>
<syntaxhighlight lang="lua">{"myOption",loadstring("killPlayer(getRandomPlayer())") }</syntaxhighlight>


Line 51: Line 58:


===stopPoll===
===stopPoll===
<syntaxhighlight lang="lua">bool stopPoll ( )</syntaxhighlight>
<syntaxhighlight lang="lua">bool, int 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'' and an error code otherwise.


===voteMap===
===voteMap===
Line 74: Line 81:
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.


==Events==
==Serverside events==
===onPollStart===
===onPollStart===
<syntaxhighlight lang="lua">void onPollStart ( void )</syntaxhighlight>
<syntaxhighlight lang="lua">void onPollStart ( )</syntaxhighlight>
Fired before a poll starts.
Fired before a poll starts. Cancelling it aborts the poll.
 
===onPollStop===
<syntaxhighlight lang="lua">void onPollStop (  )</syntaxhighlight>
Fired before a poll is halted. Cancelling it prevents the poll from being halted.
 
===onPollEnd===
<syntaxhighlight lang="lua">void onPollStop (  )</syntaxhighlight>
Fired after a poll finished. Cancelling it has no effect.


===onPollDraw===
===onPollDraw===
<syntaxhighlight lang="lua">void onPollDraw ( void )</syntaxhighlight>
<syntaxhighlight lang="lua">void onPollDraw ( )</syntaxhighlight>
Fired when a poll ends in a draw.
Fired when a poll ends in a draw. Cancelling it aborts renominations.


===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. Cancelling it has no effect.


==Configs==
==Configs==
''These will be replaced by the registry [[#Settings|settings]] below.''
'''voteconfig.xml''': default settings for a poll
'''voteconfig.xml''': default settings for a poll


'''managerconfig.xml''': votemap/kick/ban state, command block interval and individual percent.
'''managerconfig.xml''': votemap/kick/ban state and individual command lock times / percent / allowchange / timeout.
 
==Settings==
<syntaxhighlight lang="xml">
<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="*votemap.timeout" value="30"/>
  <setting name="*votekick.locktime" value="120"/>
  <setting name="*votekick.percentage" value="75"/>
  <setting name="*votemap.allowchange" value="true"/>
 
  <setting name="*voteban.enabled" value="false"/>
  <setting name="*votemap.timeout" value="30"/>
  <setting name="*voteban.locktime" value="120"/>
  <setting name="*voteban.percentage" value="85"/>
  <setting name="*votemap.allowchange" value="true"/>
 
  <setting name="*votekill.enabled" value="true"/>
  <setting name="*votemap.timeout" value="30"/>
  <setting name="*votekill.locktime" value="120"/>
  <setting name="*votekill.percentage" value="75"/>
  <setting name="*votemap.allowchange" value="true"/>
</settings>
</syntaxhighlight>
 
==TODO==
*Uncomment settings registry code when the system is finished

Revision as of 23:17, 24 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 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.

Configs

These will be replaced by the registry settings below.

voteconfig.xml: default settings for a poll

managerconfig.xml: votemap/kick/ban state and individual command lock times / percent / allowchange / timeout.

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="*votemap.timeout" value="30"/>
   <setting name="*votekick.locktime" value="120"/>
   <setting name="*votekick.percentage" value="75"/>
   <setting name="*votemap.allowchange" value="true"/>
   
   <setting name="*voteban.enabled" value="false"/>
   <setting name="*votemap.timeout" value="30"/>
   <setting name="*voteban.locktime" value="120"/>
   <setting name="*voteban.percentage" value="85"/>
   <setting name="*votemap.allowchange" value="true"/>
   
   <setting name="*votekill.enabled" value="true"/>
   <setting name="*votemap.timeout" value="30"/>
   <setting name="*votekill.locktime" value="120"/>
   <setting name="*votekill.percentage" value="75"/>
   <setting name="*votemap.allowchange" value="true"/>
</settings>

TODO

  • Uncomment settings registry code when the system is finished