Hi,
Thanks for the quick reply. The vote itself is functional, but I was wanting the vote feature to be written with the native votes API for a better looking HUD:
https://forums.alliedmods.net/showthread.php?t=208008
Video demonstration - you can see the nice HUD layout when I call the !fullspawns command as well as voting to change chapters:
https://youtu.be/XA_5p7zo6nM
Some example code that uses the Native Votes API (taken from the fullspawns sp file):
PHP Code:
public TurnOffFullSpawns(client)
{
if(StartEnableSpawnClearVote(client))
{
FakeClientCommand(client, "Vote Yes");
}
//====================
// Voting
//====================
bool:StartDisableSpawnClearVote(client)
{
if (!NativeVotes_IsVoteInProgress())
{
new iNumPlayers;
decl iPlayers[MaxClients];
for (new i=1; i<=MaxClients; i++)
{
if (!IsClientInGame(i) || IsFakeClient(i) || (GetClientTeam(i) == L4D_TEAM_SPECTATE))
{
continue;
}
iPlayers[iNumPlayers++] = i;
}
new String:sVote[64];
g_hDisableShutdownVote = NativeVotes_Create(VoteActionHandler, NativeVotesType_Custom_YesNo, MenuAction_Cancel | MenuAction_VoteEnd | MenuAction_End);
Format(sVote, sizeof(sVote), "Don't Allow Spawns To Shut Down?");
NativeVotes_SetTitle(g_hDisableShutdownVote, sVote);
NativeVotes_SetInitiator(g_hDisableShutdownVote, client);
NativeVotes_SetResultCallback(g_hDisableShutdownVote, VoteResultHandler);
NativeVotes_Display(g_hDisableShutdownVote, iPlayers, iNumPlayers, 20);
return true;
}
return false;
}
bool:StartEnableSpawnClearVote(client)
{
if (!NativeVotes_IsVoteInProgress())
{
new iNumPlayers;
decl iPlayers[MaxClients];
for (new i=1; i<=MaxClients; i++)
{
if (!IsClientInGame(i) || IsFakeClient(i) || (GetClientTeam(i) == L4D_TEAM_SPECTATE))
{
continue;
}
iPlayers[iNumPlayers++] = i;
}
new String:sVote[64];
g_hEnableShutdownVote = NativeVotes_Create(VoteActionHandler, NativeVotesType_Custom_YesNo, MenuAction_Cancel | MenuAction_VoteEnd | MenuAction_End);
Format(sVote, sizeof(sVote), "Allow Spawns To Shut Down?");
NativeVotes_SetTitle(g_hEnableShutdownVote, sVote);
NativeVotes_SetInitiator(g_hEnableShutdownVote, client);
NativeVotes_SetResultCallback(g_hEnableShutdownVote, VoteResultHandler);
NativeVotes_Display(g_hEnableShutdownVote, iPlayers, iNumPlayers, 20);
return true;
}
return false;
}
public VoteActionHandler(Handle:vote, MenuAction:action, param1, param2)
{
switch (action)
{
case MenuAction_End:
{
g_hDisableShutdownVote = INVALID_HANDLE;
g_hEnableShutdownVote = INVALID_HANDLE;
NativeVotes_Close(vote);
}
case MenuAction_VoteCancel:
{
switch (param1)
{
case VoteCancel_Generic:
{
NativeVotes_DisplayFail(vote, NativeVotesFail_Generic);
}
case VoteCancel_NoVotes:
{
NativeVotes_DisplayFail(vote, NativeVotesFail_NotEnoughVotes);
}
}
}
}
}
public VoteResultHandler(Handle:vote, num_votes, num_clients, const client_indexes[], const client_votes[], num_items, const item_indexes[], const item_votes[])
{
for (new i=0; i<num_items; i++)
{
if (item_indexes[i] == NATIVEVOTES_VOTE_YES)
{
if (item_votes[i] > (num_clients / 2))
{
if (vote == g_hDisableShutdownVote)
{
NativeVotes_DisplayPass(vote, "Disabling spawn clearing...");
DisableSpawnClear();
return;
}
else if (vote == g_hEnableShutdownVote)
{
NativeVotes_DisplayPass(vote, "Enabling spawn clearing...");
EnableSpawnClear();
return;
}
}
}
}
NativeVotes_DisplayFail(vote, NativeVotesFail_Loses);
}