AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved [Help] Wrong Value Printed !!! (https://forums.alliedmods.net/showthread.php?t=339286)

Begineer Programmer 08-30-2022 09:52

[Help] Wrong Value Printed !!!
 
1 Attachment(s)
Hi All !!!
i need little help when mapname cfg file not found its should return 0 and if file exist and have no value of mp_maxrounds then should also return 0 and printed to 0 but it print 1 why ? [Where i have done mistake !!!] [See Red Highlighted One !!!]


PHP Code:

#include <amxmodx> 
#include <cstrike>
#include <amxmisc>
#pragma semicolon 1
#pragma tabsize 4
new runde 0;
new 
prefix[32] = "AMXX";
new 
TerrScoreCTScore;
public 
plugin_init()  

    
register_plugin"Info Top""1.4""->UrOS<-");    
    
register_event("HLTV""round_start""a""1=0""2=0");
    
register_event("TextMsg""round_restart""a""2=#Game_will_restart_in""2=#Game_Commencing");
    
register_event("TeamScore""terr_score""a""1=TERRORIST");
    
register_event("TeamScore""ct_score""a""1=CT");

public 
round_restart()
{
    
runde 0;
    
TerrScore=0;
    
CTScore=0;
}
public 
terr_score()
{
    
TerrScore read_data(2);
}
public 
ct_score()
{
    
CTScore read_data(2);
}
public 
round_start() 

    
    
    new 
mapname[32], nextmap[32], players[32], player ,maxrundimaxplayers,maxroundsCvar;
    
    
maxrundi=get_cvar_num("mp_maxrounds");
    
maxplayers=get_maxplayers();
    
get_cvar_string("amx_nextmap",nextmap,31); 
    
get_mapname(mapname,31);
    
get_players(playersplayer);
    
maxroundsCvar=get_map_maxrounds(mapname);
    
client_print_color(0,print_team_default,"^4[%s]^3 Rounds:^4 %d^3/^4%d ^1|^3 Score:^3 Ts:^4%i^3 -^3 CTs:^4%i ^1|^3 Map:^4 %s^3/^4%s [%i] ^1|^3 Players:^4 %d^3/^4%d",prefixrunde,maxrundi,TerrScore,CTScore,mapnamenextmap,maxroundsCvarplayer,maxplayers); 
    
runde++;
}

get_map_maxrounds(szMapname[])
{
    new 
szConfigsDir[64], szFilePath[128];
    
get_configsdir(szConfigsDircharsmax(szConfigsDir));
    
format(szFilePathcharsmax(szFilePath), "%s/maps/%s.cfg",szConfigsDirszMapname);
    new 
fopen(szFilePath"rt");
    if( 
)
    {
        new 
szCvar[32], szValue[32], szCfgData[64],iValue;
    
        while(
fgets(fszCfgDatacharsmax(szCfgData)))
        {
            
parse(szCfgDataszCvarcharsmax(szCvar), szValuecharsmax(szValue));
        
            if(
equali(szCvar"mp_maxrounds"))
            {
                
iValue str_to_num(szValue);    
            }
            
        }
        
fclose(f);
        return 
iValue==1?iValue:0;
    }
    return 
PLUGIN_HANDLED;



jimaway 08-30-2022 11:06

Re: [Help] Wrong Value Printed !!!
 
PLUGIN_HANDLED is 1, you're returning it if the file couldn't be opened

Begineer Programmer 08-30-2022 11:24

Re: [Help] Wrong Value Printed !!!
 
Quote:

Originally Posted by jimaway (Post 2787755)
PLUGIN_HANDLED is 1, you're returning it if the file couldn't be opened

I rename it as PLUGIN_CONTINUE !!!

PHP Code:

#include <amxmodx> 
#include <cstrike>
#include <amxmisc>
#pragma semicolon 1
#pragma tabsize 4
new runde 0;
new 
prefix[32] = "AMXX";
new 
TerrScoreCTScore;
public 
plugin_init()  

    
register_plugin"Info Top""1.4""->UrOS<-");    
    
register_event("HLTV""round_start""a""1=0""2=0");
    
register_event("TextMsg""round_restart""a""2=#Game_will_restart_in""2=#Game_Commencing");
    
register_event("TeamScore""terr_score""a""1=TERRORIST");
    
register_event("TeamScore""ct_score""a""1=CT");

public 
round_restart()
{
    
runde 0;
    
TerrScore=0;
    
CTScore=0;
}
public 
terr_score()
{
    
TerrScore read_data(2);
}
public 
ct_score()
{
    
CTScore read_data(2);
}
public 
round_start() 

    
    
    new 
mapname[32], nextmap[32], players[32], player ,maxrundimaxplayers,maxroundsCvar;
    
    
maxrundi=get_cvar_num("mp_maxrounds");
    
maxplayers=get_maxplayers();
    
get_cvar_string("amx_nextmap",nextmap,31); 
    
get_mapname(mapname,31);
    
get_players(playersplayer);
    
