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

Ini Help


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ironskillz1
AlliedModders Donor
Join Date: Jul 2012
Location: Sweden
Old 06-12-2014 , 15:38   Ini Help
Reply With Quote #1

Hey i need some help to update my levelmod that i released a while ago.
Im planinng on making an ini document where the user can choose needed lvl | lvl name | knifemodel. The problem is that i dont realy know how i can make it.

I want something like this in a ini
Code:
"0" "New Player" "v_knife" "p_knife"
"200" "Beginner" "Levelmod/v_crowbar" "Levelmod/p_crowbar"
Right now im using these const todo the level functions
Code:
#define MaxLevels 6

new const iLevels[MaxLevels] = 
{ 
        0,
	200,
	300, 
	550, 
	700, 
	1000 
}
new const iLevelsName[MaxLevels][] =
{
	"New Player", 
	"Beginner", 
	"Rambo",  
	"Freak", 
	"Elite", 
	"Superman" 
}
new const iKnife[MaxLevels][2][] =
{
	{"models/v_knife.mdl", "models/p_knife.mdl"},
	{"models/LevelMod/v_crowbar.mdl", "models/LevelMod/p_crowbar.mdl"},
	{"models/LevelMod/v_axe.mdl", "models/LevelMod/p_axe.mdl"},
	{"models/LevelMod/v_machete.mdl", "models/LevelMod/p_machete.mdl"},
	{"models/LevelMod/v_katana.mdl", "models/LevelMod/p_katana.mdl"},
	{"models/LevelMod/v_silverblade.mdl", "models/LevelMod/p_silverblade.mdl"}
}
I manage todo this by looking on Vecos knife menu. But i dont know how i can connect them like when i im level 1 i should have evrything on the first line in the ini and so on
Code:
public plugin_precache( ) 
{    
	new file[44] 
	formatex(file,43,"addons/amxmodx/configs/levelmod.ini") 
	
	if(file_exists(file)) 
	{ 
		new iLevels2[64], iLevelNames2[64], iLevelModel_v[64], iLevelModel_p[64]    
		for(new i=0;i <= file_size(file, 1) - 1;i++) 
		{ 
			new data[1024],buffer 
			read_file(file,i,data,1023,buffer) 
			parse(data, iLevels2,64, iLevelNames2,64, iLevelModel_v,64, iLevelModel_p,64) 
			
			if(!equali(iLevelModel_v,"") || !equali(iLevelModel_p,""))
			{
				precache_model(iLevelModel_v) 
				precache_model(iLevelModel_p) 
			}
		} 
	} 
	else 
		log_amx("[%s] ERROR: File configs/levelmod.ini doesn't exist!", TAG) 
}
The plugin is in my signature
__________________
I have many private and unique plugins for Jailbreak and Hide'N'Seek. PM me for more info.

Pm me.

Check out my roulette site.
ironskillz1 is offline
Send a message via Skype™ to ironskillz1
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-12-2014 , 15:45   Re: Ini Help
Reply With Quote #2

I really don't understand your problem because you are practically done. You simply need to populate your global variable arrays with the information from the file. If you do this before the original precaching code, you don't need to add any precaching code and can simply insert the loading of the file at the beginning of plugin_precache().
__________________
fysiks is offline
ironskillz1
AlliedModders Donor
Join Date: Jul 2012
Location: Sweden
Old 06-12-2014 , 16:37   Re: Ini Help
Reply With Quote #3

Quote:
Originally Posted by fysiks View Post
I really don't understand your problem because you are practically done. You simply need to populate your global variable arrays with the information from the file. If you do this before the original precaching code, you don't need to add any precaching code and can simply insert the loading of the file at the beginning of plugin_precache().
Sorry but i dont understand. If you are able to show me i would be grateful
__________________
I have many private and unique plugins for Jailbreak and Hide'N'Seek. PM me for more info.

Pm me.

Check out my roulette site.
ironskillz1 is offline
Send a message via Skype™ to ironskillz1
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-12-2014 , 16:47   Re: Ini Help
Reply With Quote #4

e.g.

