Raised This Month: $ Target: $400
 0% 

if ! [Help] Equali, Print


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Baws
Veteran Member
Join Date: Oct 2012
Old 03-13-2014 , 21:10   if ! [Help] Equali, Print
Reply With Quote #1

I want something like when i type the command ( /search ) and if it didn't find anything it will print "Results: Nothing was found". What i did, didn't work. Tried many things didn't work. if(!...... else print ...etc didn't work. Is there a way to do it?


PHP Code:
public Cmd_Sayid 
{
        new 
szText192 ];
        
read_argsszTextcharsmaxszText ) );
        
remove_quotesszText );
    
        if( 
szText] != '/' )
                return 
PLUGIN_CONTINUE;
    
        if( 
equaliszText], "music") ) 
        {
                
SongListid );
        
                return 
PLUGIN_HANDLED;
        }
    
        else if( 
equaliszText], "stop") ) 
        {
                new 
Motd384 ], Len;
        
                
Len formatexMotdcharsmaxMotd ), "<html><head><style type=^"text/css^">pre{color:#FFB000;}body{background:#000000;margin-left:8px;margin-top:0px;}</style></head><pre><body><center>" );
                
Len += formatexMotdLen ], charsmaxMotd ) - Len"<b>Music Stopped</b>." );
                
Len += formatexMotdLen ], charsmaxMotd ) - Len"This has been brought you by %s.^n"g_szAuthor );
                
Len += formatexMotdLen ], charsmaxMotd ) - Len"%s is the most powerful music player plugin ever!^n"g_szPlugin );
                
Len += formatexMotdLen ], charsmaxMotd ) - Len"Hope you had fun listening to the nice music!^n" );
                
formatexMotdLen ], charsmaxMotd ) - Len"</center></body></pre></html>" );
        
                
show_motdidMotdg_szPlugin );
                return 
PLUGIN_HANDLED;
        }
    
        else if( 
equaliszText], "replay") ) 
        {
        
                if( 
g_Songid ] != )
                        
Play_Songidg_Songid ] );
                else
                        
client_print_coloridNORMAL"%L"id"NO_SONG_PLAYED" );
            
                return 
PLUGIN_HANDLED;
        }
    
        else if( 
equaliszText], "copy") ) 
        {
                
Cmd_CopySongid );
        
                return 
PLUGIN_HANDLED;
        }
    
        else if( 
equaliszText], "search") ) 
        {
                new 
szName64 ];
                
strbreakszText""0szNamecharsmaxszName ) );
        
                
Cmd_SearchidszName );
        
                return 
PLUGIN_HANDLED;
        }
    
        return 
PLUGIN_CONTINUE;
}

public 
SongList_HandleridhMenuitem 
{    
        if( 
item != MENU_EXIT )
        {
                new 
szData], szName64 ], accesscallback;
                
menu_item_getinfohMenuitemaccessszDatacharsmaxszData ), szNamecharsmaxszName ), callback )

                new 
sChoice str_to_numszData );

                
Play_SongidsChoice );
        }
    
        
menu_destroyhMenu )
        return 
PLUGIN_HANDLED;
}

Cmd_Searchid, const iText[ ] )
{
        
client_print_coloridNORMAL"%L"id"SEARCHED_FOR"iText ); //Where it says: "Searched for 'x'. " I want that if the 'x' word is not found well it will says instead of searched for, it'll say not found.

        
new szNum], hMenu menu_create"\ySearch Results:""SongList_Handler" );
    
        for( new 
g_SongCount i++ ) 
        {
                
num_to_striszNum)
                
ArrayGetArrayg_hArrayig_SongInformation );

                if( 
containig_SongInformationName ], iText ) == -)
                        continue;
        
                
menu_additemhMenug_SongInformationName ], szNum );
        }

        
menu_displayidhMenu )
        return 
PLUGIN_HANDLED;

__________________
Like my clean plugins and work?

Last edited by Baws; 03-13-2014 at 21:11.
Baws is offline
Kiske
Veteran Member
Join Date: May 2009
Old 03-13-2014 , 21:37   Re: if ! [Help] Equali, Print
Reply With Quote #2

PHP Code:
Cmd_Searchid, const iText[ ] )
{
    new 
szNum], hMenu menu_create"\ySearch Results:""SongList_Handler" );

    for( new 
g_SongCount i++ ) 
    {
        
num_to_striszNum)
        
ArrayGetArrayg_hArrayig_SongInformation );

        if( 
containig_SongInformationName ], iText ) == -)
            continue;

        
menu_additemhMenug_SongInformationName ], szNum );
    }

    if(
menu_items(hMenu) <= 0) {
        
client_print_coloridNORMAL"Results: Nothing was found");

        
menu_destroy(hMenu);
        return 
