Player/AddPlayerOption

From Garry's Mod
Jump to: navigation, search
 Player:AddPlayerOption( )

Contents

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

string name

Name of the vote

Arguments

number timeout

Time until the vote expires

Arguments

function vote_callback

The function to be run when the player presses 0-9 while a vote is active.

Arguments

function draw_callback

Used to draw the vote panel.

Examples

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

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


Personal tools
Navigation