Raised This Month: $ Target: $400
 0% 

Solved Plugin not reading lines properly


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
PinHeaDi
Senior Member
Join Date: Jul 2013
Location: Bulgaria
Old 11-16-2017 , 08:05   Plugin not reading lines properly
Reply With Quote #1

PHP Code:
public void OnMapStart()
{
    
checkmap();

PHP Code:
void checkmap()
{
    if(!
GetConVarBool(RespawnEnabled))
        return;

    
char line[128], g_szConfig[PLATFORM_MAX_PATH], g_szMap[128];
    
    
GetCurrentMap(g_szMapsizeof(g_szMap));
    
BuildPath(Path_SMg_szConfigsizeof(g_szConfig), "configs/ar_respawn_maps.cfg.cfg");
    
    
Handle MgMaps OpenFile(g_szConfig"r");
    
    while(!
IsEndOfFile(MgMaps))
    {
        
ReadFileLine(MgMapslinesizeof(line));
        
        if (
StrEqual(lineg_szMapfalse))
        { 
            
g_bEnableMap true;
            
LateForRespawn false;
        }
        
CloseHandle(MgMaps);
    } 
    else 
    {
        
PrintToServer("[SM] Could not find config (configs/ar_respawn_maps.cfg)");
    }

It only reads the last line of the config, so only the last map in the list, not all of them.

ar_respawn_maps.cfg.cfg:

Code:
mg_acrophobia_run_v1
mg_adev
mg_antique_course
mg_cartoon_course_v3_1
mg_course_ravine_final
mg_crash_bandicoot_course_v1
mg_cyber_course_v5
mg_damons_course_beta
mg_dans_course_remaster
mg_dev_galaxie_course_csgo
mg_dev_netrial_course
mg_dust_course_2_csgo_v1
mg_escape_castle_v3_fix
mg_gavle_course_v5
mg_lego_course_3_csgo
mg_metal_course_2
mg_metal_course_level
mg_metal_course_level_2
mg_minecraft_adventure_final_fix
mg_minecraft_course_JB_N1
mg_nimafa_3_final_v3
mg_nxr_course_csgo
mg_office_coursee_2012_fixed
mg_runordie_final
mg_savethebacon_course_final
mg_savetheisland_course_reskin
mg_saw_3_v1
mg_siberdev_2
mg_sky_realm_v3
mg_sonic_islands_v4
mg_switch_cource
mg_last_light_v3
mg_touchdev_course_fix
mg_tunnel_beta_cource
mg_office45_course
mg_pharaohs_tomb2_go_v3
mg_onetaprun_course_v2_d
mg_ancient_course_v2
mg_blood_sector_v1
mg_east_office_beta
mg_ghosts_cave_csgo
mg_halo_course_csgo
mg_heppy_dev_v1
mg_office_easy_course_csgo
__________________

Last edited by PinHeaDi; 11-16-2017 at 15:58.
PinHeaDi is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 11-16-2017 , 10:17   Re: Plugin not reading lines properly
Reply With Quote #2

first thing i see is that you close the handle to the file in the while loop..
second thing i see is: configs/ar_respawn_maps.cfg.cfg

Last edited by Mitchell; 11-16-2017 at 10:18.
Mitchell is offline
PinHeaDi
Senior Member
Join Date: Jul 2013
Location: Bulgaria
Old 11-16-2017 , 10:38   Re: Plugin not reading lines properly
Reply With Quote #3

PHP Code:
void checkmap()
{
    if(!
GetConVarBool(RespawnEnabled))
        return;

    
char line[128], g_szConfig[PLATFORM_MAX_PATH], g_CurrentMap[128];
    
    
GetCurrentMap(g_CurrentMapsizeof(g_CurrentMap));
    
BuildPath(Path_SMg_szConfigsizeof(g_szConfig), "configs/ar_respawn_maps.cfg");
    
    
Handle MgMaps OpenFile(g_szConfig"r");
    
    if (
MgMaps != INVALID_HANDLE)
    {
        while(!
IsEndOfFile(MgMaps))
        {
            
ReadFileLine(MgMapslinesizeof(line));
            if (
StrEqual(lineg_CurrentMapfalse))
            { 
                
g_bEnableMap true;
                
LateForRespawn false;
            { 
            else
            {
                
g_bEnableMap false;
            }
        }
        
CloseHandle(MgMaps);
    }
    else
    {
        
PrintToServer("[SM] Could not find config (configs/ar_respawn_maps.cfg)"); 
    } 
Still, it doesn't load as it should, only the last line /map/ in the config.
__________________

Last edited by PinHeaDi; 11-16-2017 at 10:43.
PinHeaDi is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 11-16-2017 , 10:43   Re: Plugin not reading lines properly
Reply With Quote #4

you should loop ReadFileLine instead of IsEndOfFile
https://github.com/MitchDizzle/Would...Rather.sp#L252
Mitchell is offline
PinHeaDi
Senior Member
Join Date: Jul 2013
Location: Bulgaria
Old 11-16-2017 , 10:50   Re: Plugin not reading lines properly
Reply With Quote #5

So, since I can't test the code right now. Should it be something like that:

PHP Code:
void checkmap()
{
    if(!
GetConVarBool(RespawnEnabled))
        return;

    
char line[128], g_szConfig[PLATFORM_MAX_PATH], g_CurrentMap[128];
    
    
GetCurrentMap(g_CurrentMapsizeof(g_CurrentMap));
    
BuildPath(Path_SMg_szConfigsizeof(g_szConfig), "configs/ar_respawn_maps.cfg"); 
    
    
File MgMaps;
    
MgMaps OpenFile(g_szConfig"r");
    
    if (
MgMaps != INVALID_HANDLE)
    {
        while(
MgMaps.ReadLine(linesizeof(line)))
        {
            if (
StrEqual(lineg_CurrentMapfalse))
            { 
                
g_bEnableMap true;
                
LateForRespawn false;
            }
            else{
                
g_bEnableMap false;
            }
        }
        
MgMaps.Close();
    }
    else{
        
PrintToServer("[SM] Could not find config (configs/ar_respawn_maps.cfg)"); 
    }

It compiles without errors.
__________________
PinHeaDi is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 11-16-2017 , 10:59   Re: Plugin not reading lines properly
Reply With Quote #6

you would need something like this, or g_bEnableMap will never be true unless you were on the very last map in the list.
Code:
void checkmap() 
{ 
    if(!GetConVarBool(RespawnEnabled)) 
        return; 

    char line[128], g_szConfig[PLATFORM_MAX_PATH], g_CurrentMap[128]; 
     
    GetCurrentMap(g_CurrentMap, sizeof(g_CurrentMap)); 
    BuildPath(Path_SM, g_szConfig, sizeof(g_szConfig), "configs/ar_respawn_maps.cfg");  
     
    File MgMaps; 
    MgMaps = OpenFile(g_szConfig, "r"); 
     
    g_bEnableMap = false; 
    if (MgMaps != null) 
    { 
        while(MgMaps.ReadLine(line, sizeof(line))) 
        { 
            if (StrEqual(line, g_CurrentMap, false)) 
            {  
                g_bEnableMap = true; 
                LateForRespawn = false;
                break;
            }
        } 
        MgMaps.Close(); 
    } 
    else{ 
        PrintToServer("[SM] Could not find config (configs/ar_respawn_maps.cfg)");  
    } 
}
Mitchell is offline
PinHeaDi
Senior Member
Join Date: Jul 2013
Location: Bulgaria
Old 11-16-2017 , 11:04   Re: Plugin not reading lines properly
Reply With Quote #7

Will try that later, but I have a bool g_bEnableMap = false; at the beginning of the plugin or get that wrong. Isn't that bool supposed to put g_bEnableMap false by default.

P.S.: Nvm, it wasn't set to false, only bool g_bEnablemap;.
__________________

Last edited by PinHeaDi; 11-16-2017 at 11:15.
PinHeaDi is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 11-16-2017 , 11:15   Re: Plugin not reading lines properly
Reply With Quote #8

Quote:
Originally Posted by PinHeaDi View Post
Will try that later, but I have a bool g_bEnableMap = false; at the beginning of the plugin or get that wrong. Isn't that bool supposed to put g_bEnableMap false by default
By default yes, however plugins don't reload after map change unless they are modified. So you'll either want to set it false before checking on the next map again or set it to false with OnMapEnd.
Mitchell is offline
PinHeaDi
Senior Member
Join Date: Jul 2013
Location: Bulgaria
Old 11-16-2017 , 11:27   Re: Plugin not reading lines properly
Reply With Quote #9

So if I put g_bEnableMap = false; before checkmap(); in OnMapStart and not the in the checkmap();, it should work too
__________________
PinHeaDi is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 11-16-2017 , 11:31   Re: Plugin not reading lines properly
Reply With Quote #10

Quote:
Originally Posted by PinHeaDi View Post
So if I put g_bEnableMap = false; before checkmap(); in OnMapStart and not the in the checkmap();, it should work too
sure, but it makes no difference what so ever where you put it either in checkmap() or in OnMapStart(), it's just for when reading it later instead of the variable be spread around the plugin you can have it where you check the maps list
Mitchell 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 21:01.


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