Raised This Month: $51 Target: $400
 12% 

Solved Get max array of X flags in the loop


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Supremache
Veteran Member
Join Date: Sep 2019
Location: Egypt
Old 01-28-2022 , 04:55   Get max array of X flags in the loop
Reply With Quote #1

Hi all,
I have question i trying to make a code for check vip members in the chat but i had a small issue when compared vips number with max array number as example:

PHP Code:
@OnVipsOnlineid )
{
    new 
szBufferMAX_TEXT_LENGTH ], szPlayersMAX_PLAYERS ], iPlayeriNum;
    
formatexszBuffercharsmaxszBuffer ), "&x04Online:&x01 " );
    
    
get_playersszPlayersiNum "ch" ); // iNum = it is max player numbers in the server if i used it any where in the loop it also return all players in the server

    
for( new iIndexiiNumi++  )
    {
        if( 
g_iPlayer[ ( iIndex szPlayers] ) /* Check who has a vip flag */  ][ VIP ] & g_iSettingsAccess_OnlineList ] )
        { 
// i tried to compare iIndex with iNum and it work like adding symbol (,)  behinde all player names and another symbol (.) to the last player but work only when all players has that vip flag in the server so if anyone does not have that flag will add symbol (,) till if it was the last player
// I tried these ways but didn't work
            
formatszBuffercharsmaxszBuffer ), "%s%s%s"szBufferg_iPlayeriIndex ][ Name ], iNum < ( iPlayer iIndex /* return the vip numbers */ ) ? ", " "." );
            
formatszBuffercharsmaxszBuffer ), "%s%s%s"szBufferg_iPlayeriIndex ][ Name ], ( ( iPlayer iIndex ) < iNum ? ( iIndex <= iNum iIndex ) : ( iIndex <= iNum || iNum iIndex ) ) ? ", " "." );
            
formatszBuffercharsmaxszBuffer ), "%s%s%s"szBufferg_iPlayeriIndex ][ Name ], iNum == ( iPlayer iIndex ) ? "." ", " );
        }
    }
    
    if( !
iPlayer )
    {
        
addszBuffercharsmaxszBuffer ), "There are no vip's online." );
    }
    
    
CC_SendMessageidszBuffer );

I can do this with two loop but i think it's possible to do it with just one loop.
__________________
Youtube.com/Supremache

Bank System [Nvault - SQL Support]
VIP System
  • If you think it's that simple, then do it yourself.

Last edited by Supremache; 01-28-2022 at 07:24.
Supremache is offline
jimaway
Heeeere's Jimmy!
Join Date: Jan 2009
Location: Estonia
Old 01-28-2022 , 05:31   Re: Get max array of X flags in the loop
Reply With Quote #2

Code:
new istrlen for( new iIndex, i; i < iNum; i++  )     {         if( g_iPlayer[ ( iIndex = szPlayers[ i ] ) /* Check who has a vip flag */  ][ VIP ] & g_iSettings[ Access_OnlineList ] )         {             istrlen += formatex( szBuffer[istrlen], charsmax(szBuffer) - istrlen, "%s,",g_iPlayer[ iIndex ][ Name ]);         }     } szBuffer[istrlen-1] = '.'
jimaway is offline
Supremache
Veteran Member
Join Date: Sep 2019
Location: Egypt
Old 01-28-2022 , 06:09   Re: Get max array of X flags in the loop
Reply With Quote #3

Quote:
Originally Posted by jimaway View Post
Code:
new istrlen for( new iIndex, i; i < iNum; i++  )     {         if( g_iPlayer[ ( iIndex = szPlayers[ i ] ) /* Check who has a vip flag */  ][ VIP ] & g_iSettings[ Access_OnlineList ] )         {             istrlen += formatex( szBuffer[istrlen], charsmax(szBuffer) - istrlen, "%s,",g_iPlayer[ iIndex ][ Name ]);         }     } szBuffer[istrlen-1] = '.'
It's not what i want, what i want is adding symbol ( , ) after vip names except for the last one without creating a double loop in the same function
__________________
Youtube.com/Supremache

Bank System [Nvault - SQL Support]
VIP System
  • If you think it's that simple, then do it yourself.
Supremache is offline
jimaway
Heeeere's Jimmy!
Join Date: Jan 2009
Location: Estonia
Old 01-28-2022 , 06:29   Re: Get max array of X flags in the loop
Reply With Quote #4

Quote:
Originally Posted by Supremache View Post
what i want is adding symbol ( , ) after vip names except for the last one without creating a double loop in the same function
that's exactly what it does
jimaway is offline
Supremache
Veteran Member
Join Date: Sep 2019
Location: Egypt
Old 01-28-2022 , 07:15   Re: Get max array of X flags in the loop
Reply With Quote #5

Quote:
Originally Posted by jimaway View Post
that's exactly what it does
Yes, i was think adding strlen out the loop will do bug but it's work
Thanks you

PHP Code:
@OnVipsOnlineid )
{
    new 
szBufferMAX_TEXT_LENGTH ], szPlayersMAX_PLAYERS ], iPlayeriNum;
    
