AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Select/Copy random maps from a file (https://forums.alliedmods.net/showthread.php?t=187917)

dFF 06-19-2012 17:13

Select/Copy random maps from a file
 
I have this code
PHP Code:

LoadMapFile( const szFile[] )
{
    new 
szBuffer256 ], iFile
    
    iFile 
fopenszFile"rt" )
    
    new 
iVoteMapCount
    
    
while( iVoteMapCount MAX_VOTE_MAPS && !feofiFile ) && fgetsiFileszBuffercharsmaxszBuffer ) ) )
    {
        
trimszBuffer )
        
        if( ( ( 
szBuffer] == '^0' ) || ( szBuffer] == '/' ) || ( szBuffer] == ';' ) ) || !is_map_validszBuffer ) ) 
            continue
        
        
copyg_szVoteMapsiVoteMapCount ], charsmaxg_szVoteMaps[] ), szBuffer )
        
        
g_iMapVotesiVoteMapCount ][ e_MapIndex ] = iVoteMapCount++
        
        
menu_additemg_iVoteMenuszBuffer )
    }
    
    
fcloseiFile )


How to add (menu: copy( g_szVoteMaps .. ) | id: g_iMapVotes[ iVoteMapCount ][ e_MapIndex ]) to select random maps from a file (szFile[]) ?

Like: g_iMapVotes[ iVoteMapCount ][ e_MapIndex ] = random_num( 0, iVoteMapCount++ - 1 ), but I don't know how to update the right name in a menu (menu: copy( g_szVoteMaps .. ).

Exolent[jNr] 06-19-2012 18:00

Re: Select/Copy random maps from a file
 
PHP Code:

LoadMapFile( const szFile[] )
{
    new 
szBuffer256 ], iFile
    
    iFile 
fopenszFile"rt" )
    
    new Array:
aMaps ArrayCreatesizeofg_szVoteMaps[ ] ) );
    
    new 
iVoteMapCount
    
    
while( !feofiFile ) && fgetsiFileszBuffercharsmaxszBuffer ) ) )
    {
        
trimszBuffer )
        
        if( ( ( 
szBuffer] == '^0' ) || ( szBuffer] == '/' ) || ( szBuffer] == ';' ) ) || !is_map_validszBuffer ) ) 
            continue
        
        
ArrayPushStringaMapsszBuffer )
        
        
iVoteMapCount++
    }
    
    
fcloseiFile )
    
    new 
iAddediIndex;
    
    while( 
iAdded MAX_VOTE_MAPS && iVoteMapCount )
    {
        
iIndex randomiVoteMapCount-- );
        
        
ArrayGetStringaMapsiIndexszBuffercharsmaxszBuffer ) );
        
        
copyg_szVoteMapsiAdded ], charsmaxg_szVoteMaps[ ] ), szBuffer );
        
        
g_iMapVotesiAdded ][ e_MapIndex ] = iAdded++
        
        
menu_additemg_iVoteMenuszBuffer )
        
        
ArrayDeleteItemaMapsiIndex );
    }
    
    
ArrayDestroyaMaps );



dFF 06-20-2012 01:50

Re: Select/Copy random maps from a file
 
Thanks for reply! But there are some problems:
a. To prevent compile error change
PHP Code:

ArrayDeleteItemiIndex ); 

to
PHP Code:

ArrayDeleteItemaMapsiIndex ); 

b. In menu is count over MAX_VOTE_MAPS (MAX_VOTE_MAPS = 5)
I added in
PHP Code:

while( iAdded MAX_VOTE_MAPS && iVoteMapCount 

next debug:
PHP Code:

after "menu_additem( g_iVoteMenu, szText )" I add:
server_print"%d. %s (%d)"iAddedg_szVoteMapsiAdded ], iIndex 

and the result:
Code:

1.  (0)
2.  (0)
3.  (2)
4.  (0)
5.  (0)
1. cs_backalley (3)
2. de_airstrip (3)
3. cs_militia (2)
4. cs_office (0)
5.  (0)

the id (iIndex) is wrong. When vote in end, plugin will say error on g_szVoteMaps with rong ID.

ConnorMcLeod 06-20-2012 02:08

Re: Select/Copy random maps from a file
 
Show g_szVoteMaps declaration.

dFF 06-20-2012 02:09

Re: Select/Copy random maps from a file
 
PHP Code:

enum _:eMapInfo
{
    
e_MapIndex,
    
e_MapVotes
}

#define MAX_VOTE_LENGHT 50

new g_szVoteMapsMAX_VOTE_LENGHT ][ 33 ]
new 
g_iMapVotesMAX_VOTE_LENGHT ][ eMapInfo 


ConnorMcLeod 06-20-2012 02:39

Re: Select/Copy random maps from a file
 
Try to log szBuffer after trim() and at ArrayPushString( aMaps, szBuffer ).
Try to put fgets( iFile, szBuffer, charsmax( szBuffer ) ) inside the block.

dFF 06-20-2012 03:02

Re: Select/Copy random maps from a file
 
Thank you, Thanks Exolent :mrgreen: !


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

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