Raised This Month: $214 Target: $400
 53% 

Arrays and all of that :)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
bally
Senior Member
Join Date: Aug 2015
Old 12-18-2015 , 20:16   Arrays and all of that :)
Reply With Quote #1

So, 3 months have passed since I touched any SM project. I basically forgot it all...

I have a few newbish-like questions for you guys, if someone can reply to me, it'd be just great.

If I want to store multiple int/float values in different array indexes, how should I create the variable, how should I store them inside that array, and how should I use them in the array?
( reading those values from a keyvalue. )

For example, if I wanted to fix this... ugly example:
Code:
public void readconfigs()
{
	char path_cfgs[PLATFORM_MAX_PATH];
	BuildPath(Path_SM, path_cfgs, sizeof(path_cfgs), "configs/traderoom/roompos.cfg");
	Handle kv = CreateKeyValues("roomPos");
	char buffer[PLATFORM_MAX_PATH];
	FileToKeyValues(kv, path_cfgs);
	
	if (!KvGotoFirstSubKey(kv))
	{
		LogError("[!] roompos .CFG File not found: %s", path_cfgs);
		CloseHandle(kv);
		return;
	}
	
	do {
		
		KvGetSectionName(kv, buffer, sizeof(buffer));
		
		if (StrEqual(buffer, "room1"))
		{
			r1tposx = KvGetFloat(kv, "tposx");
			r1tposy = KvGetFloat(kv, "tposy");
			r1tposz = KvGetFloat(kv, "tposz");
			
			r1ctposx = KvGetFloat(kv, "ctposx");
			r1ctposy = KvGetFloat(kv, "ctposy");
			r1ctposz = KvGetFloat(kv, "ctposz");
		}
		
		if (StrEqual(buffer, "room2"))
		{
			r2tposx = KvGetFloat(kv, "tposx");
			r2tposy = KvGetFloat(kv, "tposy");
			r2tposz = KvGetFloat(kv, "tposz");
			
			r2ctposx = KvGetFloat(kv, "ctposx");
			r2ctposy = KvGetFloat(kv, "ctposy");
			r2ctposz = KvGetFloat(kv, "ctposz");
		}
		if (StrEqual(buffer, "room3"))
		{
			r3tposx = KvGetFloat(kv, "tposx");
			r3tposy = KvGetFloat(kv, "tposy");
			r3tposz = KvGetFloat(kv, "tposz");
			
			r3ctposx = KvGetFloat(kv, "ctposx");
			r3ctposy = KvGetFloat(kv, "ctposy");
			r3ctposz = KvGetFloat(kv, "ctposz");
		}
		if (StrEqual(buffer, "room4"))
		{
			r4tposx = KvGetFloat(kv, "tposx");
			r4tposy = KvGetFloat(kv, "tposy");
			r4tposz = KvGetFloat(kv, "tposz");
			
			r4ctposx = KvGetFloat(kv, "ctposx");
			r4ctposy = KvGetFloat(kv, "ctposy");
			r4ctposz = KvGetFloat(kv, "ctposz");
		}
		
		
		
	} while (KvGotoNextKey(kv));
	
	CloseHandle(kv);
}

Also, would it be a way to add custom commands from a config? for example, I have a keyvalue with alot of commands, my plugin would read the commands and add them.

Thanks for reading my topic, have fun coding
__________________
Perhaps my lack of faith was my undoing,

Last edited by bally; 12-18-2015 at 20:19.
bally is offline
thecount
Veteran Member
Join Date: Jul 2013
Old 12-19-2015 , 16:36   Re: Arrays and all of that :)
Reply With Quote #2

Quote:
Originally Posted by bally View Post
If I want to store multiple int/float values in different array indexes, how should I create the variable, how should I store them inside that array, and how should I use them in the array?
Also, would it be a way to add custom commands from a config? for example, I have a keyvalue with alot of commands, my plugin would read the commands and add them.
I think you're looking for a multi-dimensional array.
PHP Code:
new Float:values[12][3]; 
In this example, there would be 12 different indexes with 3 different values. values[0][2] = third value of first index. But you can also use an adt_array if you are uncertain of the size you want and such.

As for adding custom commands from a config (if you mean Sourcemod commands and not server commands), you would have to find all the command names then RegConsoleCmd(CMD_NAME, CMD_CALLBACK, CMD_DESCRIPTION);

Last edited by thecount; 12-19-2015 at 16:36.
thecount is offline
Reply


Thread Tools
Display Modes

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 11:45.


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