AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Cells And Array Errors [ Wrong? ] (https://forums.alliedmods.net/showthread.php?t=236423)

Baws 03-04-2014 16:51

Cells And Array Errors [ Wrong? ]
 
fputs: Error: Number of arguments does not match definition on line 257

PHP Code:

get_localinfo"amxx_configsdir"iConfigDircharsmaxiConfigDir ) )
    
        
format(iFile127"configs/songlist.ini")
        if( !
file_existsiFile ) )  
        {
                new 
FileP fopeniFile"+a" )
                
fputsFileP"; %s Songs^n"g_szPlugin )
                
fputsFileP"; Format: ^"Song Name^"  ^"Song Url/Link^"^n" )
                
fputsFileP"; eg. ^"Eminem Mockingbird^" ^"http://www.youtube.com/watch?v=S9bCLPwzSC0^n^"" )
                
fcloseFileP )
                
server_print"%L"iFile"FILE_ADDED" )
        } 

Array:
Error: Undefined symbol "MaxSongs" on line 24
Error: Undefined symbol "MaxSongs" on line 25
Error: Undefined symbol "x" on line 45
Warning: Tag mismatch on line 281

PHP Code:

                if( SongCount MaxSongs // warning
                        
break; 

PHP Code:

plugin_init:         MaxSongs ArrayCreate);
New: new 
g_Song_NamesMaxSongs ][ 64 ];
new 
g_Song_LinksMaxSongs ][ 512 ];

new Array:
MaxSongs

What's the problem up there?

YamiKaitou 03-04-2014 16:56

Re: Cells And Array Errors [ Wrong? ]
 
Complete code?

Remember, you need to define the variable before you use it. Also, you cannot use a CellArray as a size of an array.
fputs does not format, use fprintf to do that

Baws 03-04-2014 16:59

Re: Cells And Array Errors [ Wrong? ]
 
Full code: ( The fprintf worked thanks but others idk )
Didn't test the plugin yet tho.
PHP Code:

#include < amxmodx >
#include < amxmisc >

#define TASK_ID_CMSG 2000

new const g_szPlugin[ ]   = "Advanced Music Player";
new const 
g_szVersion[ ]  = "1.5";
new const 
g_szAuthor[ ]   = "Baws";

enum Color
{
    
NORMAL 1,
    
GREEN
    
TEAM_COLOR,
    
GREY
    
RED
    
BLUE
};

new 
SongId;
new 
LastSongSongCount;

new 
g_MusicPlayer1206 ];
new 
g_Song_NamesMaxSongs ][ 64 ];
new 
g_Song_LinksMaxSongs ][ 512 ];
new 
g_LastMusic33 ];

new Array:
MaxSongs;

new 
PcvarConnectMsg;

public 
plugin_init( )
{
        
register_pluging_szPluging_szVersiong_szAuthor );
        
register_cvarg_szPluging_szVersionFCVAR_SERVER FCVAR_EXTDLL FCVAR_UNLOGGED FCVAR_SPONLY );
       
        
register_clcmd"say""Cmd_Say" );
        
register_clcmd"say_team""Cmd_Say" );
    
        
register_concmd"amx_addsong""AddSong"ADMIN_CFG"- Usage: <song name> <song url/link> | Attention: Instead of < > use quotes." );
        
register_concmd"amx_reloadfile""ReloadSongList"ADMIN_CFG"- Reload's the songlist.ini file." );
    
        
PcvarConnectMsg register_cvar"sv_connectmessage""1" );
    
        
MaxSongs ArrayCreate);
    
        
register_dictionary_colored"AdvMusicPlayer.txt" );
       
        
Initialize( );
}

public 
client_putinserverid )
{
        
g_LastMusicid ] = 0;

        if( 
get_pcvar_numPcvarConnectMsg ) == )
                
set_task25.0"ConnectMsg"id TASK_ID_CMSG )
}

public 
ConnectMsgid )
{
        
id -= TASK_ID_CMSG
    
        
if( get_pcvar_numPcvarConnectMsg ) == )
        {
                new 
szName32 ];
                
get_user_nameidszNamecharsmaxszName ) )
                
client_print_coloridNORMAL"%L"szNameid"CONNECT_MSG" )
        }
}

public 
AddSongidlevelcid )
{
        if( !
cmd_accessidlevelcid) )
                return 
