Raised This Month: $ Target: $400
 0% 

Select/Copy random maps from a file


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
dFF
sıɹɹoɥɔ ʞɔnu
Join Date: Oct 2009
Old 06-19-2012 , 17:13   Select/Copy random maps from a file
Reply With Quote #1

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 .. ).

Last edited by dFF; 06-19-2012 at 17:14.
dFF is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 06-19-2012 , 18:00   Re: Select/Copy random maps from a file
Reply With Quote #2

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 );

__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!

Last edited by Exolent[jNr]; 06-20-2012 at 09:36.
Exolent[jNr] is offline
dFF
sıɹɹoɥɔ ʞɔnu
Join Date: Oct 2009
Old 06-20-2012 , 01:50   Re: Select/Copy random maps from a file
Reply With Quote #3

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.

Last edited by dFF; 06-20-2012 at 01:51.
dFF is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 06-20-2012 , 02:08   Re: Select/Copy random maps from a file
Reply With Quote #4

Show g_szVoteMaps declaration.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
dFF
sıɹɹoɥɔ ʞɔnu
Join Date: Oct 2009
Old 06-20-2012 , 02:09   Re: Select/Copy random maps from a file
Reply With Quote #5

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 

Last edited by dFF; 06-20-2012 at 02:11.
dFF is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 06-20-2012 , 02:39   Re: Select/Copy random maps from a file
Reply With Quote #6

Try to log szBuffer after trim() and at ArrayPushString( aMaps, szBuffer ).
Try to put fgets( iFile, szBuffer, charsmax( szBuffer ) ) inside the block.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
dFF
sıɹɹoɥɔ ʞɔnu
Join Date: Oct 2009
Old 06-20-2012 , 03:02   Re: Select/Copy random maps from a file
Reply With Quote #7

Thank you, Thanks Exolent !

Last edited by dFF; 06-20-2012 at 03:16.
dFF is offline
Reply


Thread Tools
Display Modes

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 06:16.


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