Raised This Month: $ Target: $400
 0% 

Need a simple example of random get 5 map from map.ini


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
GarbageBox
Senior Member
Join Date: Feb 2010
Old 08-06-2012 , 15:12   Need a simple example of random get 5 map from map.ini
Reply With Quote #1

When player say 'maps' then print out 5 random map's name from map.ini, anyone can help?
__________________
You can be a SUPER coder but you Haven't to say such as "stupid, etc." words to the others
GarbageBox is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 08-06-2012 , 16:12   Re: Need a simple example of random get 5 map from map.ini
Reply With Quote #2

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

Last edited by Exolent[jNr]; 08-06-2012 at 16:42.
Exolent[jNr] is offline
GarbageBox
Senior Member
Join Date: Feb 2010
Old 08-06-2012 , 16:23   Re: Need a simple example of random get 5 map from map.ini
Reply With Quote #3

It show couldn't load any maps but I have maps.ini in my configs dir.
__________________
You can be a SUPER coder but you Haven't to say such as "stupid, etc." words to the others
GarbageBox is offline
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 08-06-2012 , 16:30   Re: Need a simple example of random get 5 map from map.ini
Reply With Quote #4

Untested:

PHP Code:

    
#include <amxmodx>
    #include <amxmisc>
    
    // How many maps you want displayed to the player
    #define MAPS_TO_SHOW 5
    
    // Array to hold maps found in file
    
new Array:g_aMapList:
    
    public 
plugin_init()
    {
        
register_plugin"Display 5 Maps""1.0""H3avY Ra1n" );
        
        
// Register command for when they say 'maps'
        
register_clcmd"say maps""cmdShowMaps" );
        
        
// Initialize the array
        
g_aMapList ArrayCreate64 );
        
        
// call function to read maps from the file
        
readMapsFromFile();
    }
    
    public 
cmdShowMapsid )
    {
        
// if size of array is 0 either no maps were loaded or the map file couldn't be found
        
if( ArraySizeg_aMapList ) == )
        {
            
client_printidprint_chat"No maps to show." );
        }
        
        else
        {
            
// Create a temporary array with the same values that are in the global arra
            
new Array:aTemp g_aMapList;
            
            
// String to hold what we're going to display to the user
            
new szMapList256 ];
            
            
// String to hold individual maps pulled from the array
            
new szMap32 ];
            
            
// Integer to hold a random number
            
new iRand;
            
            
// Loop from 0 to the amount of maps we want to show
            
for( new 0MAPS_TO_SHOWi++ )
            {
                
// Get a random index of the array
                
iRand randomArraySizeaTemp ) );
                
                
// Get the string that is in that index and put it in szMap
                
ArrayGetStringaTempiRandszMapcharsmaxszMap ) );
                
                
// Add szMap to the szMapList, which we are going to show to the player
                // The last parameter decides whether or not to put a comma at the end.
                
formatszMapListcharsmaxszMapList ), "%s %s%s "szMapListszMap== MAPS_TO_SHOW "" "," );
                
                
// Delete that item so it's not shown more than once.
                
ArrayDeleteItemaTempiRand );
                
            }
            
            
// Show szMapList to the player
            
client_printidprint_chatszMapList );
        }
        
    }
    
    
readMapsFromFile()
    {
        
// string for the directory of the maps file
        
new szDirectory128 ];
        
// gets the configs/ directory
        
get_configsdirszDirectorycharsmaxszDirectory ) );
        
        
// Find the maps.ini file
        
addszDirectorycharsmaxszDirectory ), "/maps.ini" );

        
// Open the file with read text permissions
        
new iFile fopenszDirectory"rt" );
        
        
// If file doesn't exist or couldn't open it
        
if( !iFile )
        {
            
// Stop the plugin
            
set_fail_state"Unable to read from file." );
            return;
        }
        
        
// String holder to hold maps found in the file.
        
new szMap32 ];
        
        
// While not at the end of the file
        
while( !feofiFile ) )
        {
            
// Get string from the file
            
fgetsiFileszMapcharsmaxszMap ) );
            
            
// Remove white space from the map name
            
trimszMap );
            
            
// Put that string in the array
            
ArrayPushStringg_aMapListszMap );
        }

        
fcloseiFile );
    } 
__________________
Quote:
Originally Posted by DarkGod View Post
nikhilgupta generates his plugins using sheer awesome.
If you like my work, please

Last edited by nikhilgupta345; 08-06-2012 at 16:32.
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 08-06-2012 , 16:43   Re: Need a simple example of random get 5 map from map.ini
Reply With Quote #5

Quote:
Originally Posted by GarbageBox View Post
It show couldn't load any maps but I have maps.ini in my configs dir.
Forgot to increase the total variable. Should work now.

Quote:
Originally Posted by nikhilgupta345 View Post
Untested:

PHP Code:
            // Create a temporary array with the same values that are in the global arra
            
new Array:aTemp g_aMapList
You can't copy dynamic arrays like that. It is just a reference to the global one.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
GarbageBox
Senior Member
Join Date: Feb 2010
Old 08-06-2012 , 17:04   Re: Need a simple example of random get 5 map from map.ini
Reply With Quote #6

Both of yours code are work too, thanks so much!
But nikhilgupta345's code will read ';' and the stuff at back and Exolent's code won't.
__________________
You can be a SUPER coder but you Haven't to say such as "stupid, etc." words to the others
GarbageBox is offline
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 08-06-2012 , 17:19   Re: Need a simple example of random get 5 map from map.ini
Reply With Quote #7

Quote:
Originally Posted by Exolent[jNr] View Post
Forgot to increase the total variable. Should work now.



You can't copy dynamic arrays like that. It is just a reference to the global one.
I thought things in Pawn were copied by-value unless specifically told otherwise?
__________________
Quote:
Originally Posted by DarkGod View Post
nikhilgupta generates his plugins using sheer awesome.
If you like my work, please
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 08-06-2012 , 19:52   Re: Need a simple example of random get 5 map from map.ini
Reply With Quote #8

Quote:
Originally Posted by nikhilgupta345 View Post
I thought things in Pawn were copied by-value unless specifically told otherwise?
Yes, but a value of a dynamic array is a handle.
All of the data is stored into the modules.
Therefore, you are copying the handle value, instead of referencing that handle variable you made.
Either way, it is the same exact dynamic array.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 08-06-2012 , 20:29   Re: Need a simple example of random get 5 map from map.ini
Reply With Quote #9

Quote:
Originally Posted by Exolent[jNr] View Post
Yes, but a value of a dynamic array is a handle.
All of the data is stored into the modules.
Therefore, you are copying the handle value, instead of referencing that handle variable you made.
Either way, it is the same exact dynamic array.
Oh, makes sense. I couldn't find any ArrayCopy methods or anything, so is there another way to copy an array without looping through all the elements and putting it in a brand new array?
__________________
Quote:
Originally Posted by DarkGod View Post
nikhilgupta generates his plugins using sheer awesome.
If you like my work, please
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 08-06-2012 , 20:46   Re: Need a simple example of random get 5 map from map.ini
Reply With Quote #10

Quote:
Originally Posted by nikhilgupta345 View Post
Oh, makes sense. I couldn't find any ArrayCopy methods or anything, so is there another way to copy an array without looping through all the elements and putting it in a brand new array?
Nothing that exists. Though it would be more efficient to do it in a module.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] 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 01:32.


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