Raised This Month: $344 Target: $400
 86%   Almost there!

Checking if a player hits "Next" and "Previous" in a menu


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
eyal282
Veteran Member
Join Date: Aug 2011
Old 01-19-2018 , 14:29   Checking if a player hits "Next" and "Previous" in a menu
Reply With Quote #1

How to do that? I can only do it on menu cancel but even then it may false predict if another menu interrupts.
__________________
I am available to make plugins for pay.

Discord: Eyal282#1334
eyal282 is offline
Ermert1992
Member
Join Date: Jan 2012
Location: Germany
Old 01-19-2018 , 15:50   Re: Checking if a player hits "Next" and "Previous" in a menu
Reply With Quote #2

Cool, there is a thread about this topic! Hopefully, there will appear some more helpful answers...
Ermert1992 is offline
Psyk0tik
Veteran Member
Join Date: May 2012
Location: Homeless
Old 01-20-2018 , 01:11   Re: Checking if a player hits "Next" and "Previous" in a menu
Reply With Quote #3

If it's a vote menu you can use IsVoteInProgress() to prevent other menus from interrupting it.
__________________
Psyk0tik is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 01-20-2018 , 09:00   Re: Checking if a player hits "Next" and "Previous" in a menu
Reply With Quote #4

Quote:
Originally Posted by Crasher_3637 View Post
If it's a vote menu you can use IsVoteInProgress() to prevent other menus from interrupting it.
It is. But I wanna massively re-display it so I must know when next is used and when previous is used.
__________________
I am available to make plugins for pay.

Discord: Eyal282#1334
eyal282 is offline
backwards
AlliedModders Donor
Join Date: Feb 2014
Location: USA
Old 01-20-2018 , 09:13   Re: Checking if a player hits "Next" and "Previous" in a menu
Reply With Quote #5

https://wiki.alliedmods.net/Menus_St...Action_Display

This could help
__________________
I highly recommend joining the SourceMod Discord Server for real time support.
backwards is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 01-20-2018 , 09:20   Re: Checking if a player hits "Next" and "Previous" in a menu
Reply With Quote #6

Quote:
Originally Posted by 1337norway View Post
A bit confusing for me, what to do with a hexadecimal value?
__________________
I am available to make plugins for pay.

Discord: Eyal282#1334
eyal282 is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 01-20-2018 , 09:23   Re: Checking if a player hits "Next" and "Previous" in a menu
Reply With Quote #7

Quote:
Originally Posted by eyal282 View Post
How to do that? I can only do it on menu cancel but even then it may false predict if another menu interrupts.
What problem? The menu isn't disposed until after the MenuAction_Cancel finishes. menu.Selection or GetMenuSelectionPosition should work until then.

You use these along with menu.DisplayAt or DisplayMenuAtItem to redisplay a menu at the correct page.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 01-20-2018 at 09:24.
Powerlord is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 01-20-2018 , 19:04   Re: Checking if a player hits "Next" and "Previous" in a menu
Reply With Quote #8

Quote:
Originally Posted by Powerlord View Post
What problem? The menu isn't disposed until after the MenuAction_Cancel finishes. menu.Selection or GetMenuSelectionPosition should work until then.

You use these along with menu.DisplayAt or DisplayMenuAtItem to redisplay a menu at the correct page.
Only valid in MenuAction_Select, and even then, it returns before the item was selected, therefore won't help.
__________________
I am available to make plugins for pay.

Discord: Eyal282#1334
eyal282 is offline
Lux
Veteran Member
Join Date: Jan 2015
Location: Brexit
Old 01-20-2018 , 19:27   Re: Checking if a player hits "Next" and "Previous" in a menu
Reply With Quote #9

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
__________________
Connect
My Plugins: KlickME
[My GitHub]

Commission me for L4D
Lux is offline
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
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 21:04.


Powered by vBulletin®
Copyright ©2000 - 2022, vBulletin Solutions, Inc.
Theme made by Freecode