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

Solved [Help] Wrong Value Printed !!!


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Begineer Programmer
Member
Join Date: Nov 2021
Old 08-30-2022 , 09:52   [Help] Wrong Value Printed !!!
Reply With Quote #1

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;

Attached Thumbnails
Click image for larger version

Name:	1.png
Views:	35
Size:	37.0 KB
ID:	196577  

Last edited by Begineer Programmer; 08-31-2022 at 05:55.
Begineer Programmer is offline
jimaway
Heeeere's Jimmy!
Join Date: Jan 2009
Location: Estonia
Old 08-30-2022 , 11:06   Re: [Help] Wrong Value Printed !!!
Reply With Quote #2

PLUGIN_HANDLED is 1, you're returning it if the file couldn't be opened
jimaway is offline
Begineer Programmer
Member
Join Date: Nov 2021
Old 08-30-2022 , 11:24   Re: [Help] Wrong Value Printed !!!
Reply With Quote #3

Quote:
Originally Posted by jimaway View Post
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;


Last edited by Begineer Programmer; 08-30-2022 at 11:39.
Begineer Programmer is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-31-2022 , 01:27   Re: [Help] Wrong Value Printed !!!
Reply With Quote #4

Do NOT use PLUGIN_CONTINUE because it makes no sense in the context. You should simply return a 0.
__________________
fysiks is offline
Begineer Programmer
Member
Join Date: Nov 2021
Old 08-31-2022 , 02:59   Re: [Help] Wrong Value Printed !!!
Reply With Quote #5

Quote:
Originally Posted by fysiks View Post
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;

Begineer Programmer is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 08-31-2022 , 09:15   Re: [Help] Wrong Value Printed !!!
Reply With Quote #6

Btw you should return a negative numbers when an error occur, it help understanding the problem...
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
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 09:36.


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