Raised This Month: $32 Target: $400
 8% 

Getting first value of the menu function and take points.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Mesharsky How2Kill
AlliedModders Donor
Join Date: May 2017
Location: Poland
Old 05-07-2019 , 22:13   Getting first value of the menu function and take points.
Reply With Quote #1

Hello there guys.

I have developed my own csgo ranks plugin, it's based by points.
More points you have, then higher rank you get silver 1 to global elite.
Now i added a feature to loose points, but when client goes to 0 or less there is spamming error in console that array index out of bounds, that's reasonable, because i didin't secure that.

Anyway, i have administration panel written by myself that allows admin to take the points from players


Code:
public Action CreateMenu_AddRemovePoints(int admin, int client, int iSelect)
{
	Menu next = new Menu(PointAct_MenuHandler);
	char frm[128];
	char pname[MAX_NAME_LENGTH + 1];
	GetClientName(client, pname, sizeof pname);
	Format(frm, sizeof frm, "Rangi - %s", pname);
	next.SetTitle(frm);
	
	next.AddItem("1", "1 point");
	next.AddItem("5", "5 Points");
	next.AddItem("10", "100 Points");
	next.AddItem("20", "200 Points");
	next.AddItem("50", "500 Points");
	next.AddItem("100", "1000 Points");
	next.AddItem("5000", "5000 Points");
	
	char sInfo[12];

	Format(sInfo, sizeof(sInfo), "%d", iSelect);
	next.AddItem("-SELECT-", sInfo, ITEMDRAW_IGNORE);
	Format(sInfo, sizeof(sInfo), "%d", client);
	next.AddItem("-CLIENT-", sInfo, ITEMDRAW_IGNORE);
	
	next.ExitButton = true;
	next.Display(admin, 60);
}
How can i do when player have less points than first value in the menu for example 100, if player have less than 100 points so this specific item in menu will have tag [X] and ITEMDRAW_DISABLED?

I don't know how can i get the first values of the menu in very simple way.

For a current solution i did something like that, but still i want this 1st option to work

Code:
if (iSelect == 1)
				g_iPoints[client] +=StringToInt(item);
			else if (iSelect == 2)
				if(g_iPoints[client] < StringToInt(item))
				{
					CPrintToChat(client, "{darkred}[✖] {yellow}You can't choose this option because client will have less than 0 points.", g_iPoints[client]);
				}
				else
				{
					g_iPoints[client] -= StringToInt(item);
				}
			
			CreateMenu_AddRemovePoints(param1, client, iSelect);
			CheckRank(client);
Appreciate any tips and help.

Last edited by Mesharsky How2Kill; 05-07-2019 at 22:19.
Mesharsky How2Kill is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 05-07-2019 , 23:22   Re: Getting first value of the menu function and take points.
Reply With Quote #2

If you ever plan on changing the point values on this menu, you may want to add MenuAction_DrawItem to the actions list and then use that action in your menu handler to check the items. Something like this:

PHP Code:
//When you create the menu
Menu next = new Menu(PointAct_MenuHandlerMENU_ACTIONS_DEFAULT|MenuAction_DrawItem);

