AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Plugin_handled & main (https://forums.alliedmods.net/showthread.php?t=236360)

Baws 03-03-2014 12:54

Plugin_handled & main
 
I know the difference but what's the best to use? Like in all the plugins i see ( Mostly ) they use PLUGIN_HANDLED. So what's the best in the case of Music Player?

Code:
#define PLUGIN_CONTINUE  0    /* Results returned by public functions */ #define PLUGIN_HANDLED    1 /* stop other plugins */ #define PLUGIN_HANDLED_MAIN 2    /* to use in client_command(), continue all plugins but stop the command */

georgik57 03-03-2014 13:13

Re: Plugin_handled & main
 
Please show exactly where you want to use it. For hooking the chat I would recommend MAIN so other plugins can read the line too.

Baws 03-03-2014 13:25

Re: Plugin_handled & main
 
Here:
PHP Code:

#include < amxmodx >
#include < amxmisc >
#include < colorchat >
 
#define b_PLUGIN  "Advanced Music Player"
#define b_VERSION "1.4"
#define b_AUTHOR  "Baws"

#define MAX_SONGS 5000

new bSongId;
new 
bLastSongbSongCount;

new 
bMusicPlayer1536 ];
new 
b_Song_NamesMAX_SONGS ][ 64 ];
new 
b_Song_LinksMAX_SONGS ][ 512 ];
new 
bLastMusic33 ];

public 
plugin_init( )
{
        
register_pluginb_PLUGINb_VERSIONb_AUTHOR );
        
register_cvarb_PLUGINb_VERSIONFCVAR_SERVER FCVAR_EXTDLL FCVAR_UNLOGGED FCVAR_SPONLY );
       
        
register_clcmd"say""Cmd_Say" );
        
register_clcmd"say_team""Cmd_Say" );
    
        
register_concmd"amx_addsong""b_AddSong"ADMIN_CFG"- Usage: <song name> <song url/link> | Attention: Instead of < > use quotes." );
        
register_concmd"amx_reloadsong""b_ReloadSongList"ADMIN_CFG"- Reload's the songlist.ini file." );
       
        
bInitialize( );
}

public 
client_putinserverid )
{
        
bLastMusicid ] = 0;
}

public 
b_AddSongidlevelcid )
{
        if( !
cmd_accessidlevelcid) )
                return 
PLUGIN_HANDLED_MAIN;
    
        new 
bSongName33 ], bSongLink256 ]
        
read_argv1bSongNamecharsmaxbSongName ) )
        
read_argv2bSongLinkcharsmaxbSongLink ) )
    
        
copyb_Song_NamesbSongId ], charsmaxb_Song_Names[ ] ), bSongName )
        
copyb_Song_LinksbSongId++ ], charsmaxb_Song_Links[ ] ), bSongLink )
    
        new 
bConfigDir128 ], bFile128 ]
        
get_localinfo"amxx_configsdir"bConfigDircharsmaxbConfigDir ) )
    
        
formatexbFilecharsmaxbFile ), "%s/%s"bConfigDir"songlist.ini" )
        if( 
file_existsbFile ) )
        {
                new 
bText512 ]
                
formatexbTextcharsmaxbText ), "^n^"%s^" ^"%s^""bSongNamebSongLink )
                
write_filebFilebText )
        
                
console_printid"* Added %s to songlist.ini *"bSongName )
        }
    
        return 
PLUGIN_HANDLED_MAIN;
}
 
public 
b_ReloadSongListidlevelcid )
{
        if( !
cmd_accessidlevelcid) )
                return 
PLUGIN_HANDLED_MAIN;
       
        
bInitialize( )
        
console_printid"* songlist.ini file has been successfully reloaded *" )
       
        return 
PLUGIN_HANDLED_MAIN;
}
 
public 
Cmd_Sayid )
{
        static 
bSaid192 ], bBaws;
        
read_argsbSaid191 );
        
remove_quotesbSaid );
 
        if( 
equalibSaid,"/",) ) bBaws 1;
        else 
bBaws 0;
       
        new 
bFirstMsg21 ], bAllied];
        
strbreakbSaidbBaws ], bFirstMsg20bAllied)
       
        if( 
equalibFirstMsg"music" ) )
        {
                
SongListid );
                return 
PLUGIN_HANDLED_MAIN
        
}
               
        else if( 
equalibFirstMsg"stop" ) )
        {      
                static 
bMotd1024 ], bLen;
                
