Raised This Month: $68 Target: $400
 17% 

Solved Read KeyValues File


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
GetRektByNoob
Member
Join Date: Nov 2018
Old 07-05-2019 , 17:26   Read KeyValues File
Reply With Quote #1

hey guys,
im working on a plugin and i need to read the items.txt file from Zephyrus's store plugin
i tried looking at the function he made to read the file but i dont understand anything that is going on on there... here is the function https://pastebin.com/gZqHFFTS can someone explain how the function works or if someone has more simpler code that does the same (go trough all the keys and sections in the file) and can send it here it would be amazing!

thanks for all the replys.

EDIT : im doing other idea

Last edited by GetRektByNoob; 07-31-2019 at 10:45.
GetRektByNoob is offline
I am inevitable
Member
Join Date: May 2019
Location: 0xA6DA34
Old 07-07-2019 , 17:21   Re: Read KeyValues File
Reply With Quote #2

https://wiki.alliedmods.net/KeyValue...eMod_Scripting)
__________________
I do make plugins upon requests, so hit me up on discord if you're interested: cucklord67xD#3823
I am inevitable is offline
GetRektByNoob
Member
Join Date: Nov 2018
Old 07-09-2019 , 07:47   Re: Read KeyValues File
Reply With Quote #3

first, thanks for replying really appreciate it.
second, I know how to use the kv class the problem is that I'm not succeeding in writing code that dose what I want (read all the file) and that's why I asked help on here.

Last edited by GetRektByNoob; 07-09-2019 at 07:48.
GetRektByNoob is offline
I am inevitable
Member
Join Date: May 2019
Location: 0xA6DA34
Old 07-09-2019 , 08:25   Re: Read KeyValues File
Reply With Quote #4

Yeah, well maybe show me what you've tried and I'll tell you what you did wrong. Reading code that you don't understand will not help you, it'll just confuse your brain even more and you'll get the idea of this being very difficult and give up.

It's important to start with the basics, I mean, you can't grow I tree without roots.
__________________
I do make plugins upon requests, so hit me up on discord if you're interested: cucklord67xD#3823
I am inevitable is offline
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
I am inevitable
Member
Join Date: May 2019
Location: 0xA6DA34
Old 07-11-2019 , 16:28   Re: Read KeyValues File
Reply With Quote #6

Nope, it only reads the sections, and the FIRST sub keys.

PHP Code:
"MyFile"
{
    
"section" // GetSectionName to get here
    
{
        
"first sub key" // GoToFirstSubKey to get here
        
{
            
"second sub key" // Now, while we're on first sub key, we can use GoToFirstSubKey again to get here
            
{
            
            }
        }
    }

Try to use this sense.

GoToFirstSubKey will get you deeper in the file.
__________________
I do make plugins upon requests, so hit me up on discord if you're interested: cucklord67xD#3823
I am inevitable is offline
GetRektByNoob
Member
Join Date: Nov 2018
Old 07-11-2019 , 19:16   Re: Read KeyValues File
Reply With Quote #7

yes I know that... do you think I'm new to this? well I'm not, the only problem is that I can't keep doing GotoFirstKey every time I go to next, i'm using this logic if you saw my code...

Last edited by GetRektByNoob; 07-12-2019 at 06:29.
GetRektByNoob is offline
I am inevitable
Member
Join Date: May 2019
Location: 0xA6DA34
Old 07-12-2019 , 18:16   Re: Read KeyValues File
Reply With Quote #8

"do you think I'm new to this?", Okay, then you clearly should see what's wrong and you would probably be able to solve the issue yourself.

Drop the attitude, I'm telling you what's wrong, and you're not using this logic.


Anyhow, if your ass 's too lazy, get rid of the sub-sub-keys. I don't see why you would do that.
__________________
I do make plugins upon requests, so hit me up on discord if you're interested: cucklord67xD#3823

Last edited by I am inevitable; 07-12-2019 at 18:19.
I am inevitable is offline
GetRektByNoob
Member
Join Date: Nov 2018
Old 07-12-2019 , 19:05   Re: Read KeyValues File
Reply With Quote #9

first i didnt want to offend and im sorry if i did, i wish i could remove the sub sub key but this file is an user input and they can add as much as they want sub sections sence the store plugin allows it,
also if ur doing GetSectionName at the begging it wont go to the first subkey like you said and i am using your logic but no all they time im using it only when
Code:
kv.NodesInStack == 1
and i cant do GotoFirstSubKey every GotoNext bc its going to make a infinite loop of me getting back a forth between 2 sections.
GetRektByNoob is offline
I am inevitable
Member
Join Date: May 2019
Location: 0xA6DA34
Old 07-17-2019 , 13:25   Re: Read KeyValues File
Reply With Quote #10

PHP Code:
void RefreshClientWeapons(int iClient)
{
    for (
int i 44i++)
    {
        
int iWeapon_Entity_Index GetPlayerWeaponSlot(iClienti);
        
        if (
iWeapon_Entity_Index != -1)
        {
            
RemovePlayerItem(iClientiWeapon_Entity_Index);
            
            
AcceptEntityInput(iWeapon_Entity_Index"Kill");
            
            
char sWeapon_Classname[32];
            
            
GetEntityClassname(iWeapon_Entity_IndexsWeapon_Classnamesizeof(sWeapon_Classname));
            
            
GivePlayerItem(iClientsWeapon_Classname);
        }
    }

__________________
I do make plugins upon requests, so hit me up on discord if you're interested: cucklord67xD#3823
I am inevitable 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 21:52.


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