Raised This Month: $ Target: $400
 0% 

Plugin_handled & main


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Baws
Veteran Member
Join Date: Oct 2012
Old 03-03-2014 , 12:54   Plugin_handled & main
Reply With Quote #1

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 */
__________________
Like my clean plugins and work?
Baws is offline
georgik57
Veteran Member
Join Date: Oct 2008
Location: 🎧Music World
Old 03-03-2014 , 13:13   Re: Plugin_handled & main
Reply With Quote #2

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.
__________________
georgik57 is offline
Send a message via MSN to georgik57 Send a message via Yahoo to georgik57 Send a message via Skype™ to georgik57
Baws
Veteran Member
Join Date: Oct 2012
Old 03-03-2014 , 13:25   Re: Plugin_handled & main
Reply With Quote #3

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++
        }

__________________
Like my clean plugins and work?

Last edited by Baws; 03-03-2014 at 13:42.
Baws is offline
georgik57
Veteran Member
Join Date: Oct 2008
Location: 🎧Music World
Old 03-03-2014 , 13:40   Re: Plugin_handled & main
Reply With Quote #4

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.
__________________
georgik57 is offline
Send a message via MSN to georgik57 Send a message via Yahoo to georgik57 Send a message via Skype™ to georgik57
Baws
Veteran Member
Join Date: Oct 2012
Old 03-03-2014 , 13:54   Re: Plugin_handled & main
Reply With Quote #5

Thanks You<3
__________________
Like my clean plugins and work?
Baws is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 03-03-2014 , 13:55   Re: Plugin_handled & main
Reply With Quote #6

Quote:
Originally Posted by georgik57 View Post
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
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
georgik57
Veteran Member
Join Date: Oct 2008
Location: 🎧Music World
Old 03-03-2014 , 13:56   Re: Plugin_handled & main
Reply With Quote #7

Quote:
Originally Posted by YamiKaitou View Post
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.
__________________
georgik57 is offline
Send a message via MSN to georgik57 Send a message via Yahoo to georgik57 Send a message via Skype™ to georgik57
Baws
Veteran Member
Join Date: Oct 2012
Old 03-03-2014 , 14:00   Re: Plugin_handled & main
Reply With Quote #8

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++
        }

__________________
Like my clean plugins and work?

Last edited by Baws; 03-03-2014 at 14:01.
Baws is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 03-03-2014 , 14:03   Re: Plugin_handled & main
Reply With Quote #9

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)
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
Baws
Veteran Member
Join Date: Oct 2012
Old 03-03-2014 , 14:05   Re: Plugin_handled & main
Reply With Quote #10

Okay thanks appreciate it!
__________________
Like my clean plugins and work?
Baws 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 05:59.


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