Thread: [Solved] Read KeyValues File
View Single Post
GetRektByNoob
Member
Join Date: Nov 2018
Old 07-11-2019 , 09:58   Re: Read KeyValues File
Reply With Quote #5

Code:
#pragma semicolon 1

#define DEBUG

#include <sourcemod>
#include <sdktools>
#include <cstrike>

#define PLUGIN_AUTHOR 		"GetRektByNoob"
#define PLUGIN_VERSION		"1.00"
#define MAX_CASES_AMOUNT 	20
#define ITEM_NAME_LENGTH 	64
#define MAX_CASEID_LENGTH		25

#pragma newdecls required

char gPath_Store[PLATFORM_MAX_PATH]; // For Items.txt file

public Plugin myinfo =  {
	name = "",
	author = PLUGIN_AUTHOR, 
	description = "", 
	version = PLUGIN_VERSION, 
	url = "https://steamcommunity.com/profiles/765611988057643"
};

public void OnPluginStart() {
	BuildPath(Path_SM, gPath_Store, sizeof(gPath_Store), "configs/store/items.txt");
	RegConsoleCmd("sm_r", Command_Read);
}

public Action Command_Read(int client, int args) {
	KeyValues KV_Store = CreateKeyValues("Store");
	KV_Store.ImportFromFile(gPath_Store);
	KV_Store.GotoFirstSubKey();
	bool isDone, isDeepest;
	bool FoundInArray;
	ArrayList AL_CheckCatagorys = CreateArray(ByteCountToCells((ITEM_NAME_LENGTH)));
	char ItemName[520];

	do
	{
		if(KV_Store.NodesInStack() == 1) {
			char SectionName[ITEM_NAME_LENGTH];

			isDeepest = false;
			while(!isDeepest) {
				KV_Store.GetSectionName(SectionName, sizeof(SectionName));
				AL_CheckCatagorys.PushString(SectionName);
				isDeepest = !KV_Store.GotoFirstSubKey();
			}
		}

		KV_Store.GetSectionName(ItemName, sizeof(ItemName));
		PrintToChatAll(ItemName);
		
		if(!FoundInArray) {
			if(KV_Store.GotoNextKey() == false) {
				if(KV_Store.GoBack() == false) {
					isDone = true;
				}
			}
		}
	}
	while(!isDone);

	for(int i = 0; i < AL_CheckCatagorys.Length; i++) {
		char A[ITEM_NAME_LENGTH];
		AL_CheckCatagorys.GetString(i, A, sizeof(A));
		PrintToChatAll("\x07[#%d] \x01%s", i, A);
	}

	CloseHandle(KV_Store);
}

/*
"Store"
{	
	"A"
	{	
		"B"
		{
			"model" "models/chicken/chicken.mdl"
			"position" "50.0 0.0 0.0"
			"angles" "0.0 0.0 0.0"
			"idle" "idle01"
			"run" "run01"
			"price" "100"
			"type" "pet"
		}
		
		"C"
		{
			"D"
			{
				"E" 
				{
					"model" "models/chicken/chicken.mdl"
					"position" "50.0 0.0 0.0"
					"angles" "0.0 0.0 0.0"
					"idle" "idle01"
					"run" "run01"
					"price" "100"
					"type" "pet"
				}
				
				"F"
				{
					"G"
					{
						"model" "models/chicken/chicken.mdl"
						"position" "50.0 0.0 0.0"
						"angles" "0.0 0.0 0.0"
						"idle" "idle01"
						"run" "run01"
						"price" "100"
						"type" "pet"
					}
				}
			}
		}
		
		"H"
		{
			"model" "models/chicken/chicken.mdl"
			"position" "50.0 0.0 0.0"
			"angles" "0.0 0.0 0.0"
			"idle" "idle01"	
			"run" "run01"
			"price" "100"
			"type" "pet"
		}
	}

	"I"
	{
		"J"
		{
			"model" "models/chicken/chicken.mdl"
			"position" "50.0 0.0 0.0"
			"angles" "0.0 0.0 0.0"
			"idle" "idle01"
			"run" "run01"
			"price" "100"
			"type" "pet"
		}
		
		"K"
		{
			"L"
			{
				"model" "models/chicken/chicken.mdl"
				"position" "50.0 0.0 0.0"
				"angles" "0.0 0.0 0.0"
				"idle" "idle01"
				"run" "run01"
				"price" "100"
				"type" "pet"
			}
		}
	}
}

*/
this dosent read D, E , F ,G and L
GetRektByNoob is offline