PLUGIN_HANDLED;
    
        new 
szSongName36 ], szSongLink256 ]
        
read_argv1szSongNamecharsmaxszSongName ) )
        
read_argv2szSongNamecharsmaxszSongLink ) )
    
        
copyg_Song_NamesSongId ], charsmaxg_Song_Names[ ] ), szSongName )
        
copyg_Song_LinksSongId++ ], charsmaxg_Song_Links[ ] ), szSongLink )
    
        new 
iConfigDir128 ], iFile128 ]
        
get_localinfo"amxx_configsdir"iConfigDircharsmaxiConfigDir ) )
    
        
formatexiFilecharsmaxiFile ), "%s/%s"iConfigDir"songlist.ini" )
        if( 
file_existsiFile ) )
        {
                new 
iText512 ]
                
formatexiTextcharsmaxiText ), "^n^"%s^" ^"%s^""szSongNameszSongLink )
                
write_fileiFileiText )
        
                
console_printid"%L"szSongNameid"SONG_ADDED" )
        }
    
        return 
PLUGIN_HANDLED;
}
 
public 
ReloadSongListidlevelcid )
{
        if( !
cmd_accessidlevelcid) )
                return 
PLUGIN_HANDLED;
       
        
Initialize( )
        
console_printid"%L"id"FILE_RELOADED" )
       
        return 
PLUGIN_HANDLED;
}

public 
Cmd_Sayid )
{
        static 
Said192 ], Baws;
        
read_argsSaid191 );
        
remove_quotesSaid );
 
        if( 
equaliSaid"/") ) Baws 1;
        else 
Baws 0;
       
        new 
szFirstMsg21 //szAllied[ 2 ]; //strbreak( Said[ Baws ], szFirstMsg, 20, szAllied, 1 )
       
        
if( equaliszFirstMsg"music" ) )
        {
                
SongListid );
                return 
PLUGIN_HANDLED;
        }
        else if( 
equaliszFirstMsg"stop" ) )
        {      
                static 
Motd1024 ], 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>" )
                
Len += formatexMotdLen], charsmaxMotd ) - Len"<center><b>Music Stopped</b>." )
                
Len += formatexMotdLen ], charsmaxMotd ) - Len"<center>This has been brought you by %s.^n"g_szAuthor )
                
Len += formatexMotdLen ], charsmaxMotd ) - Len"<center>%s is the most powerful music player plugin ever!"g_szPlugin )
                
Len += formatexMotdLen ], charsmaxMotd ) - Len"<center>Hope you had fun listening to the nice music!^n" )
                
Len += formatexMotdLen ], charsmaxMotd ) - Len"</body></pre></html>^n" )
                       
                
show_motdidMotdg_szPlugin )
                       
                return 
PLUGIN_HANDLED;
        }
        else if( 
equaliszFirstMsg"replay" ) )
        {
                if( 
g_LastMusicid ] != )
                {
                        
Play_Songidg_LastMusicid ] );
                }
                else
                {
                        
client_print_coloridNORMAL"%L"id"NO_SONG_PLAYED" );
                }

                return 
PLUGIN_HANDLED;
        }
        else if( 
equaliszFirstMsg"copy" ) )
        {
                
Cmd_CopySongid );
                return 
PLUGIN_HANDLED;
        }
        else if( 
equaliszFirstMsg"search" ) )
        {      
                new 
Left151 ], Right151 ];
 
                
parseSaidBaws ], Left150Right150 //strbreak( Right, Left, 150, Right, 150 )
               
                
Cmd_SearchidLeft );
                return 
PLUGIN_HANDLED;
        }
       
        return 
PLUGIN_CONTINUE;
}
 
public 
SongListid )
{
        new 
Menu menu_create"\yChoose a song to play:\r""SongList_Handler" )

        new 
Num];
        for( new 
0SongCounti++ )
        {
                
num_to_striNum);
                
menu_additemMenug_Song_Names], Num );
        }
       
        
menu_displayidMenu );
 
        return 
PLUGIN_HANDLED;
}

public 
SongList_HandleridMenuitem )
{
        if( 
item == MENU_EXIT )
        {
                
menu_destroyMenu );
                return 
PLUGIN_HANDLED;
        }
       
        
Play_Songiditem );
       
        return 
PLUGIN_HANDLED;
}

