Raised This Month: $51 Target: $400
 12% 

file in .ini mode


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
yagami
Senior Member
Join Date: Jan 2021
Old 07-16-2023 , 13:04   file in .ini mode
Reply With Quote #1

How do I put these models, sounds, sprites in an .ini file?

PHP Code:
new g_DispActive[] = "teste/dispenser_generate_metal.wav"
new g_DispSndFail[] = "teste/dispenser_fail.wav"
new g_DispSndDestroy[] = "teste/dispenser_explode.wav"
new g_DispSndIdle[] = "teste/dispenser_idle.wav"

new g_DispModelPrint[] = "models/teste/dispenser_blueprint.mdl"
new g_DispModel[] = "models/teste/new_dispenser.mdl"
new g_DispModelVip[] = "models/teste/dispenser_free.mdl"
new g_DispModelGibsR[] = "models/teste/dispenser_gibs_r.mdl"
new g_DispModelGibsB[] = "models/teste/dispenser_gibs_b.mdl"
new g_DispSprSmoke[] = "sprites/teste/dispenser_smoke.spr"
new g_DispSprHealLifeB[] = "sprites/teste/healbeam_blue.spr"
new g_DispSprHealLifeR[] = "sprites/teste/healbeam_red.spr"

public plugin_precache()
{
    
g_PrecSprFlare3 precache_model("sprites/flare3.spr")
    
g_PrecSprLife precache_model("sprites/teste/dispenser1.spr")
    
    
g_PrecSprSmoke precache_model(g_DispSprSmoke)
    
g_PrecSprHealLifeB precache_model(g_DispSprHealLifeB)
    
g_PrecSprHealLifeR precache_model(g_DispSprHealLifeR)
    
g_PrecDispModelGibsR precache_model(g_DispModelGibsR)
    
g_PrecDispModelGibsB precache_model(g_DispModelGibsB)
    
xModelIndex[0] = precache_model(g_DispModelVip)
    
xModelIndex[1] = precache_model(g_DispModel)

    
precache_model(g_DispModelPrint)
    
precache_model(g_DispModel)
    
precache_model(g_DispModelVip)
    
precache_sound(g_DispActive)
    
precache_sound(g_DispSndFail)
    
precache_sound(g_DispSndDestroy)
    
precache_sound(g_DispSndIdle)

    static 
i
    
for(0sizeof(g_DamageSounds);i++) 
        
engfunc(EngFunc_PrecacheSoundg_DamageSounds[i])

    for(
0sizeof(xBulletsSounds);i++) 
        
engfunc(EngFunc_PrecacheSoundxBulletsSounds[i])

yagami is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-16-2023 , 17:06   Re: file in .ini mode
Reply With Quote #2

This can be done fairly simply. Read the file (using fopen, fgets, fclose). You should be able to find other plugins that use these file functions for an example.

You can parse each line with argparse() like this:

PHP Code:
    new pos
    pos 
argparse(szDataposszVariableNamecharsmax(szVariableName))
    
argparse(szDataposszPathcharsmax(szPath)) 
and then you'll use a series of if else if conditions to be able to assign the path to the variable:

PHP Code:
    if( equal(szVariableName"DispActive") )
    {
        
copy(g_DispActivecharsmax(g_DispActive), szPath)
    }
    else if( 
equal(szVariableName"DispSndFail") )
    {
        
copy(DispSndFailcharsmax(DispSndFail), szPath)
    }
    else if( 
/* and so on */
And your file could look something like this:
Code:
"DispActive" "teste/dispenser_generate_metal.wav" 
"DispSndFail" "teste/dispenser_fail.wav"
...
__________________
fysiks is offline
yagami
Senior Member
Join Date: Jan 2021
Old 07-16-2023 , 18:22   Re: file in .ini mode
Reply With Quote #3

Quote:
Originally Posted by fysiks View Post
This can be done fairly simply. Read the file (using fopen, fgets, fclose). You should be able to find other plugins that use these file functions for an example.

You can parse each line with argparse() like this:

PHP Code:
    new pos
    pos 
argparse(szDataposszVariableNamecharsmax(szVariableName))
    
argparse(szDataposszPathcharsmax(szPath)) 
and then you'll use a series of if else if conditions to be able to assign the path to the variable:

PHP Code:
    if( equal(szVariableName"DispActive") )
    {
        
copy(g_DispActivecharsmax(g_DispActive), szPath)
    }
    else if( 
equal(szVariableName"DispSndFail") )
    {
        
copy(DispSndFailcharsmax(DispSndFail), szPath)
    }
    else if( 
/* and so on */
And your file could look something like this:
Code:
"DispActive" "teste/dispenser_generate_metal.wav" 
"DispSndFail" "teste/dispenser_fail.wav"
...
I almost had a heart attack and couldn't understand anything researching about it
yagami is offline
lexzor
Veteran Member
Join Date: Nov 2020
Old 07-17-2023 , 07:14   Re: file in .ini mode
Reply With Quote #4

using the file format that fysiks used

PHP Code:
#include <amxmodx>
#include <amxconst>

new g_DispActive[128]
new 
g_DispSndFail[128]
new 
g_DispSndDestroy[128]
new 
g_DispSndIdle[128]
new 
g_DispModelPrint[128]
new 
g_DispModel[128]
new 
g_DispModelVip[128]
new 
g_DispModelGibsR[128]
new 
g_DispModelGibsB[128]
new 
g_DispSprSmoke[128]
new 
g_DispSprHealLifeB[128]
new 
g_DispSprHealLifeR[128]


public 
plugin_precache()
{
    new 
iFile fopen("path/to/file.ini""r")

    if(!
iFile)
    {
        
// file failed to be opened: doesn't exist or another cause
        
return
    }

    new 
szLine[256], szVariableIndentifier[128], szModelPath[128]

    while(
fgets(iFileszLinecharsmax(szLine))) //while can read
    
{
//check if: line is empty || line is commented
        
if(szLine[0] == EOS || szLine[0] == ';')
        {
            continue; 
// continue reading, don't parse this line
        
}

        
parse(szLineszVariableIndentifiercharsmax(szVariableIndentifier), szModelPathcharsmax(szModelPath)) // parse line looking like: "variable_name" "path_to_model"

        
if(equal(szVariableIndentifier"g_DispActive")) // checking if the variable name from the file correspond with one of the variables
        
{
            if(
file_exists(szModelPath)) // check if model exists
            
{
                
precache_model(szModelPath)// precache it
                
copy(g_DispActivecharsmax(g_DispActive), szModelPath//copy the model to the variable so you can use it later in the plugin
            
}
            else 
            {
                
log_error(AMX_ERR_NOTFOUND"File %s does not exists"szModelPath// log an error if model path is incorrect or file doesn't exists
            
}
        }
        else if(
equal(szVariableIndentifier"g_DispSndFail"))
        {
            if(
file_exists(szModelPath))
            {
                
precache_model(szModelPath)
                
copy(g_DispSndFailcharsmax(g_DispSndFail), szModelPath)
            }
            else 
            {
                
log_error(AMX_ERR_NOTFOUND"File %s does not exists"szModelPath)
            }
        }
        else if()
///do this for every variable
        
{
            
//...
        
}
        else 
//add this in case the a variable name doesn't correspond with existing one 
        
{
            
log_error(AMX_ERR_NOTFOUND"Varibale name %s does not exists"szVariableIndentifier)
        }
    }


Last edited by lexzor; 07-17-2023 at 07:15.
lexzor is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 07-17-2023 , 14:15   Re: file in .ini mode
Reply With Quote #5

There you can also use this func

PHP Code:
#define MAX_FILE_DIRECTORY_LEN 64

#define INVALID_CATEGORY -1
#define INVALID_KEY -1
#define INVALID_LINE -1

enum (+=1) {
    
FILE_ERROR 0,
    
FILE_CATEGORY_CREATED,
    
FILE_KEYVALUE_BUFFERED,
    
FILE_KEYVALUE_UPDATED,
    
FILE_KEYVALUE_CREATED,
    
FILE_KEYVALUE_EMPTY
}

new const 
CONFIGS_DIR[] = "addons/amxmodx/configs";

get_file_keyvalue(const file[], const cata[], const key[], value[], len=0)
{
    static 
sFile[MAX_FILE_DIRECTORY_LEN], fp;
    
formatex(sFilecharsmax(sFile), "%s/%s"CONFIGS_DIRfile);
    
    
fp fopen(sFile"at+");
    
    if(!
fp)
    {
        
set_fail_state("Error opening the file!");
        return 
0;
    }
    
    static 
sBuffer[256], szCata[64], szKey[64], key_foundcata_foundlinebool:keyvalue_update;
    
key_found INVALID_KEY;
    
cata_found INVALID_CATEGORY;
    
line INVALID_LINE;
    
keyvalue_update false;
    
    
fseek(fp0SEEK_SET);
    while(!
feof(fp))
    {
        
line ++;
        
        
fgets(fpsBuffercharsmax(sBuffer));
        
trim(sBuffer);
        
        if(!
sBuffer[0] || strlen(sBuffer) <= || sBuffer[0] == ';' || (sBuffer[0] == '/' && sBuffer[1] == '/'))
            continue;
        
        if(
sBuffer[0] == '[' && contain(sBuffer[1], "]") > -1)
        {
            if(
cata_found != INVALID_CATEGORY)
            {
                break;
            }
            
            
copyc(szCatacharsmax(szCata), sBuffer[1], ']');
            
            if(
equali(szCatacata))
            {
                
cata_found line;
            }
            
            continue;
        }
        
        if(
cata_found != INVALID_CATEGORY && key_found == INVALID_KEY)
        {
            
strtok(sBufferszKeycharsmax(szKey), sBuffercharsmax(sBuffer), '=');
            
trim(szKey);
            
trim(sBuffer);
            
remove_quotes(szKey);
            
remove_quotes(sBuffer);
            
            if(
equali(szKeykey))
            {
                
key_found line;
                
                if(
sBuffer[0] == EOS)
                {
                    if(
value[0] != EOS)
                    {
                        
keyvalue_update true;
                        break;
                    }

                    
fclose(fp);
                    return 
FILE_KEYVALUE_EMPTY;
                }
                
                
copy(valuelensBuffer);

                
fclose(fp);
                return 
FILE_KEYVALUE_BUFFERED;
            }
        }
    }
    
    if(
cata_found == INVALID_CATEGORY)
    {
        
formatex(szCatacharsmax(szCata), "^n[%s]^n"cata);
        
fputs(fpszCata);
        
        
formatex(sBuffercharsmax(sBuffer), "%s = ^"%s^" ^n"keyvalue)
        
fputs(fpsBuffer);
    }
    
    else if((
cata_found != INVALID_CATEGORY && key_found == INVALID_KEY) || keyvalue_update == true)
    {
        static 
sFile2[128], fp2;
        
formatex(sFile2charsmax(sFile2), "%s/2_%s"CONFIGS_DIRfile);
        
        
fp2 fopen(sFile2"at+");
        
        if(!
fp2)
        {
            
set_fail_state("Error opening the file!");
            return 
0;
        }
        
        
line INVALID_LINE;
        
fseek(fp0SEEK_SET);
        while( !
feof(fp) )
        {
            
line ++;
            if(
fgets(fpsBuffercharsmax(sBuffer)) == 0) continue;
            
            if(
keyvalue_update == true)
            {
                if(
key_found == line)
                {
                    
formatex(sBuffercharsmax(sBuffer), "%s = ^"%s^" ^n"keyvalue)
                }
            }
            else if(
cata_found == line)
            {
                
formatex(szCatacharsmax(szCata), "[%s]^n"cata);
                
fputs(fp2szCata);
                
formatex(sBuffercharsmax(sBuffer), "%s = ^"%s^"^n"keyvalue)
            }
            
            
fputs(fp2sBuffer);
        }
        
fclose(fp);
        
fclose(fp2);
        
        
delete_file(sFile);
        if(!
rename_file(sFile2sFile,1))
        {
            
delete_file(sFile2);
            return 
FILE_ERROR;
        }

        return 
keyvalue_update FILE_KEYVALUE_UPDATED FILE_KEYVALUE_CREATED;
    }

    
fclose(fp);
    return 
FILE_CATEGORY_CREATED;

How to use ?
Simple...


Spoiler
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 07-17-2023 at 20:31.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
yagami
Senior Member
Join Date: Jan 2021
Old 07-17-2023 , 16:40   Re: file in .ini mode
Reply With Quote #6

Quote:
Originally Posted by lexzor View Post
using the file format that fysiks used

PHP Code:
#include <amxmodx>
#include <amxconst>

new g_DispActive[128]
new 
g_DispSndFail[128]
new 
g_DispSndDestroy[128]
new 
g_DispSndIdle[128]
new 
g_DispModelPrint[128]
new 
g_DispModel[128]
new 
g_DispModelVip[128]
new 
g_DispModelGibsR[128]
new 
g_DispModelGibsB[128]
new 
g_DispSprSmoke[128]
new 
g_DispSprHealLifeB[128]
new 
g_DispSprHealLifeR[128]


public 
plugin_precache()
{
    new 
iFile fopen("path/to/file.ini""r")

    if(!
iFile)
    {
        
// file failed to be opened: doesn't exist or another cause
        
return
    }

    new 
szLine[256], szVariableIndentifier[128], szModelPath[128]

    while(
fgets(iFileszLinecharsmax(szLine))) //while can read
    
{
//check if: line is empty || line is commented
        
if(szLine[0] == EOS || szLine[0] == ';')
        {
            continue; 
// continue reading, don't parse this line
        
}

        
parse(szLineszVariableIndentifiercharsmax(szVariableIndentifier), szModelPathcharsmax(szModelPath)) // parse line looking like: "variable_name" "path_to_model"

        
if(equal(szVariableIndentifier"g_DispActive")) // checking if the variable name from the file correspond with one of the variables
        
{
            if(
file_exists(szModelPath)) // check if model exists
            
{
                
precache_model(szModelPath)// precache it
                
copy(g_DispActivecharsmax(g_DispActive), szModelPath//copy the model to the variable so you can use it later in the plugin
            
}
            else 
            {
                
log_error(AMX_ERR_NOTFOUND"File %s does not exists"szModelPath// log an error if model path is incorrect or file doesn't exists
            
}
        }
        else if(
equal(szVariableIndentifier"g_DispSndFail"))
        {
            if(
file_exists(szModelPath))
            {
                
precache_model(szModelPath)
                
copy(g_DispSndFailcharsmax(g_DispSndFail), szModelPath)
            }
            else 
            {
                
log_error(AMX_ERR_NOTFOUND"File %s does not exists"szModelPath)
            }
        }
        else if()
///do this for every variable
        
{
            
//...
        
}
        else 
//add this in case the a variable name doesn't correspond with existing one 
        
{
            
log_error(AMX_ERR_NOTFOUND"Varibale name %s does not exists"szVariableIndentifier)
        }
    }

I'm studying everything but I got lost in some things
My precache was like this but I have a doubt what to do with g_DamageSounds, xBulletsSounds


PHP Code:
public plugin_precache()
{
    new 
iFile fopen("amxmodx/config/dispenser.ini""r")
    
    if(!
iFile)
    {
        return
    }
    
    new 
szLine[256], szVariableIndentifier[128], szModelPath[128]

    while(
fgets(iFileszLinecharsmax(szLine))) //while can read
    
{
        
//check if: line is empty || line is commented
        
if(szLine[0] == EOS || szLine[0] == ';')
        {
            continue; 
// continue reading, don't parse this line
        
}

        
parse(szLineszVariableIndentifiercharsmax(szVariableIndentifier), szModelPathcharsmax(szModelPath)) // parse line looking like: "variable_name" "path_to_model"

        
if(equal(szVariableIndentifier"g_DispActive")) // checking if the variable name from the file correspond with one of the variables
        
{
            if(
file_exists(szModelPath)) // check if model exists
            
{
                
precache_model(szModelPath)// precache it
                
copy(g_DispActivecharsmax(g_DispActive), szModelPath//copy the model to the variable so you can use it later in the plugin
            
}
            else 
            {
                
log_error(AMX_ERR_NOTFOUND"File %s does not exists"szModelPath// log an error if model path is incorrect or file doesn't exists
            
}
        }
        else if(
equal(szVariableIndentifier"g_DispSndFail"))
        {
            if(
file_exists(szModelPath))
            {
                
precache_model(szModelPath)
                
copy(g_DispSndFailcharsmax(g_DispSndFail), szModelPath)
            }
            else 
            {
                
log_error(AMX_ERR_NOTFOUND"File %s does not exists"szModelPath)
            }
        }
        else if(
equal(szVariableIndentifier"g_DispSndDestroy")) 
        {
            if(
file_exists(szModelPath))
            {
                
precache_model(szModelPath)
                
copy(g_DispSndDestroycharsmax(g_DispSndDestroy), szModelPath
            }
            else 
            {
                
log_error(AMX_ERR_NOTFOUND"File %s does not exists"szModelPath)
            }
        }
        else if(
equal(szVariableIndentifier"g_DispSndIdle")) 
        {
            if(
file_exists(szModelPath))
            {
                
precache_model(szModelPath)
                
copy(g_DispSndIdlecharsmax(g_DispSndIdle), szModelPath
            }
            else 
            {
                
log_error(AMX_ERR_NOTFOUND"File %s does not exists"szModelPath)
            }
        }
        else if(
equal(szVariableIndentifier"g_DispModelPrint")) 
        {
            if(
file_exists(szModelPath))
            {
                
precache_model(szModelPath)
                
copy(g_DispModelPrintcharsmax(g_DispModelPrint), szModelPath
            }
            else 
            {
                
log_error(AMX_ERR_NOTFOUND"File %s does not exists"szModelPath)
            }
        }

        else if(
equal(szVariableIndentifier"g_DispModel")) 
        {
            if(
file_exists(szModelPath))
            {
                
precache_model(szModelPath)
                
copy(g_DispModelcharsmax(g_DispModel), szModelPath
            }
            else 
            {
                
log_error(AMX_ERR_NOTFOUND"File %s does not exists"szModelPath)
            }
        }

        else if(
equal(szVariableIndentifier"g_DispModelVip")) 
        {
            if(
file_exists(szModelPath))
            {
                
precache_model(szModelPath)
                
copy(g_DispModelVipcharsmax(g_DispModelVip), szModelPath
            }
            else 
            {
                
log_error(AMX_ERR_NOTFOUND"File %s does not exists"szModelPath)
            }
        }

        else if(
equal(szVariableIndentifier"g_DispModelGibsR")) 
        {
            if(
file_exists(szModelPath))
            {
                
precache_model(szModelPath)
                
copy(g_DispModelGibsRcharsmax(g_DispModelGibsR), szModelPath
            }
            else 
            {
                
log_error(AMX_ERR_NOTFOUND"File %s does not exists"szModelPath)
            }
        }

        else if(
equal(szVariableIndentifier"g_DispModelGibsR"))
        {
            if(
file_exists(szModelPath))
            {
                
precache_model(szModelPath)
                
copy(g_DispModelGibsRcharsmax(g_DispModelGibsR), szModelPath
            }
            else 
            {
                
log_error(AMX_ERR_NOTFOUND"File %s does not exists"szModelPath)
            }
        }

        else if(
equal(szVariableIndentifier"g_DispModelGibsB")) 
        {
            if(
file_exists(szModelPath))
            {
                
precache_model(szModelPath)
                
copy(g_DispModelGibsBcharsmax(g_DispModelGibsB), szModelPath
            }
            else 
            {
                
log_error(AMX_ERR_NOTFOUND"File %s does not exists"szModelPath)
            }
        }

        else if(
equal(szVariableIndentifier"g_DispModelGibsB")) 
        {
            if(
file_exists(szModelPath))
            {
                
precache_model(szModelPath)
                
copy(g_DispModelGibsBcharsmax(g_DispModelGibsB), szModelPath
            }
            else 
            {
                
log_error(AMX_ERR_NOTFOUND"File %s does not exists"szModelPath)
            }
        }

        else if(
equal(szVariableIndentifier"g_DispSprSmoke")) 
        {
            if(
file_exists(szModelPath))
            {
                
precache_model(szModelPath)
                
copy(g_DispSprSmokecharsmax(g_DispSprSmoke), szModelPath
            }
            else 
            {
                
log_error(AMX_ERR_NOTFOUND"File %s does not exists"szModelPath)
            }
        }

        else if(
equal(szVariableIndentifier"g_DispSprHealLifeB"))
        {
            if(
file_exists(szModelPath))
            {
                
precache_model(szModelPath)
                
copy(g_DispSprHealLifeBcharsmax(g_DispSprHealLifeB), szModelPath
            }
            else 
            {
                
log_error(AMX_ERR_NOTFOUND"File %s does not exists"szModelPath)
            }
        }

        else if(
equal(szVariableIndentifier"g_DispSprHealLifeR"))
        {
            if(
file_exists(szModelPath))
            {
                
precache_model(szModelPath)
                
copy(g_DispSprHealLifeRcharsmax(g_DispSprHealLifeR), szModelPath
            }
            else 
            {
                
log_error(AMX_ERR_NOTFOUND"File %s does not exists"szModelPath)
            }
        }   
        else 
//add this in case the a variable name doesn't correspond with existing one 
        
{
            
log_error(AMX_ERR_NOTFOUND"Varibale name %s does not exists"szVariableIndentifier)
        }
    }

    
g_PrecSprFlare3 precache_model("sprites/flare3.spr")
    
g_PrecSprLife precache_model("sprites/teste/dispenser1.spr")
    
    
/*g_PrecSprSmoke = precache_model(g_DispSprSmoke)
    g_PrecSprHealLifeB = precache_model(g_DispSprHealLifeB)
    g_PrecSprHealLifeR = precache_model(g_DispSprHealLifeR)
    g_PrecDispModelGibsR = precache_model(g_DispModelGibsR)
    g_PrecDispModelGibsB = precache_model(g_DispModelGibsB)
    xModelIndex[0] = precache_model(g_DispModelVip)
    xModelIndex[1] = precache_model(g_DispModel)

    precache_model(g_DispModelPrint)
    precache_model(g_DispModel)
    precache_model(g_DispModelVip)
    precache_sound(g_DispActive)
    precache_sound(g_DispSndFail)
    precache_sound(g_DispSndDestroy)
    precache_sound(g_DispSndIdle)*/

    
static i
    
for(0sizeof(g_DamageSounds);i++) 
        
engfunc(EngFunc_PrecacheSoundg_DamageSounds[i])

    for(
0sizeof(xBulletsSounds);i++) 
        
engfunc(EngFunc_PrecacheSoundxBulletsSounds[i])


PHP Code:
write_short(g_PrecSprSmoke
New
PHP Code:
write_short(szModelPath
?
yagami is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-17-2023 , 23:39   Re: file in .ini mode
Reply With Quote #7

Quote:
Originally Posted by yagami View Post
I'm studying everything but I got lost in some things
My precache was like this


PHP Code:
public plugin_precache()
{
    new 
iFile fopen("amxmodx/config/dispenser.ini""r")
    
    if(!
iFile)
    {
        return
    }
    
    new 
szLine[256], szVariableIndentifier[128], szModelPath[128]

    while(
fgets(iFileszLinecharsmax(szLine))) //while can read
    
{
        
//check if: line is empty || line is commented
        
if(szLine[0] == EOS || szLine[0] == ';')
        {
            continue; 
// continue reading, don't parse this line
        
}

        
parse(szLineszVariableIndentifiercharsmax(szVariableIndentifier), szModelPathcharsmax(szModelPath)) // parse line looking like: "variable_name" "path_to_model"

        
if(equal(szVariableIndentifier"g_DispActive")) // checking if the variable name from the file correspond with one of the variables
        
{
            if(
file_exists(szModelPath)) // check if model exists
            
{
                
precache_model(szModelPath)// precache it
                
copy(g_DispActivecharsmax(g_DispActive), szModelPath//copy the model to the variable so you can use it later in the plugin
            
}
            else 
            {
                
log_error(AMX_ERR_NOTFOUND"File %s does not exists"szModelPath// log an error if model path is incorrect or file doesn't exists
            
}
        }
        else if(
equal(szVariableIndentifier"g_DispSndFail"))
        {
            if(
file_exists(szModelPath))
            {
                
precache_model(szModelPath)
                
copy(g_DispSndFailcharsmax(g_DispSndFail), szModelPath)
            }
            else 
            {
                
log_error(AMX_ERR_NOTFOUND"File %s does not exists"szModelPath)
            }
        }
        else if(
equal(szVariableIndentifier"g_DispSndDestroy")) 
        {
            if(
file_exists(szModelPath))
            {
                
precache_model(szModelPath)
                
copy(g_DispSndDestroycharsmax(g_DispSndDestroy), szModelPath
            }
            else 
            {
                
log_error(AMX_ERR_NOTFOUND"File %s does not exists"szModelPath)
            }
        }
        else if(
equal(szVariableIndentifier"g_DispSndIdle")) 
        {
            if(
file_exists(szModelPath))
            {
                
precache_model(szModelPath)
                
copy(g_DispSndIdlecharsmax(g_DispSndIdle), szModelPath
            }
            else 
            {
                
log_error(AMX_ERR_NOTFOUND"File %s does not exists"szModelPath)
            }
        }
        else if(
equal(szVariableIndentifier"g_DispModelPrint")) 
        {
            if(
file_exists(szModelPath))
            {
                
precache_model(szModelPath)
                
copy(g_DispModelPrintcharsmax(g_DispModelPrint), szModelPath
            }
            else 
            {
                
log_error(AMX_ERR_NOTFOUND"File %s does not exists"szModelPath)
            }
        }

        else if(
equal(szVariableIndentifier"g_DispModel")) 
        {
            if(
file_exists(szModelPath))
            {
                
precache_model(szModelPath)
                
copy(g_DispModelcharsmax(g_DispModel), szModelPath
            }
            else 
            {
                
log_error(AMX_ERR_NOTFOUND"File %s does not exists"szModelPath)
            }
        }

        else if(
equal(szVariableIndentifier"g_DispModelVip")) 
        {
            if(
file_exists(szModelPath))
            {
                
precache_model(szModelPath)
                
copy(g_DispModelVipcharsmax(g_DispModelVip), szModelPath
            }
            else 
            {
                
log_error(AMX_ERR_NOTFOUND"File %s does not exists"szModelPath)
            }
        }

        else if(
equal(szVariableIndentifier"g_DispModelGibsR")) 
        {
            if(
file_exists(szModelPath))
            {
                
precache_model(szModelPath)
                
copy(g_DispModelGibsRcharsmax(g_DispModelGibsR), szModelPath
            }
            else 
            {
                
log_error(AMX_ERR_NOTFOUND"File %s does not exists"szModelPath)
            }
        }

        else if(
equal(szVariableIndentifier"g_DispModelGibsR"))
        {
            if(
file_exists(szModelPath))
            {
                
precache_model(szModelPath)
                
copy(g_DispModelGibsRcharsmax(g_DispModelGibsR), szModelPath
            }
            else 
            {
                
log_error(AMX_ERR_NOTFOUND"File %s does not exists"szModelPath)
            }
        }

        else if(
equal(szVariableIndentifier"g_DispModelGibsB")) 
        {
            if(
file_exists(szModelPath))
            {
                
precache_model(szModelPath)
                
copy(g_DispModelGibsBcharsmax(g_DispModelGibsB), szModelPath
            }
            else 
            {
                
log_error(AMX_ERR_NOTFOUND"File %s does not exists"szModelPath)
            }
        }

        else if(
equal(szVariableIndentifier"g_DispModelGibsB")) 
        {
            if(
file_exists(szModelPath))
            {
                
precache_model(szModelPath)
                
copy(g_DispModelGibsBcharsmax(g_DispModelGibsB), szModelPath
            }
            else 
            {
                
log_error(AMX_ERR_NOTFOUND"File %s does not exists"szModelPath)
            }
        }

        else if(
equal(szVariableIndentifier"g_DispSprSmoke")) 
        {
            if(
file_exists(szModelPath))
            {
                
precache_model(szModelPath)
                
copy(g_DispSprSmokecharsmax(g_DispSprSmoke), szModelPath
            }
            else 
            {
                
log_error(AMX_ERR_NOTFOUND"File %s does not exists"szModelPath)
            }
        }

        else if(
equal(szVariableIndentifier"g_DispSprHealLifeB"))
        {
            if(
file_exists(szModelPath))
            {
                
precache_model(szModelPath)
                
copy(g_DispSprHealLifeBcharsmax(g_DispSprHealLifeB), szModelPath
            }
            else 
            {
                
log_error(AMX_ERR_NOTFOUND"File %s does not exists"szModelPath)
            }
        }

        else if(
equal(szVariableIndentifier"g_DispSprHealLifeR"))
        {
            if(
file_exists(szModelPath))
            {
                
precache_model(szModelPath)
                
copy(g_DispSprHealLifeRcharsmax(g_DispSprHealLifeR), szModelPath
            }
            else 
            {
                
log_error(AMX_ERR_NOTFOUND"File %s does not exists"szModelPath)
            }
        }   
        else 
//add this in case the a variable name doesn't correspond with existing one 
        
{
            
log_error(AMX_ERR_NOTFOUND"Varibale name %s does not exists"szVariableIndentifier)
        }
    }

    
g_PrecSprFlare3 precache_model("sprites/flare3.spr")
    
g_PrecSprLife precache_model("sprites/teste/dispenser1.spr")
    
    
/*g_PrecSprSmoke = precache_model(g_DispSprSmoke)
    g_PrecSprHealLifeB = precache_model(g_DispSprHealLifeB)
    g_PrecSprHealLifeR = precache_model(g_DispSprHealLifeR)
    g_PrecDispModelGibsR = precache_model(g_DispModelGibsR)
    g_PrecDispModelGibsB = precache_model(g_DispModelGibsB)
    xModelIndex[0] = precache_model(g_DispModelVip)
    xModelIndex[1] = precache_model(g_DispModel)

    precache_model(g_DispModelPrint)
    precache_model(g_DispModel)
    precache_model(g_DispModelVip)
    precache_sound(g_DispActive)
    precache_sound(g_DispSndFail)
    precache_sound(g_DispSndDestroy)
    precache_sound(g_DispSndIdle)*/

    
static i
    
for(0sizeof(g_DamageSounds);i++) 
        
engfunc(EngFunc_PrecacheSoundg_DamageSounds[i])

    for(
0sizeof(xBulletsSounds);i++) 
        
engfunc(EngFunc_PrecacheSoundxBulletsSounds[i])


If you hard code a path like that, you need to remember that the path is based on the root of the mod that you're running (cstrike, dod, etc.). So, in your case, you'd use "addons/amxmodx/configs/dispenser.ini". There is a programmatic way to get this directory with get_configsdir() but I'd leave that for later, after you get other things working.

Quote:
Originally Posted by yagami View Post
I have a doubt what to do with g_DamageSounds, xBulletsSounds
The code you provided doesn't include how those are defined so we didn't touch those variables. However, you could add them exactly the way we added them here except you'll populate the array and increment a counter to know where in the array to put them:

PHP Code:
        else if(equal(szVariableIndentifier"DamageSound"))
        {
            static 
DamageSoundCount
            
if( DamageSoundCount sizeof(g_DamageSounds) && file_exists(szModelPath) )
            {
                
copy(g_DamageSounds[DamageSoundCount], charsmax(g_DamageSounds[]), szModelPath)
                
DamageSoundCount++
            }
        } 
However, you might consider using a global variable for this counter (DamageSoundCount) so that you can properly handle not having the array completely full. You can refactor this if you want to add in the error message like the others but you can easily test with this just fine.

If you also need the precached model reference, you can simply add that back in front of precache_model().

Quote:
Originally Posted by yagami View Post
PHP Code:
write_short(g_PrecSprSmoke
New
PHP Code:
write_short(szModelPath
?
We didn't change any variable names so you shouldn't have to change any code anywhere else to implement your request. If you need the model reference like you do here, you need to add that assignment back into the code like your original had it. I.e. g_PrecSprSmoke = precache_model(szModelPath) for each one that you need.
__________________
fysiks is offline
lexzor
Veteran Member
Join Date: Nov 2020
Old 07-18-2023 , 05:31   Re: file in .ini mode
Reply With Quote #8

write_short means in the message a parameter must be write as a short (or int/cell whatever you want to call it), in this case you asked to replace the write_short with a string. if there would have been the case, the parameter must been wrote with write_string

precache_* just return a cache id (precache it's just cache it before used)

eg from precache_model
PHP Code:
Return
Unique cache id of the model 
and for practice purpose, to organize your code better and to have a better readibility, i encourage you to use enums:

Code:
#include <amxmodx>
enum _:PRECACHED_STRUCT
{     DISP_SMOKE,     DISP_HEALLIFEB,     DISP_HEALLIFER,     DISP_MODELGIBSR,     //... so on }
new g_iPrecachedModelID[PRECACHED_STRUCT]
public plugin_precache() {     //.. reading file code....     if(equal(szVariableIndentifier, "g_PrecSprSmoke"))     {         if(file_exists(szModelPath))         {
           g_iPrecachedModelID[DISP_SMOKE] = precache_model(szModelPath)
        }         else         {             log_error(AMX_ERR_NOTFOUND, "File %s does not exists", szModelPath)         }     } } callingMessage() {     message_begin(/** Your parameters... */)     //..annother writing message natives.. if there are any
   write_short(g_iPrecachedModelID[DISP_SMOKE])
    //..annother writing message natives.. if there are any     message_end() }

there is no use of this, just wanted to show you how you could build the plugin better

Last edited by lexzor; 07-18-2023 at 05:33.
lexzor is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 07-18-2023 , 11:09   Re: file in .ini mode
Reply With Quote #9

You could easily use OcixCrom's plugins as reference as most of his plugin are pretty advanced in terms of config/initiate customization.
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
bigdaddy424
Senior Member
Join Date: Oct 2021
Location: Jupiter
Old 07-18-2023 , 12:49   Re: file in .ini mode
Reply With Quote #10

Quote:
Originally Posted by Natsheh View Post
There you can also use this func...
isnt fopen memory consuming? would this work?
PHP Code:
new file fopen()
get_file_keyvalue(Handle:file, ...) 
__________________
bigdaddy424 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 10:28.


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