Raised This Month: $32 Target: $400
 8% 

Solved Dynamic Array


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
soumyadip77
Senior Member
Join Date: Jul 2017
Location: INDIA,KOLKATA
Old 08-15-2018 , 11:28   Dynamic Array
Reply With Quote #1

i want to store song path and song from ini file play when i want. Me tried to make helped taken from ZE 2.5. But it is not working plz some one fix this plzzz her eis code and ini and error

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

#include <amxmodx>
#include <amxmisc>
// #include <cstrike>
// #include <engine>
// #include <fakemeta>
// #include <hamsandwich>
// #include <fun>
// #include <xs>
// #include <sqlx>

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

#define CONFIG_FILE "song.ini"

new Array: ready_sound

public plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("say /t1""play")
}

public 
plugin_precache()
{
    
ready_sound ArrayCreate(641)

    new 
ibuffer[128], temp_string[256]

    for(
0ArraySize(ready_sound); i++)
    {
        
ArrayGetString(ready_sounditemp_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))
    {
        new 
error[100]
        
formatex(errorcharsmax(error), "error")
        
set_fail_state(error)
        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))
        
        
// Replace newlines with a null character to prevent headaches
        
replace(linedatacharsmax(linedata), "^n""")
        
        
// 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)
            }
        }
    }
}

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

    
PlaySound(0temp_string)
}

stock PlaySound(id, const sound[])
{
    if(
id == 0)
    {
        if (
equal(sound[strlen(sound)-4], ".mp3"))
            
client_cmd(0"mp3 play ^"sound/%s^""sound)
        else
            
client_cmd(0"spk ^"%s^""sound)
        } else {
        if(
is_user_connected(id)&& is_user_alive(id))
        {
            if (
equal(sound[strlen(sound)-4], ".mp3"))
                
client_cmd(id"mp3 play ^"sound/%s^""sound)
            else
                
client_cmd(id"spk ^"%s^""sound)            
        }
    }

PHP Code:
L 08/11/2018 11:19:43Start of error session.
L 08/11/2018 11:19:43Info (map "de_dust2") (file "addons/amxmodx/logs/error_20180811.log")
L 08/11/2018 11:19:43Invalid array handle provided (0)
L 08/11/2018 11:19:43: [AMXXDisplaying debug trace (plugin "Dynamic_array.amxx"version "unknown")
L 08/11/2018 11:19:43: [AMXXRun time error 10native error (native "ArrayPushString")
L 08/11/2018 11:19:43: [AMXX]    [0Dynamic_array.sma::load_config_file (line 97)
L 08/11/2018 11:19:43: [AMXX]    [1Dynamic_array.sma::plugin_precache (line 34)
L 08/11/2018 11:39:57Start of error session.
L 08/11/2018 11:39:57Info (map "de_airstrip") (file "addons/amxmodx/logs/error_20180811.log")
L 08/11/2018 11:39:57Invalid array handle provided (0)
L 08/11/2018 11:39:57: [AMXXDisplaying debug trace (plugin "Dynamic_array.amxx"version "unknown")
L 08/11/2018 11:39:57: [AMXXRun time error 10native error (native "ArrayPushString")
L 08/11/2018 11:39:57: [AMXX]    [0Dynamic_array.sma::load_config_file (line 97)
L 08/11/2018 11:39:57: [AMXX]    [1Dynamic_array.sma::plugin_precache (line 34)
L 08/11/2018 12:00:02Start of error session.
L 08/11/2018 12:00:02Info (map "cs_havana") (file "addons/amxmodx/logs/error_20180811.log")
L 08/11/2018 12:00:02Invalid array handle provided (0)
L 08/11/2018 12:00:02: [AMXXDisplaying debug trace (plugin "Dynamic_array.amxx"version "unknown")
L 08/11/2018 12:00:02: [AMXXRun time error 10native error (native "ArrayPushString")
L 08/11/2018 12:00:02: [AMXX]    [0Dynamic_array.sma::load_config_file (line 97)
L 08/11/2018 12:00:02: [AMXX]    [1Dynamic_array.sma::plugin_precache (line 34
PHP Code:
START sound/enf_misc2/enf_knife_4.mp3 

Last edited by soumyadip77; 08-15-2018 at 23:20. Reason: php tag
soumyadip77 is offline
Send a message via Skype™ to soumyadip77
Ghosted
Veteran Member
Join Date: Apr 2015
Location: Georgia
Old 08-15-2018 , 12:22   Re: Dynamic Array
Reply With Quote #2

load_config_file is not even executed from the code. But i think one from array functions (ArrayPushString, ArrayGetString etc..) is called before ArrayCreate
__________________

[MOD] CS Weapon Mod V1.7.1
[MM] MetaMod-C V1.0
[MOD] CS NPC Mod (5%)


Probably Left AM

Last edited by Ghosted; 08-15-2018 at 12:23.
Ghosted is offline
soumyadip77
Senior Member
Join Date: Jul 2017
Location: INDIA,KOLKATA
Old 08-15-2018 , 21:24   Re: Dynamic Array
Reply With Quote #3

if u can plz fix it beq i am not pro in this Dynamic Array and file system
soumyadip77 is offline
Send a message via Skype™ to soumyadip77
soumyadip77
Senior Member
Join Date: Jul 2017
Location: INDIA,KOLKATA
Old 08-15-2018 , 22:33   Re: Dynamic Array
Reply With Quote #4

here i tried 1 more time and still error some one help
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;

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)

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

public 
plugin_precache()
{
    
ready_sound ArrayCreate(641)

    new 
ibuffer[128], temp_string[256]

    for(
0ArraySize(ready_sound); i++)
    {
        
ArrayGetString(ready_sounditemp_stringsizeof(temp_string))

        
format(buffercharsmax(buffer), "sound/%s"temp_string)
        
precache_generic(buffer)

    }
}

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

        
// 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)
            }
        }
    }
}

public 
play()
{
    static 
temp_string[128]
    
ArrayGetString(ready_soundArraySize(ready_sound), temp_stringsizeof(temp_string))

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

    
client_cmd(0"mp3 play ^"sound/%s^""temp_string)
}

public 
plugin_end()
{
    
ArrayDestroy(ready_sound);

PHP Code:
L 08/16/2018 08:02:32Start of error session.
L 08/16/2018 08:02:32Info (map "de_dust2") (file "addons/amxmodx/logs/error_20180816.log")
L 08/16/2018 08:02:32Invalid index 0 (count0)
L 08/16/2018 08:02:32: [AMXXDisplaying debug trace (plugin "test_array.amxx"version "1.0")
L 08/16/2018 08:02:32: [AMXXRun time error 10native error (native "ArrayGetString")
L 08/16/2018 08:02:32: [AMXX]    [0test_array.sma::play (line 91
soumyadip77 is offline
Send a message via Skype™ to soumyadip77
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
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 02:05.


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