bLen formatexbMotdcharsmaxbMotd ), "<html><head><style type=^"text/css^">pre{color:#FFB000;}body{background:#000000;margin-left:8px;margin-top:0px;}</style></head><pre><body>" )
                
bLen += formatexbMotdbLen ], charsmaxbMotd ) - bLen"<center>Music Stopped. This has been brought you by %s.^n"b_PLUGIN )
                
bLen += formatexbMotdbLen ], charsmaxbMotd ) - bLen"<center>Hope you had fun listening to the nice music!^n" )
                
bLen += formatexbMotdbLen ], charsmaxbMotd ) - bLen"</body></pre></html>^n" )
                       
                
show_motdidbMotdb_PLUGIN )
                       
                return 
PLUGIN_HANDLED_MAIN;
        }
        else if( 
equalibFirstMsg"replay" ) )
        {
                if( 
bLastMusicid ] != )
                {
                        
bPlay_SongidbLastMusicid ] );
                }
                else
                {
                        
ColorChatidGREEN,"^x01You have not played any song yet." );
                }

                return 
PLUGIN_HANDLED_MAIN;
        }
        else if( 
equalibFirstMsg"copy" ) )
        {
                
Cmd_CopySongid );
                return 
PLUGIN_HANDLED_MAIN;
        }
        else if( 
equalibFirstMsg"search" ) )
        {      
                new 
bLeft151 ], bRight151 ]
 
                
strbreakbSaidbBaws ], bLeft150bRight150 )
                
strbreakbRightbLeft150bRight150 )
               
                
Cmd_SearchidbLeft );
                return 
PLUGIN_HANDLED_MAIN;
        }
       
        return 
PLUGIN_CONTINUE;
}
 
public 
SongListid )
{
        new 
bMenu menu_create"\yChoose a song to play:\r""SongList_Handler" )
        for( new 
1bSongCounti++ )
        {
                new 
bNum];
                
num_to_stribNum);
                
menu_additembMenub_Song_Names], bNum );
        }
       
        
menu_displayidbMenu );
 
        return 
PLUGIN_HANDLED;
}
 
public 
SongList_HandleridbMenuitem )
{
        if( 
item == MENU_EXIT )
        {
                
menu_destroybMenu );
                return 
PLUGIN_HANDLED;
        }
       
        new 
bData], bName64 ];
        new 
accesscallback;
        
menu_item_getinfobMenuitemaccessbDatacharsmaxbData ), bNamecharsmaxbName ), callback );
       
        new 
bChoice str_to_numbData );
       
        
bPlay_SongidbChoice );
       
        return 
PLUGIN_HANDLED;
}
 
public 
Cmd_SearchidbSearch[ ] )
{
        
ColorChatidGREEN"^x01You searched for '^x04%s^x01'^x04."bSearch )

        new 
bSearchMenu menu_create"\ySearching Results:\r""SongList_Handler" )
        new 
bNum];
       
        for( new 
1<= bSongCounti++ )
        {
                if( 
containib_Song_Names], bSearch ) != -)
                {
                        
num_to_stribNum);
                        
menu_additembSearchMenub_Song_Names], bNum );
                }
        }
       
        
menu_displayidbSearchMenu );
   
        return 
PLUGIN_HANDLED;
}
 
public 
Cmd_CopySongid )
{
        
bPlay_SongidbLastSong );
}
 
bPlay_Songidkey )
{
        if( !
file_existsbMusicPlayer ) )
                return;
 
        new 
bPlayersizeofbMusicPlayer ) ], bMotdsizeofbMusicPlayer ) ], bLinebLength
        
while( read_filebMusicPlayerbLine++, bPlayercharsmaxbPlayer ), bLength ) )
                
addbMotdcharsmaxbMotd ), bPlayer )
 
        
replace_allbMotdcharsmaxbMotd ), "[MEDIA_NAME]"b_Song_Nameskey ] )
        
replace_allbMotdcharsmaxbMotd ), "[MEDIA_URL]"b_Song_Linkskey ] )
       
        
show_motdidbMotdb_PLUGIN )
       
        new 
bName32 ];
        
get_user_nameidbName31 )
        
ColorChat0GREEN"^x03%s ^x01is now listening to ^x04%s^x01. Type ^x04/copy ^x01to copy his song."bNameb_Song_Nameskey ] )

        
bLastSong key
        bLastMusic
id ] = key
}
 
public 
bInitialize( )
{
        new 
bConfigDir128 ], bFile128 ], bFileText2048 ], bLen 0;
        