formatexszBuffercharsmaxszBuffer ), "&x04Online:&x01 " );
    
    
get_playersszPlayersiNum "ch" );

    for( new 
iIndexiiNumi++ )
    {
        if( 
g_iPlayer[ ( iIndex szPlayers] ) ][ VIP ] & g_iSettingsAccess_OnlineList ] )
        {  
// ( iPlayer = iIndex ) is see this way is better than using this iPlayer++ 
            
formatszBuffercharsmaxszBuffer ), "%s%s, "szBufferg_iPlayer[ ( iPlayer iIndex ) ][ Name ] );
        }
    }

    if( 
iPlayer )
    {
        
szBufferstrlenszBuffer ) - ] = '.' // Changed the strlen form -1 to -2 because i added a space 
    
}
    else
    {
        
addszBuffercharsmaxszBuffer ), "There are no vip's online." );
    }
    
    
CC_SendMessageidszBuffer );

__________________
Youtube.com/Supremache

Bank System [Nvault - SQL Support]
VIP System
  • If you think it's that simple, then do it yourself.

Last edited by Supremache; 01-28-2022 at 07:28.
Supremache is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 01-28-2022 , 08:29   Re: Get max array of X flags in the loop
Reply With Quote #6

Quote:
Originally Posted by jimaway View Post
Code:
new istrlen for( new iIndex, i; i < iNum; i++  )     {         if( g_iPlayer[ ( iIndex = szPlayers[ i ] ) /* Check who has a vip flag */  ][ VIP ] & g_iSettings[ Access_OnlineList ] )         {             istrlen += formatex( szBuffer[istrlen], charsmax(szBuffer) - istrlen, "%s, ",g_iPlayer[ iIndex ][ Name ]);         }     } szBuffer[istrlen-2] = '.' szBuffer[istrlen-1] = EOS;

Duhhhhh !??!?
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 01-28-2022 at 08:29.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Supremache
Veteran Member
Join Date: Sep 2019
Location: Egypt
Old 01-28-2022 , 08:33   Re: Get max array of X flags in the loop
Reply With Quote #7

Quote:
Originally Posted by Natsheh View Post
Duhhhhh !??!?
what do you mean ?
szBuffer[istrlen-2] = '.' // it work like replace so i think i dont need to clear it !!
__________________
Youtube.com/Supremache

Bank System [Nvault - SQL Support]
VIP System
  • If you think it's that simple, then do it yourself.

Last edited by Supremache; 01-28-2022 at 08:39.
Supremache is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 01-28-2022 , 09:22   Re: Get max array of X flags in the loop
Reply With Quote #8

Quote:
Originally Posted by Supremache View Post
what do you mean ?
szBuffer[istrlen-2] = '.' // it work like replace so i think i dont need to clear it !!
I meant why you didn't use jimmy's code and instead you kept using your code, jimmy's code is more efficient and faster.

And also you don't need the iPlayer variable just check whether the buffer is empty or not, like this...


PHP Code:
if( szBuffer[0] != EOS )
    {
        
szBufferstrlenszBuffer ) - ] = '.' // Changed the strlen form -1 to -2 because i added a space 
         
CC_SendMessage(idszBuffer);
    }
    else
    {
        
CC_SendMessageid"There are no vip's online." );
    } 
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 01-28-2022 at 09:36.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 01-28-2022 , 09:35   Re: Get max array of X flags in the loop
Reply With Quote #9

Quote:
Originally Posted by Supremache View Post
what do you mean ?
szBuffer[istrlen-2] = '.' // it work like replace so i think i dont need to clear it !!
PHP Code:
new istrlen
for( new iIndexiiNumi++  )
{
    if( 
g_iPlayer[ ( iIndex szPlayers] ) /* Check who has a vip flag */  ][ VIP ] & g_iSettingsAccess_OnlineList ] )
    { 
        
istrlen += formatexszBuffer[istrlen], charsmax(szBuffer) - istrlen"%s%s "g_iPlayeriIndex ][ Name ], == iNum -"" ",");
    }

__________________


Accepting Paid Requests, contact PM.

MVP Of The Round View project on GITHUB / AlliedModders
CSGO REMAKE ~ CSGO MOD [STABLE + SOURCE CODE]
Shadows Adi is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 01-28-2022 , 09:38   Re: Get max array of X flags in the loop
Reply With Quote #10

Quote:
Originally Posted by Shadows Adi View Post
PHP Code:
new istrlen
for( new iIndexiiNumi++  )
{
    if( 
g_iPlayer[ ( iIndex szPlayers] ) /* Check who has a vip flag */  ][ VIP ] & g_iSettingsAccess_OnlineList ] )
    { 
        
istrlen += formatexszBuffer[istrlen], charsmax(szBuffer) - istrlen"%s%s "g_iPlayeriIndex ][ Name ], == iNum -"" ",");
    }


This might not work because iNum might not be the last vip index.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 01-28-2022 at 09:46.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
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 14:11.


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