Raised This Month: $ Target: $400
 0% 

Solved arrays help


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
riste.kgb
Junior Member
Join Date: Oct 2019
Location: Macedonia, Bogdanci
Old 10-24-2019 , 10:10   arrays help
Reply With Quote #1

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
}

Last edited by riste.kgb; 10-25-2019 at 06:38. Reason: I solved the issue in my own way.
riste.kgb is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 10-24-2019 , 10:25   Re: arrays help
Reply With Quote #2

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)
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 10-24-2019 at 10:29.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
riste.kgb
Junior Member
Join Date: Oct 2019
Location: Macedonia, Bogdanci
Old 10-24-2019 , 10:28   Re: arrays help
Reply With Quote #3

Quote:
Originally Posted by Natsheh View Post
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.
riste.kgb 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 02:57.


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