Raised This Month: $ Target: $400
 0% 

Solved How to set dynamic array size


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
alasfourom
Senior Member
Join Date: Feb 2022
Location: Saudi Arabia
Old 02-11-2023 , 22:17   Re: How to set dynamic array size
Reply With Quote #1

I have mental block now, just to clear my point I will list the callback function here

PHP Code:
Action Command_Top(int clientint args)
{
    
g_KeyValue.Rewind();
    if(!
g_KeyValue.JumpToKey("Players Information"))
    {
        
delete g_KeyValue;
        
ThrowError("Corrupted file %s."g_sData_Path);
    }
    
    
//int iCount = GetTotalPlayersInTheDataFile();
    
int iPoints[100], iNumber 0;
    
char sName[100][32], sSteamID[100][32], sTemp[64];
    
    
Menu menu = new Menu(Handle_ShowTop10);
    
menu.SetTitle("Top 5 Ranks:");
    
    if(
g_KeyValue.GotoFirstSubKey())
    {
        do
        {
            
g_KeyValue.GetSectionName(sSteamID[iNumber], sizeof(sSteamID));
            
g_KeyValue.GetString("Player Name"sName[iNumber], sizeof(sName));
            
iPoints[iNumber] = g_KeyValue.GetNum("Total Points");
            
iNumber++;
        }
        while(
g_KeyValue.GotoNextKey());
    }
    
    
SortIntegers(iPoints100Sort_Descending);
    
    for (
int i 05i++)
    {
        
FormatEx(sTempsizeof(sTemp), "%s: %d points"sName[i], iPoints[i]);
        
menu.AddItem(sSteamID[i], sTempITEMDRAW_DEFAULT);
    }
    
    
menu.ExitBackButton true;
    
menu.Display(clientMENU_TIME_FOREVER);
    
    return 
Plugin_Handled;

its totally showing the top 5 players when called, but my issue, if the players count in the data file exceeded the [100], how to make it fit exactly my long data list.

So this part would be dunno something like this

PHP Code:
    int iCount GetTotalPlayersInTheDataFile();
    
int iPoints[iCount ], iNumber 0;
    
char sName[iCount ][32], sSteamID[iCount ][32], sTemp[64]; 
I also updated the post, cause I was poorly explaining my point, which I think its a little bit better
__________________

Last edited by alasfourom; 02-11-2023 at 22:20.
alasfourom 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 00:58.


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