public 
Cmd_SearchidSearch[ ] )
{
        
client_print_coloridNORMAL"%L"Searchid"SEARCHED_FOR" )

        new 
SearchMenu menu_create"\ySearching Results:\r""SongList_Handler" )
    
        new 
Num];
        for( new 
0<= SongCounti++ )
        {
                if( 
containig_Song_Names], Search ) != -)
                {
                        
num_to_striNum);
                        
menu_additemSearchMenug_Song_Names], Num );
                }
        }
       
        
menu_displayidSearchMenu );
   
        return 
PLUGIN_HANDLED;
}
 
public 
Cmd_CopySongid )
        
Play_SongidLastSong );
 
Play_Songidkey )
{
        if( !
file_existsg_MusicPlayer ) )
                return;

        new 
szPlayercharsmaxg_MusicPlayer ) ], szMotdcharsmaxg_MusicPlayer ) ], szLineszLength
        
while( read_fileg_MusicPlayerszLine++, szPlayercharsmaxszPlayer ), szLength ) )
                
addszMotdcharsmaxszMotd ), szPlayer )
 
        
parseszMotdcharsmaxszMotd ), "[MEDIA_NAME]"g_Song_Nameskey ] )
        
parseszMotdcharsmaxszMotd ), "[MEDIA_URL]"g_Song_Linkskey ] )
       
        
show_motdidszMotdg_szPlugin )
       
        new 
szName32 ];
        
get_user_nameidszName31 )
        
client_print_color0NORMAL"%L"szNameg_Song_Nameskey ], id"LISTENING_TO" )

        
LastSong key
        g_LastMusic
id ] = key
}
 
public 
Initialize( )
{
        new 
iConfigDir128 ], iFile128 ]//, iFileText[ 2048 ], iLen = 0;
        
get_localinfo"amxx_configsdir"iConfigDircharsmaxiConfigDir ) )
    
        
format(iFile127"configs/songlist.ini")
        if( !
file_existsiFile ) )  
        {
                new 
FileP fopeniFile"+a" )
                
fprintfFileP"; %s Songs^n"g_szPlugin )
                
fprintfFileP"; Format: ^"Song Name^"  ^"Song Url/Link^"^n" )
                
fprintfFileP"; eg. ^"Eminem Mockingbird^" ^"http://www.youtube.com/watch?v=S9bCLPwzSC0^n^"" )
                
fcloseFileP )
                
server_print"%L"iFile"FILE_ADDED" )
        }
        
/*formatex( iFile, charsmax( iFile ), "%s/%s", iConfigDir, "songlist.ini" )
        if( !file_exists( iFile ) )
        {
                iLen = format( iFileText, charsmax( iFileText ), "; %s Songs^n", g_szPlugin )
                iLen += format( iFileText[ iLen ], charsmax( iFileText ) - iLen, "; Format: ^"Song Name^"  ^"Song Url/Link^"^n" )
                iLen += format( iFileText[ iLen ], charsmax( iFileText ) - iLen, "; eg. ^"Eminem - Mockingbird^" ^"http://www.youtube.com/watch?v=S9bCLPwzSC0^n^"" )    
                write_file( iFile, iFileText )
        }*/
       
        
formatexg_MusicPlayercharsmaxg_MusicPlayer ), "%s/%s"iConfigDir"AdvMusicPlayer.html" ); //iLen = 0
        
SongCount 1;

        new 
szText1024 ], LineLength;
        while( 
read_fileiFileLine++, szTextcharsmaxszText ), Length ) )
        {
                
trimszText )
                if( !
Length || szText] == ';' )
                        continue;
               
                if( 
SongCount MaxSongs )
                        break;
                       
                static 
Left35 ], Right512 ]
                