get_localinfo"amxx_configsdir"bConfigDircharsmaxbConfigDir ) )
       
        
formatexbFilecharsmaxbFile ), "%s/%s"bConfigDir"songlist.ini" )
        if( !
file_existsbFile ) )
        {
                
bLen formatbFileTextcharsmaxbFileText ), "; %s Songs^n"b_PLUGIN )
                
bLen += formatbFileTextbLen ], charsmaxbFileText ) - bLen"; Format: ^"Song Name^"  ^"Song Url/Link^"^n" )
                
bLen += formatbFileTextbLen ], charsmaxbFileText ) - bLen"; eg. ^"Eminem Mockingbird^" ^"http://www.youtube.com/watch?v=S9bCLPwzSC0^n^"" )    
                
write_filebFilebFileText )
        }
       
        
formatexbMusicPlayercharsmaxbMusicPlayer ), "%s/%s"bConfigDir"AdvMusicPlayer.html" ); bLen 0
        bSongCount 
1;

        new 
bText1024 ], bLinebLength
        
while( read_filebFilebLine++, bTextcharsmaxbText ), bLength ) )
        {
                
trimbText )
                if( !
bLength || bText] == ';' )
                        continue;
               
                if( 
bSongCount MAX_SONGS )
                        break;
                       
                static 
bLeft32 ], bRight512 ]
                
