Garry's Mod Wiki

Player:AddPlayerOption

  Player:AddPlayerOption( string name, number timeout, function vote_callback, function draw_callback )

Description

Sets up the voting system for the player. This is a really barebone system. By calling this a vote gets started, when the player presses 0-9 the callback function gets called along with the key the player pressed. Use the draw callback to draw the vote panel.

Arguments

1 string name
Name of the vote
2 number timeout
Time until the vote expires
3 function vote_callback
The function to be run when the player presses 0-9 while a vote is active.
4 function draw_callback
Used to draw the vote panel.

Example

Simple example. Prints player's choice in chat.

function AfterChoice( num ) -- This is callback after we press number (Argument #3) chat.AddText( "Your rate is " .. num .. ". Thanks!" ) return true -- Return true to close vote end local BlackTransparent = Color( 0, 0, 0, 200 ) function VisualVote() -- This is drawing function (Argument #4) draw.RoundedBox( 4, ScrW() / 2 - 300, ScrH() / 2 - 25, 600, 50, BlackTransparent ) draw.SimpleText( "Rate our server by scale of zero to nine. Use number line to vote.", "Trebuchet24", ScrW() / 2 , ScrH() / 2, color_white, 1, 1 ) end LocalPlayer():AddPlayerOption( "SelectWeapon", 30, AfterChoice, VisualVote ) -- Creates new vote