maxroundsCvar=get_map_maxrounds(mapname);
    if (
maxroundsCvar==0)
    {
        
client_print_color(0,print_team_default,"^4[%s]^3 Rounds:^4 %d^3/^4%d ^1|^3 Score:^3 Ts:^4%i^3 -^3 CTs:^4%i ^1|^3 Map:^4 %s^3/^4%s [No Round Limit] ^1|^3 Players:^4 %d^3/^4%d",prefixrunde,maxrundi,TerrScore,CTScore,mapnamenextmapplayer,maxplayers);
    }
    else
    {
        
client_print_color(0,print_team_default,"^4[%s]^3 Rounds:^4 %d^3/^4%d ^1|^3 Score:^3 Ts:^4%i^3 -^3 CTs:^4%i ^1|^3 Map:^4 %s^3/^4%s [%i] ^1|^3 Players:^4 %d^3/^4%d",prefixrunde,maxrundi,TerrScore,CTScore,mapnamenextmap,maxroundsCvarplayer,maxplayers);
    }
     
    
runde++;
}

get_map_maxrounds(szMapname[])
{
    new 
szConfigsDir[64], szFilePath[128];
    
get_configsdir(szConfigsDircharsmax(szConfigsDir));
    
format(szFilePathcharsmax(szFilePath), "%s/maps/%s.cfg",szConfigsDirszMapname);
    new 
fopen(szFilePath"rt");
    if( 
)
    {
        new 
szCvar[32], szValue[32], szCfgData[64],iValue;
    
        while(
fgets(fszCfgDatacharsmax(szCfgData)))
        {
            
parse(szCfgDataszCvarcharsmax(szCvar), szValuecharsmax(szValue));
        
            if(
equali(szCvar"mp_maxrounds"))
            {
                
iValue str_to_num(szValue);    
            }
            
        }
        
fclose(f);
        return 
iValue;
    }
    return 
PLUGIN_CONTINUE;



fysiks 08-31-2022 01:27

Re: [Help] Wrong Value Printed !!!
 
Do NOT use PLUGIN_CONTINUE because it makes no sense in the context. You should simply return a 0.

Begineer Programmer 08-31-2022 02:59

Re: [Help] Wrong Value Printed !!!
 
Quote:

Originally Posted by fysiks (Post 2787797)
Do NOT use PLUGIN_CONTINUE because it makes no sense in the context. You should simply return a 0.

Thanks and Updated !!!

PHP Code:

#include <amxmodx> 
#include <cstrike>
#include <amxmisc>
#pragma semicolon 1
#pragma tabsize 4
new runde 0;
new 
prefix[32] = "AMXX";
new 
TerrScoreCTScore;
public 
plugin_init()  

    
register_plugin"Info Top""1.4""->UrOS<-");    
    
register_event("HLTV""round_start""a""1=0""2=0");
    
register_event("TextMsg""round_restart""a""2=#Game_will_restart_in""2=#Game_Commencing");
    
register_event("TeamScore""terr_score""a""1=TERRORIST");
    
register_event("TeamScore""ct_score""a""1=CT");

public 
round_restart()
{
    
runde 0;
    
TerrScore=0;
    
CTScore=0;
}
public 
terr_score()
{
    
TerrScore read_data(2);
}
public 
ct_score()
{
    
CTScore read_data(2);
}
public 
round_start() 

    
    
    new 
mapname[32], nextmap[32], players[32], player ,maxrundimaxplayers,maxroundsCvar;
    
    
maxrundi=get_cvar_num("mp_maxrounds");
    
maxplayers=get_maxplayers();
    
get_cvar_string("amx_nextmap",nextmap,31); 
    
get_mapname(mapname,31);
    
get_players(playersplayer);
    
maxroundsCvar=get_map_maxrounds(mapname);
    if (
maxroundsCvar==0)
    {
        
client_print_color(0,print_team_default,"^4[%s]^3 Rounds:^4 %d^3/^4%d ^1|^3 Score:^3 Ts:^4%i^3 -^3 CTs:^4%i ^1|^3 Map:^4 %s^3/^4%s ^1[^4No Round Limit^1] ^1|^3 Players:^4 %d^3/^4%d",prefixrunde,maxrundi,TerrScore,CTScore,mapnamenextmapplayer,maxplayers);
    }
    else
    {
        
client_print_color(0,print_team_default,"^4[%s]^3 Rounds:^4 %d^3/^4%d ^1|^3 Score:^3 Ts:^4%i^3 -^3 CTs:^4%i ^1|^3 Map:^4 %s^3/^4%s ^1[^4%i^1] ^1|^3 Players:^4 %d^3/^4%d",prefixrunde,maxrundi,TerrScore,CTScore,mapnamenextmap,maxroundsCvarplayer,maxplayers);
    }
     
    
runde++;
}
get_map_maxrounds(szMapname[])
{
    new 
szConfigsDir[64], szFilePath[128];
    
get_configsdir(szConfigsDircharsmax(szConfigsDir));
    
format(szFilePathcharsmax(szFilePath), "%s/maps/%s.cfg",szConfigsDirszMapname);
    new 
fopen(szFilePath"rt");
    if( 
)
    {
        new 
szCvar[32], szValue[32], szCfgData[64],iValue;
    
        while(
fgets(fszCfgDatacharsmax(szCfgData)))
        {
            
parse(szCfgDataszCvarcharsmax(szCvar), szValuecharsmax(szValue));
        
            if(
equali(szCvar"mp_maxrounds"))
            {
                
iValue str_to_num(szValue);    
            }
            
        }
        
fclose(f);
        return 
iValue;
    }
    return 
0;



Natsheh 08-31-2022 09:15

Re: [Help] Wrong Value Printed !!!
 
Btw you should return a negative numbers when an error occur, it help understanding the problem...


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

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