strbreakbTextbLeftcharsmaxbLeft ), bRightcharsmaxbRight ) )
               
                
replace_allbLeftcharsmaxbLeft ), "^"", "" )
                replace_all( bRight, charsmax( bRight), "
^"""" )
                
replace_allbRightcharsmaxbRight ), " ""%20" )
               
                
copyb_Song_NamesbSongCount ], charsmaxb_Song_Names[ ] ), bLeft )
                
copyb_Song_LinksbSongCount ], charsmaxb_Song_Links[ ] ), bRight )
                
bSongCount++
        }



georgik57 03-03-2014 13:40

Re: Plugin_handled & main
 
PLUGIN_HANDLED for the concmds.
If you want the chat command to be displayed PLUGIN_CONTINUE or if you want it to be hidden PLUGIN_HANDLED_MAIN.

Baws 03-03-2014 13:54

Re: Plugin_handled & main
 
Thanks You<3

YamiKaitou 03-03-2014 13:55

Re: Plugin_handled & main
 
Quote:

Originally Posted by georgik57 (Post 2106863)
PLUGIN_HANDLED for the concmds.

Only if you are trying to block the execution of the command.

Quote:

If you want the chat command to be displayed PLUGIN_CONTINUE or if you want it to be hidden PLUGIN_HANDLED_MAIN.
You can also use PLGUIN_HANDLED to hide chat

georgik57 03-03-2014 13:56

Re: Plugin_handled & main
 
Quote:

Originally Posted by YamiKaitou (Post 2106871)
Only if you are trying to block the execution of the command.


You can also use PLGUIN_HANDLED to hide chat

Ofc, but as I said before, it's up to what he wants to do. I just recommended what I think is best for his cases.

Baws 03-03-2014 14:00

Re: Plugin_handled & main
 
So what i used up there is good right? OR this is better?

PHP Code:

#include < amxmodx >
#include < amxmisc >
#include < colorchat >
 
#define b_PLUGIN  "Advanced Music Player"
#define b_VERSION "1.4"
#define b_AUTHOR  "Baws"

#define MAX_SONGS 5000

new bSongId;
new 
bLastSongbSongCount;

new 
bMusicPlayer1536 ];
new 
b_Song_NamesMAX_SONGS ][ 64 ];
new 
b_Song_LinksMAX_SONGS ][ 512 ];
new 
bLastMusic33 ];

public 
plugin_init( )
{
        
register_pluginb_PLUGINb_VERSIONb_AUTHOR );
        
register_cvarb_PLUGINb_VERSIONFCVAR_SERVER FCVAR_EXTDLL FCVAR_UNLOGGED FCVAR_SPONLY );
       
        
register_clcmd"say""Cmd_Say" );
        
register_clcmd"say_team""Cmd_Say" );
    
        
register_concmd"amx_addsong""b_AddSong"ADMIN_CFG"- Usage: <song name> <song url/link> | Attention: Instead of < > use quotes." );
        
register_concmd"amx_reloadsong""b_ReloadSongList"ADMIN_CFG"- Reload's the songlist.ini file." );
       
        
bInitialize( );
}

public 
client_putinserverid )
        
bLastMusicid ] = 0;

public 
b_AddSongidlevelcid )
{
        if( !
cmd_accessidlevelcid) )
                return 
PLUGIN_HANDLED;
    
        new 
bSongName33 ], bSongLink256 ]
        
read_argv1bSongNamecharsmaxbSongName ) )
        
read_argv2bSongLinkcharsmaxbSongLink ) )
    
        
copyb_Song_NamesbSongId ], charsmaxb_Song_Names[ ] ), bSongName )
        
copyb_Song_LinksbSongId++ ], charsmaxb_Song_Links[ ] ), bSongLink )
    
        new 
bConfigDir128 ], bFile128 ]
        
get_localinfo"amxx_configsdir"bConfigDircharsmaxbConfigDir ) )
    
        
formatexbFilecharsmaxbFile ), "%s/%s"bConfigDir"songlist.ini" )
        if( 
file_existsbFile ) )
        {
                new 
bText512 ]
                
formatexbTextcharsmaxbText ), "^n^"%s^" ^"%s^""bSongNamebSongLink )
                
write_filebFilebText )
        
                
console_printid"* Added %s to songlist.ini *"bSongName )
        }
    
        return 
PLUGIN_HANDLED;
}
 
public 
b_ReloadSongListidlevelcid )
{
        if( !
cmd_accessidlevelcid) )
                return 
PLUGIN_HANDLED;
       
        
bInitialize( )
        
console_printid"* songlist.ini file has been successfully reloaded *" )
       
        return 
PLUGIN_HANDLED;
}
 
public 
Cmd_Sayid )
{
        static 
bSaid192 ], bBaws;
        
read_argsbSaid191 );
        
remove_quotesbSaid );
 
        if( 
equalibSaid,"/",) ) bBaws 1;
        else 
bBaws 0;
       
        new 
bFirstMsg21 ], bAllied];
        
strbreakbSaidbBaws ], bFirstMsg20bAllied)
       
        if( 
equalibFirstMsg"music" ) )
        {
                
SongListid );
                return 
PLUGIN_HANDLED_MAIN;
        }
        else if( 
equalibFirstMsg"stop" ) )
        {      
                static 
bMotd1024 ], bLen;
                
bLen formatexbMotdcharsmaxbMotd ), "<html><head><style type=^"text/css^">pre{color:#FFB000;}body{background:#000000;margin-left:8px;margin-top:0px;}</style></head><pre><body>" )
                
bLen += formatexbMotdbLen ], charsmaxbMotd ) - bLen"<center>Music Stopped. This has been brought you by %s.^n"b_PLUGIN )
                
bLen += formatexbMotdbLen ], charsmaxbMotd ) - bLen"<center>Hope you had fun listening to the nice music!^n" )
                
bLen += formatexbMotdbLen ], charsmaxbMotd ) - bLen"</body></pre></html>^n" )
                       
                
show_motdidbMotdb_PLUGIN )
                       
                return 
PLUGIN_HANDLED_MAIN;
        }
        else if( 
equalibFirstMsg"replay" ) )
        {
                if( 
bLastMusicid ] != )
                {
                        
bPlay_SongidbLastMusicid ] );
                }
                else
                {
                        
ColorChatidGREEN,"[AG] ^x01You have not played any song yet." );
                }

                return 
PLUGIN_HANDLED_MAIN;
        }
        else if( 
equalibFirstMsg"copy" ) )
        {
                
Cmd_CopySongid );
                return 
PLUGIN_HANDLED_MAIN;
        }
        else if( 
equalibFirstMsg"search" ) )
        {      
                new 
bLeft151 ], bRight151 ]
 
                
strbreakbSaidbBaws ], bLeft150bRight150 )
                
strbreakbRightbLeft150bRight150 )
               
                
Cmd_SearchidbLeft );
                return 
PLUGIN_HANDLED_MAIN;
        }
       
        return 
PLUGIN_CONTINUE;
}
 
public 
SongListid )
{
        new 
bMenu menu_create"\yChoose a song to play:\r""SongList_Handler" )
        for( new 
1bSongCounti++ )
        {
                new 
bNum];
                
num_to_stribNum);
                
menu_additembMenub_Song_Names], bNum );
        }
       
        
menu_displayidbMenu );
 
        return 
PLUGIN_HANDLED;
}
 
public 
SongList_HandleridbMenuitem )
{
        if( 
item == MENU_EXIT )
        {
                
menu_destroybMenu );
                return 
PLUGIN_HANDLED;
        }
       
        new 
bData], bName64 ];
        new 
accesscallback;
        
menu_item_getinfobMenuitemaccessbDatacharsmaxbData ), bNamecharsmaxbName ), callback );
       
        new 
bChoice str_to_numbData );
       
        
bPlay_SongidbChoice );
       
        return 
PLUGIN_HANDLED;
}
 
public 
Cmd_SearchidbSearch[ ] )
{
        
ColorChatidGREEN"[AG] ^x01You searched for '^x04%s^x01'^x04."bSearch )

        new 
bSearchMenu menu_create"\ySearching Results:\r""SongList_Handler" )
        new 
bNum];
       
        for( new 
1<= bSongCounti++ )
        {
                if( 
containib_Song_Names], bSearch ) != -)
                {
                        
num_to_stribNum);
                        
menu_additembSearchMenub_Song_Names], bNum );
                }
        }
       
        
menu_displayidbSearchMenu );
   
        return 
PLUGIN_HANDLED;
}
 
public 
Cmd_CopySongid )
        
bPlay_SongidbLastSong );
 
bPlay_Songidkey )
{
        if( !
file_existsbMusicPlayer ) )
                return;
 
        new 
bPlayersizeofbMusicPlayer ) ], bMotdsizeofbMusicPlayer ) ], bLinebLength
        
while( read_filebMusicPlayerbLine++, bPlayercharsmaxbPlayer ), bLength ) )
                
addbMotdcharsmaxbMotd ), bPlayer )
 
        
replace_allbMotdcharsmaxbMotd ), "[MEDIA_NAME]"b_Song_Nameskey ] )
        
replace_allbMotdcharsmaxbMotd ), "[MEDIA_URL]"b_Song_Linkskey ] )
       
        
show_motdidbMotdb_PLUGIN )
       
        new 
bName32 ];
        
get_user_nameidbName31 )
        
ColorChat0GREEN"[AG] ^x03%s ^x01is now listening to ^x04%s^x01. Type ^x04/copy ^x01to copy his song."bNameb_Song_Nameskey ] )

        
bLastSong key
        bLastMusic
id ] = key
}
 
public 
bInitialize( )
{
        new 
bConfigDir128 ], bFile128 ], bFileText2048 ], bLen 0;
        
get_localinfo"amxx_configsdir"bConfigDircharsmaxbConfigDir ) )
       
        
formatexbFilecharsmaxbFile ), "%s/%s"bConfigDir"songlist.ini" )
        if( !
file_existsbFile ) )
        {
                
bLen formatbFileTextcharsmaxbFileText ), "; %s Songs^n"b_PLUGIN )
                
bLen += formatbFileTextbLen ], charsmaxbFileText ) - bLen"; Format: ^"Song Name^"  ^"Song Url/Link^"^n" )
                
bLen += formatbFileTextbLen ], charsmaxbFileText ) - bLen"; eg. ^"Eminem Mockingbird^" ^"http://www.youtube.com/watch?v=S9bCLPwzSC0^n^"" )    
                
write_filebFilebFileText )
        }
       
        
formatexbMusicPlayercharsmaxbMusicPlayer ), "%s/%s"bConfigDir"AdvMusicPlayer.html" ); bLen 0
        bSongCount 
1;

        new 
bText1024 ], bLinebLength
        
while( read_filebFilebLine++, bTextcharsmaxbText ), bLength ) )
        {
                
trimbText )
                if( !
bLength || bText] == ';' )
                        continue;
               
                if( 
bSongCount MAX_SONGS )
                        break;
                       
                static 
bLeft32 ], bRight512 ]
                
strbreakbTextbLeftcharsmaxbLeft ), bRightcharsmaxbRight ) )
               
                
replace_allbLeftcharsmaxbLeft ), "^"", "" )
                replace_all( bRight, charsmax( bRight), "
^"""" )
                
replace_allbRightcharsmaxbRight ), " ""%20" )
               
                
copyb_Song_NamesbSongCount ], charsmaxb_Song_Names[ ] ), bLeft )
                
copyb_Song_LinksbSongCount ], charsmaxb_Song_Links[ ] ), bRight )
                
bSongCount++
        }



YamiKaitou 03-03-2014 14:03

Re: Plugin_handled & main
 
I would use PLUGIN_HANDLED to block chat commands, unless you want another plugin to do something with them as well (and possible display them, bypassing your block)

Baws 03-03-2014 14:05

Re: Plugin_handled & main
 
Okay thanks appreciate it!


All times are GMT -4. The time now is 05:59.

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