Garry's Mod Wiki


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


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.


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.


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 function VisualVote() -- This is drawing function (Argument #4) draw.RoundedBox(4,ScrW()/2-300,ScrH()/2-25,600,50,Color(0,0,0,200)) draw.SimpleText("Rate our server by scale of zero to nine. Use number line to vote.","Trebuchet24",ScrW()/2,ScrH()/2,Color(255,255,255),1,1) end LocalPlayer():AddPlayerOption("SelectWeapon",30,AfterChoice,VisualVote) -- Creates new vote

Page Links

Special Pages



Render Time: 42ms

Session 0
DB GetPage 4
Generate Html 15
SaveChanges 10
Render Body 0
Render Sidebar 12