Quote:
Originally Posted by Jackol1234
That makes a lot of sense. I didn't notice CLIENTINFO_CLIENT_INDEX in the include I was trying to write this from. Hopefully this works.
Edit: It worked now to translate the integer into a yes or no. I'm trying to understand this portion of the handler. I got this code from ckSurf and I'm confused how it gets this:
PHP Code:
if (item_info[0][VOTEINFO_ITEM_INDEX] == 0) { // If the winner is Yes votesYes = item_info[0][VOTEINFO_ITEM_VOTES]; if (num_items > 1) { votesNo = item_info[1][VOTEINFO_ITEM_VOTES]; }
} else { // If the winner is No votesNo = item_info[0][VOTEINFO_ITEM_VOTES]; if (num_items > 1) { votesYes = item_info[1][VOTEINFO_ITEM_VOTES]; } }
What is this checking "item_info[0][VOTEINFO_ITEM_INDEX] == 0" in the if statement and why do the votesNo and votesYes change places depending on the outcome of the if statement?
|
item_info array is sorted in descending order(number of votes)
So, item_info[0] is the winner item.
then item_info[1] is the 2nd voted item.
next, item_info[0][VOTEINFO_ITEM_INDEX] means winner item's item index
so what's item indices mean here?
you could find this code.
PHP Code:
public void StartVoteExtend(int client)
{
char szPlayerName[MAX_NAME_LENGTH];
GetClientName(client, szPlayerName, MAX_NAME_LENGTH);
CPrintToChatAll("[{olive}CK{default}] Vote to Extend started by {green}%s{default}", szPlayerName);
g_szUsedVoteExtend[g_VoteExtends] = g_szSteamID[client]; // Add the user's steam ID to the list
g_VoteExtends++; // Increment the total number of vote extends so far
Menu voteExtend = CreateMenu(H_VoteExtend);
SetVoteResultCallback(voteExtend, H_VoteExtendCallback);
char szMenuTitle[128];
char buffer[8];
IntToString(RoundToFloor(GetConVarFloat(g_hVoteExtendTime)), buffer, sizeof(buffer));
Format(szMenuTitle, sizeof(szMenuTitle), "Extend map for %s minutes?", buffer);
SetMenuTitle(voteExtend, szMenuTitle);
AddMenuItem(voteExtend, "", "Yes"); // << this is the first added item! So index = 0
AddMenuItem(voteExtend, "", "No"); // << this is the second added item! So index = 1
SetMenuExitButton(voteExtend, false);
VoteMenuToAll(voteExtend, 20);
}
"item_info[0][VOTEINFO_ITEM_INDEX] == 0" means the winner item's index is 0("Yes")
VOTEINFO_ITEM_VOTES means "how many clients voted this item."
at former statement(
if (item_info[0][VOTEINFO_ITEM_INDEX] == 0)) winner is "Yes"
so, put winner("Yes" item)'s vote count(
item_info[0][VOTEINFO_ITEM_VOTES]) into
votesYes
and put loser("No" item)'s vote count(
item_info[1][VOTEINFO_ITEM_VOTES]) into
votesNo
at latter statement(
else) winner is "No" or something
else
so, put winner("No" item)'s vote count(
item_info[0][VOTEINFO_ITEM_VOTES]) into
votesNo
and put loser("Yes" item)'s vote count(
item_info[1][VOTEINFO_ITEM_VOTES]) into
votesYes
Sorry for my poor explanation.
you can check out here for more info:
https://sm.alliedmods.net/new-api/menus
__________________