Thread: [Solved] Dynamic Array
View Single Post
soumyadip77
Senior Member
Join Date: Jul 2017
Location: INDIA,KOLKATA
Old 08-15-2018 , 23:19   Re: Dynamic Array
Reply With Quote #5

prob solved here is code if any one need he will use

PHP Code:
/* Sublime AMXX Editor v2.2 */

#include <amxmodx>
#include <amxmisc>


#define PLUGIN  "New Plug-In"
#define VERSION "1.0"
#define AUTHOR  "Author"

#define CONFIG_FILE "song.ini"

new Array: ready_sound;
new Array: 
sound1;

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)

    
register_clcmd("say /t1""play")
    
register_clcmd("say /t2""play2")
}

public 
plugin_precache()
{
    
ready_sound ArrayCreate(64);
    
sound1 ArrayCreate(64);

    
load_config_file();

    
precacheSound(ready_sound);
    
precacheSound(sound1);


}

precacheSound(array)
{
    new 
buffer[128], temp_string[256], i;

    for(
0ArraySize(array); i++)
    {
        
ArrayGetString(array, itemp_stringsizeof(temp_string))

        if(
equal(temp_string[strlen(temp_string) - 4], ".mp3"))
        {
            
format(buffercharsmax(buffer), "sound/%s"temp_string)
            
precache_generic(buffer)
        }
        else
        {
            
precache_sound(temp_string)
        }
    }
}

public 
load_config_file()
{
    
// Build customization file path
    
new path[64]
    
get_configsdir(pathcharsmax(path))
    
format(pathcharsmax(path), "%s/%s"pathCONFIG_FILE)

    
// File not present
    
if (!file_exists(path))
    {
        return;
    }

    
// Set up some vars to hold parsing info
    
new linedata[1024], key[64], value[960]
    
// Open customization file for reading
    
new file fopen(path"rt")

    while (
file && !feof(file))
    {
        
// Read one line at a time
        
fgets(filelinedatacharsmax(linedata))
        
trim(linedata);

        
// Blank line or comment
        
if (!linedata[0] || linedata[0] == ';') continue;

        
// Get key and value(s)
        
strtok(linedatakeycharsmax(key), valuecharsmax(value), '=')

        
// Trim spaces
        
trim(key)
        
trim(value)


        if (
equal(key"START"))
        {
            
// Parse weapons
            
while (value[0] != && strtok(valuekeycharsmax(key), valuecharsmax(value), ','))
            {
            
// Trim spaces
                
trim(key)
                
trim(value)

                
// Add to weapons array
                
ArrayPushString(ready_soundkey)
                
//precacheSound(key)
            
}
        }
        else if (
equal(key"STOP"))
        {
                
// Parse weapons
            
while (value[0] != && strtok(valuekeycharsmax(key), valuecharsmax(value), ','))
            {
                
// Trim spaces
                
trim(key)
                
trim(value)

                
// Add to weapons array
                
ArrayPushString(sound1key)
                
//precacheSound(key)
            
}
        }
    }
}

public 
play()
{
    if(
ArraySize(ready_sound))
    {
        new 
temp_string[128]
        
ArrayGetString(ready_soundrandom_num(0ArraySize(ready_sound) - 1), temp_stringsizeof(temp_string))

        
client_print(0print_chat"song path %s"temp_string)

        
play_sound(0temp_string)
    }
}

public 
play2()
{
    if(
ArraySize(sound1))
    {
        new 
temp_string[128]
        
ArrayGetString(sound1random_num(0ArraySize(sound1) - 1), temp_stringsizeof(temp_string))

        
client_print(0print_chat"song path %s"temp_string)

        
play_sound(0temp_string)
    }
}

play_sound(idszSound[])
{
    
client_cmd(id"%s ^"sound/%s^"", (equal(szSound[strlen(szSound) - 4], ".mp3")) ? "mp3 play" "spk"szSound);
}

public 
plugin_end()
{
    
ArrayDestroy(ready_sound);
    
ArrayDestroy(sound1)

soumyadip77 is offline
Send a message via Skype™ to soumyadip77