// In your menu handler
switch (action)
{
    
// code to retrieve the client here

    
case MenuAction_Select:
    {
        
// Your other existing menu code here
    
}

    case 
MenuAction_End:
    {
        
delete menu;
    }

    
// param1 is the admin calling the menu, param2 is the menu item
    // If you changed these variable names in your handler declaration, change them here too
    
case MenuAction_DrawItem:
    {
        
char item[9];
        
int style;
        
menu.GetItem(param2itemsizeof(item), style);

        if (
StrEqual(item"-SELECT-") || StrEqual(item"-CLIENT-"))
            return 
style;

        
int itemValue StringToInt(item);
        if (
g_iPoints[client] < itemValue)
            
style ITEMDRAW_DISABLED;

        return 
style;
    }

    return 
0;

__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 05-07-2019 at 23:24. Reason: Fixed missing quotes around -CLIENT-
Powerlord is offline
Mesharsky How2Kill
AlliedModders Donor
Join Date: May 2017
Location: Poland
Old 05-08-2019 , 00:38   Re: Getting first value of the menu function and take points.
Reply With Quote #3

Quote:
Originally Posted by Powerlord View Post
If you ever plan on changing the point values on this menu, you may want to add MenuAction_DrawItem to the actions list and then use that action in your menu handler to check the items. Something like this:

PHP Code:
//When you create the menu
Menu next = new Menu(PointAct_MenuHandlerMENU_ACTIONS_DEFAULT|MenuAction_DrawItem);

// In your menu handler
switch (action)
{
    
// code to retrieve the client here

    
case MenuAction_Select:
    {
        
// Your other existing menu code here
    
}

    case 
MenuAction_End:
    {
        
delete menu;
    }

    
// param1 is the admin calling the menu, param2 is the menu item
    // If you changed these variable names in your handler declaration, change them here too
    
case MenuAction_DrawItem:
    {
        
char item[9];
        
int style;
        
menu.GetItem(param2itemsizeof(item), style);

        if (
StrEqual(item"-SELECT-") || StrEqual(item"-CLIENT-"))
            return 
style;

        
int itemValue StringToInt(item);
        if (
g_iPoints[client] < itemValue)
            
style ITEMDRAW_DISABLED;

        return 
style;
    }

    return 
0;

Thank you for fast reply, your code doesn`t really work for me, but i never createdmenu in sourcepawn like you in my life im still going to study that method.

My whole code for this is down below, i actually tried to rewrite for your method, but i got lots of errors, so i just keeped it my way.

PHP Code:
#define LoopItemCount(%1) for(int %1 = 0; %1 < menu.ItemCount; %1++)

public Action CreateMenu_AddRemovePoints(int adminint clientint iSelect)
{
    
Menu next = new Menu(PointAct_MenuHandler);
    
char frm[128];
    
char pname[MAX_NAME_LENGTH 1];
    
GetClientName(clientpnamesizeof pname);
    
Format(frmsizeof frm"Ranks - %s"pname);
    
next.SetTitle(frm);
    
    
next.AddItem("1""1 points");
    
next.AddItem("5""5 points");
    
next.AddItem("10""10 points");
    
next.AddItem("20""20 points");
    
next.AddItem("50""50 points");
    
next.AddItem("1000""1000 points");
    
next.AddItem("2500""2500 points");
    
next.AddItem("5000""5000 points");
    
    
char sInfo[12];

    
Format(sInfosizeof(sInfo), "%d"iSelect);
    
next.AddItem("-SELECT-"sInfoITEMDRAW_IGNORE);
    
Format(sInfosizeof(sInfo), "%d"client);
    
next.AddItem("-CLIENT-"sInfoITEMDRAW_IGNORE);
    
    
next.ExitButton true;
    
next.Display(admin60);
}

public 
int PointAct_MenuHandler(Menu menuMenuAction actionint param1int param2)
{
    
char sInfo[12], sDane[12];
    
int iSelectclient;
    
LoopItemCount(i)
    {
        
menu.GetItem(isInfosizeof(sInfo), _sDanesizeof(sDane));

        if (
StrEqual(sInfo"-SELECT-"))
            
iSelect StringToInt(sDane);
        
        if (
StrEqual(sInfo"-CLIENT-"))
            
client StringToInt(sDane);
    }
    if (
action == MenuAction_Select)
    {
        
char item[32];
        
menu.GetItem(param2itemsizeof(item));
        if (
IsValidClient(client))
        {
            if (
iSelect == 1)
                
g_iPoints[client] +=StringToInt(item);
            else if (
iSelect == 2)
                if(
g_iPoints[client] < StringToInt(item))
                {
                    
CPrintToChat(client"{darkred}[✖] {yellow}You can't choose this option because player will get points < 0"g_iPoints[client]);
                }
                else
                {
                    
g_iPoints[client] -= StringToInt(item);
                }
            
            
CreateMenu_AddRemovePoints(param1clientiSelect);
            
CheckRank(client);
        }
    }
    else if (
action == MenuAction_End)
        
delete menu;


Last edited by Mesharsky How2Kill; 06-17-2019 at 20:37.
Mesharsky How2Kill is offline
Mesharsky How2Kill
AlliedModders Donor
Join Date: May 2017
Location: Poland
Old 05-15-2019 , 15:56   Re: Getting first value of the menu function and take points.
Reply With Quote #4

I still don't get that, anyone any idea?
I tried to rewrite the whole menu code, but still errors or not working propery.
Mesharsky How2Kill is offline
Reply



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 07:16.


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