PLUGIN_HANDLED;
    } else {
        
client_print_coloridNORMAL"%L"id"SEARCHED_FOR"iText );
    }

    
menu_displayidhMenu )
    return 
PLUGIN_HANDLED;

__________________


Last edited by Kiske; 03-13-2014 at 21:39.
Kiske is offline
Send a message via Skype™ to Kiske
Baws
Veteran Member
Join Date: Oct 2012
Old 03-14-2014 , 00:09   Re: if ! [Help] Equali, Print
Reply With Quote #3

Won't work.


g_SongInformation[ Name ] = For the names and i think it should be used..
__________________
Like my clean plugins and work?

Last edited by Baws; 03-14-2014 at 00:10.
Baws is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 03-14-2014 , 01:20   Re: if ! [Help] Equali, Print
Reply With Quote #4

TL;DR

Just initialize a boolean as false. Set it to true ONLY if you find a match. At the end of the function, if the boolean is still false, no match was found.
__________________
fysiks is offline
Baws
Veteran Member
Join Date: Oct 2012
Old 03-14-2014 , 17:43   Re: if ! [Help] Equali, Print
Reply With Quote #5

I did everything, in any way possible. Didn't work.

Can you explain more please?
__________________
Like my clean plugins and work?
Baws is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 03-14-2014 , 18:39   Re: if ! [Help] Equali, Print
Reply With Quote #6

This is what fysiks suggested which is a good idea.
Code:
Cmd_Search( id, const iText[ ] ) {         new bool:bMatch, szNum[ 6 ], hMenu = menu_create( "\ySearch Results:", "SongList_Handler" );         for( new i = 1 ; i < g_SongCount + 1 ; i++ )     {         num_to_str( i, szNum, 5 )         ArrayGetArray( g_hArray, i, g_SongInformation );                 if( containi( g_SongInformation[ Name ], iText ) == -1 )         continue;                 bMatch = true;         menu_additem( hMenu, g_SongInformation[ Name ], szNum );     }         if ( ! bMatch ) {         client_print_color( id, NORMAL, "%L", id, "NOT_FOUND", iText );         menu_destroy(hMenu);         return;     }         client_print_color( id, NORMAL, "%L", id, "SEARCHED_FOR", iText );     menu_display( id, hMenu )     return; }
__________________
Black Rose is offline
Baws
Veteran Member
Join Date: Oct 2012
Old 03-14-2014 , 20:06   Re: if ! [Help] Equali, Print
Reply With Quote #7

It works, but i want to understand why what i did didn't work.

Here:
PHP Code:
new bool:bSearchFound;

Cmd_Searchid, const iText[ ] )
{
        if ( 
bSearchFound //if bool is false itll print this
        
{
                
client_print_coloridNORMAL"%L"id"NOT_FOUND"iText );
        
                
menu_destroyhMenu );
                return;
        }
        else 
//if bool is true, normal print 
                
client_print_coloridNORMAL"%L"id"SEARCHED_FOR"iText );

        new 
szNum], hMenu menu_create"\ySearch Results:""SongList_Handler" );
    
        for( new 
g_SongCount i++ )
        {
                
num_to_striszNum)
                
ArrayGetArrayg_hArrayig_SongInformation );
        
                if( 
containig_SongInformationName ], iText ) == -)
                continue;
        
                
bSearchFound true;
                
menu_additemhMenug_SongInformationName ], szNum );
        }

        
menu_displayidhMenu )
        return;

__________________
Like my clean plugins and work?
Baws is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 03-15-2014 , 02:58   Re: if ! [Help] Equali, Print
Reply With Quote #8

Come one baws, try to think. You see well you check bSearchFound before being set to true. Do you think once set, it will magically read the function from the start?
__________________
Arkshine is offline
Baws
Veteran Member
Join Date: Oct 2012
Old 03-15-2014 , 11:53   Re: if ! [Help] Equali, Print
Reply With Quote #9

Quote:
Originally Posted by Arkshine View Post
Come one baws, try to think. You see well you check bSearchFound before being set to true. Do you think once set, it will magically read the function from the start?
I just searched and a boolean is false from the start, yeah i did some effort and searched for it to make sure. Thanks mate.

Fixed btw.
__________________
Like my clean plugins and work?

Last edited by Baws; 03-15-2014 at 11:53.
Baws is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 03-15-2014 , 15:09   Re: if ! [Help] Equali, Print
Reply With Quote #10

Quote:
Originally Posted by baws View Post
I just searched and a boolean is false from the start, yeah i did some effort and searched for it to make sure. Thanks mate.

Fixed btw.
You never set the boolean back to false (in your code).
__________________
fysiks 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 06:50.


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