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
}