AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Reload File (https://forums.alliedmods.net/showthread.php?t=216181)

Haskyutza 05-17-2013 15:44

Reload File
 
Hi
I have a little problem with this code.I tried to reload a file with a command but it is not working(I don't know why).I saw on the another plugin this method and there it's work.
In this file I want to put the names of players (even if i think it does not matter)

I hope you can fix that or tell me where i'm wrong
PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <celltrie>

new gfi_WorkFile128 ];
new const 
gs_VipsFile[ ] = "file.ini";
new 
Trie:file_reload;

public 
plugin_init() 
{
    
register_plugin("File Beta","1.0""Hasky")
    
register_concmd("amx_reloadfile""reloadfile")
    
file_reload TrieCreate()
    
}
public 
plugin_cfg ( )
{
    new 
fi_Dir64 ];
    
get_configsdir fi_Dircharsmax fi_Dir ) );
    
formatex gfi_WorkFilecharsmax gfi_WorkFile ), "%s/%s"fi_Dirgs_VipsFile );
}


public 
reloadfile(id)
{
    
TrieClear(file_reload)
    
    new 
s_Buffer192 ], i_Linei_Lenname[32];
    while ( ( 
i_Line read_file gfi_WorkFilei_Lines_Buffercharsmax s_Buffer ), i_Len ) ) )
    {
        if ( ! 
strlen s_Buffer ) || s_Buffer] == ';' || ( s_Buffer] == '/' && s_Buffer] == '/' ) )
        continue;
        
        
parse(s_Buffernamecharsmax(name))
        
        if(!
name[0])
        continue
        
        
TrieSetCell(file_reloadname1);
    }




pokemonmaster 05-17-2013 16:21

Re: Reload File
 
What is the file format

Code:

name1
name2
name3
name4
name5

or something else?

Haskyutza 05-18-2013 01:36

Re: Reload File
 
Quote:

name1
name2
name3
name4
name5
Yes, like this

pokemonmaster 05-18-2013 06:14

Re: Reload File
 
Why do you use parse() if the line (s_Buffer) only contains a name? Also, parse is used in a wrong way.
you should do replace(s_Buffer, charsmax(s_Buffer), "^n", "") before checking anything else.

A fixed code would be
(I feel that something else is wrong, i don't know why -.-)
PHP Code:

public reloadfile(id

    
TrieClear(file_reload
    
    new 
s_Buffer192 ], i_Linei_Len;
    
    while ( ( 
i_Line read_file gfi_WorkFilei_Lines_Buffercharsmax s_Buffer ), i_Len ) ) ) 
    { 
        
replace(s_Buffercharsmax(s_Buffer), "^n""")
        
        if ( ! 
strlen s_Buffer ) || s_Buffer] == ';' || ( s_Buffer] == '/' && s_Buffer] == '/' ) ) 
            continue; 
        
        
TrieSetCell(file_reloads_Buffer1); 
    } 
    



ConnorMcLeod 05-18-2013 06:47

Re: Reload File
 
Don't use read_file, use new file natives.
Don't use replacer "^n" "", just use trim() native.

PHP Code:

public reloadfile(id)
{
    
TrieClear(file_reload)

    new 
fp fopen(gfi_WorkFile"rt")
    if( 
fp )
    {
        new 
buffer[256], c
        
while( !feof(fp) )
        {
            
fgets(fpbuffercharsmax(buffer))
            
trim(buffer)
            
buffer[0]
            if( 
&& != '#' && != ';' && !( == '/' && buffer[1] == '/' ) )
            {
                
// don't use parse there since you are only waiting for 1 argument
                
TrieSetCell(file_reloadbuffer1);
            }
        }
        
fclosefp )
        
fp 0
    
}



Haskyutza 05-18-2013 07:30

Re: Reload File
 
Neither of this two examples does not work

ConnorMcLeod 05-18-2013 07:34

Re: Reload File
 
Attach your file here.
Post the whole plugin so can see if you have made mistakes at other places, and how you check if file has been reloaded.

Haskyutza 05-18-2013 07:46

Re: Reload File
 
1 Attachment(s)
Here

pokemonmaster 05-18-2013 07:58

Re: Reload File
 
You don't use the trie to check if a player is vip, you check by the the array gs_VipsList
So each time you load a command, you need to reset the array and copy each entry from the file to it.

you could just do this to shortcut it
PHP Code:

public reloadvips(id)
{
    for(new 
isizeof(gs_VipsList); i++)
    {
        
setc(gs_VipsList[i], charsmax(gs_VipsList[]), 0)
    }
    
    
plugin_cfg()



Arkshine 05-18-2013 08:09

Re: Reload File
 
Calling 33 times a native where you could call one time with arrayset without loop or 0 with loop by just setting to = 0; do you have some awesome advice like that ?


All times are GMT -4. The time now is 16:15.

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