AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   if ! [Help] Equali, Print (https://forums.alliedmods.net/showthread.php?t=236895)

Baws 03-13-2014 21:10

if ! [Help] Equali, Print
 
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;



Kiske 03-13-2014 21:37

Re: if ! [Help] Equali, Print
 
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;



Baws 03-14-2014 00:09

Re: if ! [Help] Equali, Print
 
Won't work.


g_SongInformation[ Name ] = For the names and i think it should be used..

fysiks 03-14-2014 01:20

Re: if ! [Help] Equali, Print
 
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.

Baws 03-14-2014 17:43

Re: if ! [Help] Equali, Print
 
I did everything, in any way possible. Didn't work.

Can you explain more please?

Black Rose 03-14-2014 18:39

Re: if ! [Help] Equali, Print
 
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; }

Baws 03-14-2014 20:06

Re: if ! [Help] Equali, Print
 
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;



Arkshine 03-15-2014 02:58

Re: if ! [Help] Equali, Print
 
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?

Baws 03-15-2014 11:53

Re: if ! [Help] Equali, Print
 
Quote:

Originally Posted by Arkshine (Post 2111656)
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.

fysiks 03-15-2014 15:09

Re: if ! [Help] Equali, Print
 
Quote:

Originally Posted by baws (Post 2111811)
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).


All times are GMT -4. The time now is 06:00.

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