parseszTextLeftcharsmaxLeft ), RightcharsmaxRight ) )
               
                
parseLeftcharsmaxLeft ), "^"", "" )
                parse( Right, charsmax( Right), "
^"""" )
                
parseRightcharsmaxRight ), " ""%20" )
               
                
copyg_Song_NamesSongCount ], charsmaxg_Song_Names[ ] ), Left )
                
copyg_Song_LinksSongCount ], charsmaxg_Song_Links[ ] ), Right )
                
SongCount++
        }
}

register_dictionary_colored( const iFile[ ] ) 
{
        if( !
register_dictionaryiFile ) ) 
                return 
0;
    
        new 
iLangDir128 ];
        
get_localinfo"amxx_datadir"iLangDircharsmaxiLangDir ) )
        
formatexiLangDircharsmaxiLangDir ), "%s/lang/%s"iLangDiriFile )

        new 
FileP fopeniLangDir"rt" );
    
        if( !
FileP 
        {
                
log_amx"Failed to open: %s"iLangDir );
        
                return 
0;
        }
    
        new 
szBuffer512 ], szLang], szKey64 ], szTranslation256 ], TransKey:iKey;
    
        while( !
feofFileP ) ) 
        {
                
fgetsFilePszBuffer511 );
        
                if( 
szBuffer] == '[' 
                {
                        
strtokszBuffer], szLang2szBuffer1']' );
                } 
                else if( 
szBuffer] ) 
                {
                        
strbreakszBufferszKey63szTranslation255 );
                        
iKey GetLangTransKeyszKey );
            
                        if( 
iKey != TransKey_Bad 
                        {
                                
replace_allszTranslation255"!g""^4" );
                                
replace_allszTranslation255"!t""^3" );
                                
replace_allszTranslation255"!n""^1" );
                
                                
AddTranslationszLangiKeyszTranslation] );
                        }
                }
        }
    
        
fcloseFileP );
    
        return 
1;
}

client_print_color(idColor:type, const msg[], {Float,Sql,Result,_}:...) 
{
    static 
SayText;

    if(!
SayText)
        
SayText get_user_msgid("SayText");

    static 
message[256];

    switch(
type)
    {
        case 
GREEN// Green
        
{
            
message[0] = 0x04;
        }
        case 
TEAM_COLOR// Team Color. Ie. Red (Terrorist) or blue (Counter-Terrorist).
        
{
            
message[0] = 0x03;
        }
        default: 
// Yellow.
        
{

            
message[0] = 0x01;
        }
    }

    
vformat(message[1], 251msg4);

    
message[192] = '^0';

    if(
id)
    {
        if(
is_user_connected(id))
        {
            
message_begin(MSG_ONESayText, {000}, id);
            
write_byte(id);
            
write_string(message);
            
message_end();
        }
    } else {
        static 
players[32]; new countindex;
        
get_players(playerscount);

        for(new 
0counti++)
        {
            
index players[i];

            
message_begin(MSG_ONESayText, {000}, index);
            
write_byte(index);
            
write_string(message);
            
message_end();

        }
    }


Also Array by connor he gave me lol: https://forums.alliedmods.net/showthread.php?t=236414

YamiKaitou 03-04-2014 17:05

Re: Cells And Array Errors [ Wrong? ]
 
Code:

new g_Song_Names[ MaxSongs ][ 64 ];
new g_Song_Links[ MaxSongs ][ 512 ];

MaxSongs is undefined at this point. Either define it or hardcode a value there

Code:

new Array:MaxSongs;
Just to point out in the previous block, this variable cannot define a size for g_Song_Names or g_Song_Links. Also, the array is never used after you create it (though the places you do use it, you use it incorrectly)...

Code:

MaxSongs = ArrayCreate( x );
You didn't define x

Baws 03-04-2014 17:09

Re: Cells And Array Errors [ Wrong? ]
 
So i will do #define MaxSongs 5000 and it should be okay?

And i thought that x was infiinite. I want do this: Using such max songs value is inappropriate, for such use, dynamic array should be considered (cellarray.inc, celltrie.inc)

YamiKaitou 03-04-2014 17:12

Re: Cells And Array Errors [ Wrong? ]
 
If you want to use CellArrays, you are going to need to do a lot more work than what you have done already. There should be a tutorial or something that explains how to use them

Baws 03-04-2014 17:15

Re: Cells And Array Errors [ Wrong? ]
 
I searched for it but didn't find it :/

YamiKaitou 03-04-2014 17:26

Re: Cells And Array Errors [ Wrong? ]
 
Looks like you are right, but there are threads out there with examples/usage and then there is the include file as well

Baws 03-04-2014 17:30

Re: Cells And Array Errors [ Wrong? ]
 
can you give me an example on how to use it?

YamiKaitou 03-04-2014 17:31

Re: Cells And Array Errors [ Wrong? ]
 
Take a look at AMX_Super Menu, I use it in there


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

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