PHP Code:
iLevels[i] = str_to_num(iLevels2
Stirngs are even simpler, you can actually populate that directly from the parse command.

PHP Code:
parse(dataiLevels2,64iLevelsName[i],64iKnife[i][0],64iKnife[i][1],64
But, make sure that you declare a maximum string length in the declarations of those global variables.

-------------------------------

Another thing that you will need to consider is the maximum number of levels there will be allowed in the file and also account for when there are fewer levels. You can see an simple example of this in my Bot Apology plugin.

Also, you should avoid using the deprecated file reading method and switch to the more efficient method (fopen, fgets, fclose, etc.).
__________________

Last edited by fysiks; 06-12-2014 at 16:48.
fysiks is offline
ironskillz1
AlliedModders Donor
Join Date: Jul 2012
Location: Sweden
Old 06-12-2014 , 17:28   Re: Ini Help
Reply With Quote #5

Is this better? and will it work?

Code:
public plugin_precache( ) 
{    
	new cfgdir[64]
	get_localinfo("amxx_configsdir", cfgdir, charsmax(cfgdir))
	format(cfgdir, charsmax(cfgdir), "%s/levelmod.ini", cfgdir)
	
	if(file_exists(cfgdir)) 
	{ 
		TotalLevels = 0
		new iLevels2[64], iLevelNames2[64], tmpfile[101], sfLineData[128]
		new file = fopen(cfgdir,"rt")
		
		while(file && !feof(file)) 
		{
			fgets(file, sfLineData, charsmax(sfLineData))
			parse(sfLineData, iLevels2, 64, iLevelNames2[TotalLevels], 64, iKnife[TotalLevels][0], 64, iKnife[TotalLevels][1], 64)   
			
			TotalLevels++
			
			if(TotalLevels >= MaxLevels) 
			{
				log_amx("[%s] ERROR: You got %i levels and the plugins only allows %i", TAG, TotalLevels, MaxLevels) 
				return PLUGIN_HANDLED  
			}
			
			for (new i = 0; i < TotalLevels; ++i) 
			{
				format(tmpfile, charsmax(tmpfile), "models/%s.mdl", iKnife[i][0])
				format(tmpfile, charsmax(tmpfile), "models/%s.mdl", iKnife[i][1])
				
				iLevels[i] = str_to_num(iLevels2)  
				iLevelNames[i] = iLevelNames2[i]
				
				if (file_exists(tmpfile)) 
				{
					precache_model(iKnife[i][0]) 
					precache_model(iKnife[i][1]) 
				} 
				else 
					server_print("Failed to precache %s", tmpfile);
			}
		}
	} 
	else 
		log_amx("[%s] ERROR: File %s/levelmod.ini doesn't exist!", TAG, cfgdir) 
	
	return PLUGIN_HANDLED  
}
__________________
I have many private and unique plugins for Jailbreak and Hide'N'Seek. PM me for more info.

Pm me.

Check out my roulette site.
ironskillz1 is offline
Send a message via Skype™ to ironskillz1
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-12-2014 , 18:57   Re: Ini Help
Reply With Quote #6

Quote:
Originally Posted by ironskillz1 View Post
will it work?
What happens when you run it?
__________________
fysiks is offline
ironskillz1
AlliedModders Donor
Join Date: Jul 2012
Location: Sweden
Old 06-13-2014 , 09:16   Re: Ini Help
Reply With Quote #7

It doesnt seems to work

Here is my levelmod.ini
Code:
"200" "Pro Player" "GSJailbreak/v_katana" "GSJailbreak/p_katana"
"1000" "Elite Player" "GSJailbreak/v_hunter" "GSJailbreak/p_hunter"
Here is the function
Code:
public plugin_precache( ) 
{    
	new cfgdir[64]
	get_localinfo("amxx_configsdir", cfgdir, charsmax(cfgdir))
	format(cfgdir, charsmax(cfgdir), "%s/levelmod.ini", cfgdir)
	
	if(file_exists(cfgdir)) 
	{ 
		TotalLevels = 0
		new iLevels2[64], iLevelNames2[64], tmpfile[101], sfLineData[128]
		new file = fopen(cfgdir,"rt")
		
		while(file && !feof(file)) 
		{
			fgets(file, sfLineData, charsmax(sfLineData))
			parse(sfLineData, iLevels2, 64, iLevelNames2[TotalLevels], 64, iKnife[TotalLevels][0], 64, iKnife[TotalLevels][1], 64)   
			
			TotalLevels++
			
			if(TotalLevels >= MaxLevels) 
			{
				log_amx("[%s] ERROR: You got %i levels and the plugins only allows %i", TAG, TotalLevels, MaxLevels) 
				return PLUGIN_HANDLED  
			}
		}
		if(file) 
			fclose(file);
		
		for (new i = 0; i < TotalLevels; ++i) 
		{
			//format(tmpfile, charsmax(tmpfile), "models/%s.mdl", iKnife[i][0])
			//format(tmpfile, charsmax(tmpfile), "models/%s.mdl", iKnife[i][1])
			
			iLevels[i] = str_to_num(iLevels2)  
			iLevelNames[i] = iLevelNames2[i]
			
			log_amx("Loaded %s %s %i %s", iKnife[i][0], iKnife[i][1], iLevels[i], iLevelNames[i])
			
			/*if (file_exists(tmpfile)) 
			{
				precache_model(iKnife[i][0]) 
				precache_model(iKnife[i][1]) 
			} 
			else 
				server_print("[%s] ERROR: Failed to precache %s", TAG, tmpfile);*/
		}
	} 
	else 
		log_amx("[%s] ERROR: File %s doesn't exist!", TAG, cfgdir) 
	
	return PLUGIN_HANDLED  
}
And here is the outcome its completly wrong.
Code:
L 06/13/2014 - 15:14:35: [Untitled.amxx] Loaded GGGGSJailbreak/p_hunter GGGSJailbreak/p_hunter 1000 P
L 06/13/2014 - 15:14:35: [Untitled.amxx] Loaded GGSJailbreak/p_hunter GSJailbreak/p_hunter 1000 E
L 06/13/2014 - 15:14:35: [Untitled.amxx] Loaded SJailbreak/p_hunter Jailbreak/p_hunter 1000 l
And here is the complete plugin.
Attached Files
File Type: sma Get Plugin or Get Source (Untitled.sma - 469 views - 17.9 KB)
__________________
I have many private and unique plugins for Jailbreak and Hide'N'Seek. PM me for more info.

Pm me.

Check out my roulette site.

Last edited by ironskillz1; 06-13-2014 at 09:20.
ironskillz1 is offline
Send a message via Skype™ to ironskillz1
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-13-2014 , 16:10   Re: Ini Help
Reply With Quote #8

The first thing that I notice is that iLevelNames and iKnife are not arrays for strings. They are simply arrays (single cells). You need to make them arrays of strings.

Also, when working with strings, never assign a string directly to another string variable. Always use copy() or some other formatting function to do it.

Here is how I would do it.
Attached Files
File Type: sma Get Plugin or Get Source (fysiks.sma - 481 views - 17.2 KB)
__________________
fysiks is offline
ironskillz1
AlliedModders Donor
Join Date: Jul 2012
Location: Sweden
Old 06-13-2014 , 19:13   Re: Ini Help
Reply With Quote #9

Thanks but it still seems to have an problem.
It makes the last points loaded again when i didnt write it in the ini like this
Code:
L 06/14/2014 - 01:06:47: [Untitled.amxx] Loaded GSJailbreak/v_katana GSJailbreak/p_katana 1 Player1
L 06/14/2014 - 01:06:47: [Untitled.amxx] Loaded GSJailbreak/v_katana GSJailbreak/p_katana 2 Player2
L 06/14/2014 - 01:06:47: [Untitled.amxx] Loaded GSJailbreak/v_katana GSJailbreak/p_katana 3 Player3
L 06/14/2014 - 01:06:47: [Untitled.amxx] Loaded GSJailbreak/v_katana GSJailbreak/p_katana 4 Player4
L 06/14/2014 - 01:06:47: [Untitled.amxx] Loaded GSJailbreak/v_katana GSJailbreak/p_katana 5 Player5
L 06/14/2014 - 01:06:47: [Untitled.amxx] Loaded GSJailbreak/v_katana GSJailbreak/p_katana 6 Player6
L 06/14/2014 - 01:06:47: [Untitled.amxx] Loaded   6
Here is the updated code.
Attached Files
File Type: sma Get Plugin or Get Source (Untitled.sma - 471 views - 16.1 KB)
__________________
I have many private and unique plugins for Jailbreak and Hide'N'Seek. PM me for more info.

Pm me.

Check out my roulette site.

Last edited by ironskillz1; 06-13-2014 at 19:13.
ironskillz1 is offline
Send a message via Skype™ to ironskillz1
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-13-2014 , 19:38   Re: Ini Help
Reply With Quote #10

I can't really tell what is wrong without the exact .ini file you are using. Please upload that as well.

Also, another thing that I realized is that the prefix "i" is used for "integer" but you are using it for strings. This makes reading the code much harder. In pawn, strings are zero-terminated often denoted as "sz".

Also, the number of levels loaded will likely be needed in a global variable so that you index your arrays beyond where there is relevant data. You generally would replace your "number of levels variable" from your hard coded version with this new one.
__________________

Last edited by fysiks; 06-13-2014 at 19:42.
fysiks 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 13:07.


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