AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved arrays help (https://forums.alliedmods.net/showthread.php?t=319312)

riste.kgb 10-24-2019 10:10

arrays help
 
I'm trying to read the data from the cfg file, hovewer it's bugged. And it's bugged only in static function that checks for freevip time here is the code:
Code:

has_freevip_flag(const flag[]){
static iHour[32]
for(new i; i < ArraySize(g_serverData); i++){
                static iConfig[ServerConfig]
  ArrayGetArray(g_serverData,i,iConfig)
  get_time("%H",iHour,charsmax(iHour))
  new hour = str_to_num(iHour)
  new vipstart = str_to_num(iConfig[VIP_FREEHOUR_START])
  new vipend = str_to_num(iConfig[VIP_FREEHOUR_END])
  return iConfig[VIP_FREEHOUR_ENABLED];
  if(equali(iConfig[VIP_FREEHOUR_ENABLED],"on") && hour >= vipstart && hour < vipend && strfind(iConfig[VIP_FREEHOUR_FLAGS],flag,true)){
          return 1
        }
        return 0;
}
}

This return that i was set before if statement is just to debug, but it is always returns 0.

While i was debugging yesterday the problem comes in retrieving the array. But when i use ArraySize(g_serverData) it returns 6 as it is 6 items in base.
Here is my config file created for my own vip system config file:

Code:

VIP_DAMAGE = "3"
VIP_FREEHOUR_ENABLED = "on"
VIP_FREEHOUR_START = "12"
VIP_FREEHOUR_END = "20"
VIP_FREEHOUR_FLAGS = "abd"
VIP_NOFALL = "12"

Here is how i read the config and how i put in array the data from config file:
Code:

static readConfig(){
        ArrayClear(g_serverData)
        new szFile[128],szServerData[512],iConfig[ServerConfig];
        formatex(szFile,charsmax(szFile),"addons/amxmodx/configs/vips.cfg")
        new iFile = fopen(szFile,"rt");
        if(!iFile){
                log_amx("File not found %s", szFile)
                set_fail_state("Can't fint the vips cfg file")
                return PLUGIN_HANDLED
        }
        if(iFile){
               
        while(fgets(iFile,szServerData,charsmax(szServerData))){
                trim(szServerData)
                remove_quotes(szServerData)
                switch(szServerData[0]){
                        case EOS,'#','/','\':
                        {
                                continue;
                        }
                        default:
                        {
                                new szKey[32],szValue[32]
                                strtok(szServerData,szKey,charsmax(szKey),szValue,charsmax(szValue),'=')
                                trim(szKey)
                                trim(szValue)
                                remove_quotes(szKey)
                                remove_quotes(szValue)
                                if( ! szValue[ 0 ] || ! szKey[ 0 ] )
                                        {
                                                continue;
                                        }
                               
                                if(equali(szKey,"VIP_DAMAGE")){
                                        copy(iConfig[VIP_DAMAGE],charsmax(iConfig[VIP_DAMAGE]),szValue)
                                }
                                else if(equali(szKey,"VIP_FREEHOUR_ENABLED")){
                                copy(iConfig[VIP_FREEHOUR_ENABLED],charsmax(iConfig[VIP_FREEHOUR_ENABLED]), szValue)
                                }
                                else if(equali(szKey,"VIP_FREEHOUR_START")){
                                        copy(iConfig[VIP_FREEHOUR_START],charsmax(iConfig[VIP_FREEHOUR_START]),szValue)
                                }
                                else if(equali(szKey,"VIP_FREEHOUR_END")){
                                        copy(iConfig[VIP_FREEHOUR_END],charsmax(iConfig[VIP_FREEHOUR_END]),szValue)
                                }
                                else if(equali(szKey,"VIP_FREEHOUR_FLAGS")){
                                        copy(iConfig[VIP_FREEHOUR_FLAGS],charsmax(iConfig[VIP_FREEHOUR_FLAGS]),szValue)
                                }
                                else if(equali(szKey,"VIP_NOFALL")){
                                copy(iConfig[VIP_NOFALL],charsmax(iConfig[VIP_NOFALL]),szValue)
                                }
                               
                                //parse(szValue,iConfig[VIP_DAMAGE],charsmax(iConfig[VIP_DAMAGE]),iConfig[VIP_FREEHOUR_ENABLED],charsmax(iConfig[VIP_FREEHOUR_ENABLED]),iConfig[VIP_FREEHOUR_START],charsmax(iConfig[VIP_FREEHOUR_START]),iConfig[VIP_FREEHOUR_END],charsmax(iConfig[VIP_FREEHOUR_END]),iConfig[VIP_FREEHOUR_FLAGS],charsmax(iConfig[VIP_FREEHOUR_FLAGS]),iConfig[VIP_NOFALL],charsmax(iConfig[VIP_NOFALL]))
                                ArrayPushArray(g_serverData,iConfig)
                                arrayset(iConfig,0,sizeof(iConfig))
                        }
                }
        }
        fclose(iFile)
        }
      return PLUGIN_CONTINUE
}


Natsheh 10-24-2019 10:25

Re: arrays help
 
Read more about how static variables work..

Here is a solution replace static iHour[32] with new szHour[32]

Also setting the first char in a variable( the tag I or i) relates that it's an integer variable, using sz for string and f or F for float and a or A for an array (readability)

riste.kgb 10-24-2019 10:28

Re: arrays help
 
Quote:

Originally Posted by Natsheh (Post 2670824)
Read more about how static variables work..

Here is a solution replace static iHour[32] with new szHour[32]

The problem is not in iHour, because if i debug that array it will print the current hour. But the problem is in

iConfig array which i was used from function ArrayGetArray(g_serverData,i,iConfig)

Still not solved.


All times are GMT -4. The time now is 02:57.

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