Raised This Month: $ Target: $400
 0% 

Reload File


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Haskyutza
Junior Member
Join Date: May 2013
Location: Romania
Old 05-17-2013 , 15:44   Reload File
Reply With Quote #1

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


Haskyutza is offline
pokemonmaster
princess milk
Join Date: Nov 2010
Location: Somewhere in this world
Old 05-17-2013 , 16:21   Re: Reload File
Reply With Quote #2

What is the file format

Code:
name1
name2
name3
name4
name5
or something else?
__________________
اَشْهَدُ اَنْ لَّآ اِلٰهَ اِلَّا اللہُ وَحْدَه لَا شَرِيْكَ لَه وَ اَشْهَدُ اَنَّ مُحَمَّدًا عَبْدُه وَرَسُوْلُه
No longer active in AMXX. Sorry.
pokemonmaster is offline
Haskyutza
Junior Member
Join Date: May 2013
Location: Romania
Old 05-18-2013 , 01:36   Re: Reload File
Reply With Quote #3

Quote:
name1
name2
name3
name4
name5
Yes, like this

Last edited by Haskyutza; 05-18-2013 at 01:37.
Haskyutza is offline
pokemonmaster
princess milk
Join Date: Nov 2010
Location: Somewhere in this world
Old 05-18-2013 , 06:14   Re: Reload File
Reply With Quote #4

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

__________________
اَشْهَدُ اَنْ لَّآ اِلٰهَ اِلَّا اللہُ وَحْدَه لَا شَرِيْكَ لَه وَ اَشْهَدُ اَنَّ مُحَمَّدًا عَبْدُه وَرَسُوْلُه
No longer active in AMXX. Sorry.

Last edited by pokemonmaster; 05-18-2013 at 06:21.
pokemonmaster is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 05-18-2013 , 06:47   Re: Reload File
Reply With Quote #5

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
    
}

__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 05-18-2013 at 06:51.
ConnorMcLeod is offline
Haskyutza
Junior Member
Join Date: May 2013
Location: Romania
Old 05-18-2013 , 07:30   Re: Reload File
Reply With Quote #6

Neither of this two examples does not work
Haskyutza is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 05-18-2013 , 07:34   Re: Reload File
Reply With Quote #7

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.
__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 05-18-2013 at 07:35.
ConnorMcLeod is offline
Haskyutza
Junior Member
Join Date: May 2013
Location: Romania
Old 05-18-2013 , 07:46   Re: Reload File
Reply With Quote #8

Here
Attached Files
File Type: sma Get Plugin or Get Source (viplist.sma - 592 views - 3.0 KB)
Haskyutza is offline
pokemonmaster
princess milk
Join Date: Nov 2010
Location: Somewhere in this world
Old 05-18-2013 , 07:58   Re: Reload File
Reply With Quote #9

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

__________________
اَشْهَدُ اَنْ لَّآ اِلٰهَ اِلَّا اللہُ وَحْدَه لَا شَرِيْكَ لَه وَ اَشْهَدُ اَنَّ مُحَمَّدًا عَبْدُه وَرَسُوْلُه
No longer active in AMXX. Sorry.
pokemonmaster is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 05-18-2013 , 08:09   Re: Reload File
Reply With Quote #10

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 ?
__________________
Arkshine 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 16:15.


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