AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Solved Read KeyValues File (https://forums.alliedmods.net/showthread.php?t=317280)

GetRektByNoob 07-05-2019 17:26

Read KeyValues File
 
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

I am inevitable 07-07-2019 17:21

Re: Read KeyValues File
 
https://wiki.alliedmods.net/KeyValue...eMod_Scripting)

GetRektByNoob 07-09-2019 07:47

Re: Read KeyValues File
 
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.

I am inevitable 07-09-2019 08:25

Re: Read KeyValues File
 
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.

GetRektByNoob 07-11-2019 09:58

Re: Read KeyValues File
 
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

I am inevitable 07-11-2019 16:28

Re: Read KeyValues File
 
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.

GetRektByNoob 07-11-2019 19:16

Re: Read KeyValues File
 
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...

I am inevitable 07-12-2019 18:16

Re: Read KeyValues File
 
"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.

GetRektByNoob 07-12-2019 19:05

Re: Read KeyValues File
 
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.

I am inevitable 07-17-2019 13:25

Re: Read KeyValues File
 
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);
        }
    }




All times are GMT -4. The time now is 10:56.

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