View Single Post
eyal282
Veteran Member
Join Date: Aug 2011
Old 01-23-2018 , 11:19   Re: Checking if a player hits "Next" and "Previous" in a menu
Reply With Quote #10

Quote:
Originally Posted by Lux View Post
Make the next page into a another menu handle and save the page number to a clientarray

in MenuAction_Select besure to close the previous menu handle and save the page here
I got cancer from trying to work it out without being brain raped by another menu...

PHP Code:

#include <sourcemod>

public Plugin:myinfo 
{
    
name "Admin Vote Map",
    
author "Eyal282 ( FuckTheSchool )",
    
description "Allows admins to let players decide a map to change to.",
    
version "1.1",
    
url "<- URL ->"
}

enum enMaps
{
    
String:CampaignName[50],
    
String:CampaignSerialName[50]
}
new const 
MapList[][enMaps] =
{
    { 
"Dead Center""c1m1_hotel" },
    { 
"Dark Carnival""c2m1_highway" },
    { 
"Swamp Fever""c3m1_plankcountry" },
    { 
"Hard Rain""c4m1_milltown_a" },
    { 
"The Parish""c5m1_waterfront" },
    { 
"The Sacrifice""c7m1_docks" },
    { 
"No Mercy""c8m1_apartment" },
    { 
"Crash Course""c9m1_alleys" },
    { 
"Death Toll""c10m1_caves" },
    { 
"Dead Air""c11m1_greenhouse" },
    { 
"Blood Harvest""c12m1_hilltop" },
    { 
"Cold Stream""c13m1_alpinecreek" }
};
new 
bool:isVoteRunning;

new 
TimeLeft;

new 
bCanVote[MAXPLAYERS];
new 
bNextMenu[MAXPLAYERS];

new 
Votes[sizeof(MapList)];

new 
Handle:hVoteTimer INVALID_HANDLE;

public 
OnPluginStart()
{
    
RegAdminCmd("sm_startvotemap"Command_StartVoteMapADMFLAG_VOTE);
    
RegAdminCmd("sm_stopvotemap"Command_StopVoteMapADMFLAG_VOTE);
}

public 
OnMapStart()
{
    
hVoteTimer INVALID_HANDLE;
}

public 
Action:Command_StopVoteMap(clientargs)
{
    if(!
isVoteRunning)
    {
        
ReplyToCommand(client"[SM] Error: No map vote is running.");
        return 
Plugin_Handled;
    }
    
    
FinishVote();
    
    
PrintToChatAll("\x03%N\x01 has stopped the\x04 map vote!"client);
    
    return 
Plugin_Handled;
}
public 
Action:Command_StartVoteMap(clientargs)
{
    if(
isVoteRunning)
    {
        
ReplyToCommand(client"[SM] Error: Map vote is already running.");
        return 
Plugin_Handled;
    }
    
    
TimeLeft 15;
    
    
isVoteRunning true;
    
    for(new 
i=0;sizeof(MapList);i++)
    {
        
Votes[i] = 0;
    }
    
    new 
String:TempFormat[100];
    
    for(new 
i=1;<= MaxClients;i++)
    {
        if(!
IsClientInGame(i))
            continue;
            
        else if(
IsFakeClient(i))
            continue;
            
        
bCanVote[i] = true;
        
bNextMenu[i] = false;
        
/*
        new Handle:hMenu = CreateMenu(Vote_MenuHandler);
        
        for(new ii=0;ii < sizeof(MapList);ii++)
        {
            Format(TempFormat, sizeof(TempFormat), "%s [ %i Votes ]", MapList[ii][CampaignName], Votes[ii]);
            AddMenuItem(hMenu, "", TempFormat);
        }
        
        SetMenuTitle(hMenu, "Choose your map:");
        DisplayMenu(hMenu, i, 1);
        */
    
}
    
TriggerTimer(hVoteTimer CreateTimer(1.0CountDown_TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE), true);
    
    
PrintToChatAll("\x03%N\x01 has started a\x04 map vote!"client);
    
PrintToChat(client"You can use !stopvotemap only before the timer hits 0.");
    return 
Plugin_Handled;
}

public 
Vote_MenuHandler(Handle:hMenuMenuAction:actionclientitem)
{
    if(
action == MenuAction_End)
        
delete hMenu;
    
    if(
action == MenuAction_Select)
    {
        
PrintToChatAll("%N %i"clientitem);
        if(
item == 7)
            
bNextMenu[client] = false;
                
        else if(
item == 8)
        {
            
PrintToChat(client"Testdve");
            
bNextMenu[client] = true;
        }
            
        else if(
item == 9)
            return;
            
        else if(
bCanVote[client])
        {    
            new 
ActualItem item item item;
            
Votes[ActualItem]++;
            
bCanVote[client] = false;
        }
    }
}

public 
Action:CountDown(Handle:hTimer)
{
    if(
TimeLeft == 0)
    {        
        new 
TotalVotes 0;
        new 
WinnerID 0;
        for(new 
i=0;sizeof(MapList);i++)
        {
            
TotalVotes += Votes[i];
            
            if(
Votes[i] > Votes[WinnerID] || ( Votes[i] == Votes[WinnerID] && GetRandomInt(01) == 1) ) // Make the map the winner if it has more votes or if votes are equal and luck helped the map.
                
WinnerID i;
        }
        
        
FinishVote();
        
        
ServerCommand("changelevel %s"MapList[WinnerID][CampaignSerialName]);
        
        return 
Plugin_Stop;
    }

    
PrintHintTextToAll("Vote map is running!\nTime Left: %i"TimeLeft);
    
    new 
String:TempFormat[50];
    
    for(new 
i=1;<= MaxClients;i++)
    {
        if(!
IsClientInGame(i))
            continue;
            
        else if(
IsFakeClient(i))
            continue;
        
        new 
Handle:hMenu CreateMenu(Vote_MenuHandler);
        new 
Button 0;
        for(new 
ii=0;ii sizeof(MapList);ii++)
        {
            
Button++;
            
            if(
Button == 8)
            {
                
AddMenuItem(hMenu"""Previous");
                
AddMenuItem(hMenu"""Next");
                
AddMenuItem(hMenu"""Exit");
                
Button 1;
            }
                
            
Format(TempFormatsizeof(TempFormat), "%s [ %i Votes ]"MapList[ii][CampaignName], Votes[ii]);
            
AddMenuItem(hMenu""TempFormat);
        }
        
        
//while(Button < 7)
        //{
            //AddMenuItem(hMenu, "", "", ITEMDRAW_NOTEXT);
            //Button++;
        //}
        
AddMenuItem(hMenu"""Previous");
        
AddMenuItem(hMenu"""Next");
        
AddMenuItem(hMenu"""Exit");
        
        
SetMenuTitle(hMenu"Choose your map:");
        
SetMenuPagination(hMenuMENU_NO_PAGINATION);
        
DisplayMenuAtItem(hMenuibNextMenu[i] ? 10 01);
    }
    
TimeLeft--;
    
    return 
Plugin_Continue;
}    

public 
FinishVote()
{
    
isVoteRunning false;
    
    
TimeLeft 0;
    
    if(
hVoteTimer != INVALID_HANDLE)
    {
        
CloseHandle(hVoteTimer);
        
hVoteTimer INVALID_HANDLE
    
}

__________________
I am available to make plugins for pay.

Discord: Eyal282#1334
eyal282 is offline