Difference between revisions of "Left 4 Voting"
Devicenull (talk | contribs) (→Example voting plugin) |
Devicenull (talk | contribs) |
||
| Line 1: | Line 1: | ||
| − | Left 4 Dead has a new VGUI voting system, it's controlled by a bunch of events. | + | Left 4 Dead has a new VGUI voting system, it's controlled by a bunch of events. You can use either a string from the resource file, or L4D_TargetID_Player which will let you create any vote you want. |
| − | |||
| − | You can use a | ||
== How voting works == | == How voting works == | ||
| Line 9: | Line 7: | ||
== Example voting plugin == | == Example voting plugin == | ||
| − | This is a basic plugin that | + | This is a basic plugin that starts a vote, "Is gaben fat?". It does not ensure the same client does not vote multiple times, nor does it actually kick the user. |
<pre>#include <sourcemod> | <pre>#include <sourcemod> | ||
| Line 24: | Line 22: | ||
{ | { | ||
new Handle:msg = CreateEvent("vote_started"); | new Handle:msg = CreateEvent("vote_started"); | ||
| − | SetEventString(msg,"issue","# | + | SetEventString(msg,"issue","#L4D_TargetID_Player"); |
| − | SetEventString(msg,"param1","gaben"); | + | SetEventString(msg,"param1","Is gaben fat?"); |
SetEventInt(msg,"team",0); | SetEventInt(msg,"team",0); | ||
SetEventInt(msg,"initiator",0); | SetEventInt(msg,"initiator",0); | ||
| Line 52: | Line 50: | ||
{ | { | ||
msg = CreateEvent("vote_passed"); | msg = CreateEvent("vote_passed"); | ||
| − | SetEventString(msg,"details","# | + | SetEventString(msg,"details","#L4D_TargetID_Player"); |
| − | SetEventString(msg,"param1"," | + | SetEventString(msg,"param1","Gaben is fat"); |
SetEventInt(msg,"team",0); | SetEventInt(msg,"team",0); | ||
FireEvent(msg); | FireEvent(msg); | ||
Revision as of 23:40, 26 November 2008
Left 4 Dead has a new VGUI voting system, it's controlled by a bunch of events. You can use either a string from the resource file, or L4D_TargetID_Player which will let you create any vote you want.
How voting works
Server begins by sending a vote_started event, followed by a vote_changed event. Client's use the "Vote" command to register their votes, after which the server sends a vote_cast_yes or vote_case_no event, along with a vote_changed event.
When the vote is complete, the server sends vote_ended, followed by either vote_passed or vote_failed.
Example voting plugin
This is a basic plugin that starts a vote, "Is gaben fat?". It does not ensure the same client does not vote multiple times, nor does it actually kick the user.
#include <sourcemod>
new yesvotes;
new novotes;
#define MAX_VOTES 4
public OnPluginStart()
{
RegConsoleCmd("testvote",Callvote_Handler);
RegConsoleCmd("Vote",vote);
}
public Action:Callvote_Handler(client, args)
{
new Handle:msg = CreateEvent("vote_started");
SetEventString(msg,"issue","#L4D_TargetID_Player");
SetEventString(msg,"param1","Is gaben fat?");
SetEventInt(msg,"team",0);
SetEventInt(msg,"initiator",0);
FireEvent(msg);
yesvotes = 0;
novotes = 0;
UpdateVotes();
return Plugin_Handled;
}
public UpdateVotes()
{
new Handle:msg = CreateEvent("vote_changed");
SetEventInt(msg,"yesVotes",yesvotes);
SetEventInt(msg,"noVotes",novotes);
SetEventInt(msg,"potentialVotes",MAX_VOTES);
FireEvent(msg);
if (yesvotes+novotes == MAX_VOTES)
{
PrintToServer("voting complete!");
msg = CreateEvent("vote_ended");
FireEvent(msg);
if (yesvotes > novotes)
{
msg = CreateEvent("vote_passed");
SetEventString(msg,"details","#L4D_TargetID_Player");
SetEventString(msg,"param1","Gaben is fat");
SetEventInt(msg,"team",0);
FireEvent(msg);
}
else
{
msg = CreateEvent("vote_failed");
SetEventInt(msg,"team",0);
FireEvent(msg);
}
}
}
public Action:vote(client, args)
{
new String:arg[8];
GetCmdArg(1,arg,8);
PrintToServer("Got vote %s from %i",arg,client);
if (strcmp(arg,"Yes",true) == 0)
{
yesvotes++;
}
else if (strcmp(arg,"No",true) == 0)
{
novotes++;
}
UpdateVotes();
return Plugin_Continue;
}