Raised This Month: $ Target: $400
 0% 

Problem with keyvalues


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Matheus28
Senior Member
Join Date: Aug 2009
Old 11-20-2010 , 13:53   Problem with keyvalues
Reply With Quote #1

I still can't understand it, I tried to make this work, but I just can't.

How to copy the values from this keyvalues string to two arrays "mapsFile" and "mapsName"?
Code:
"maps"
{
	"cp_dustbowl"			"Dustbowl"
	"cp_gravelpit"			"Gravel Pit"
	"cp_steel"			"Steel"
	"pl_badwater"			"Badwater Basin"
	"pl_goldrush"			"Gold Rush"
	"pl_hoodoo_final"		"Hoodoo"
}
Matheus28 is offline
FaTony
Veteran Member
Join Date: Aug 2008
Old 11-20-2010 , 14:03   Re: Problem with keyvalues
Reply With Quote #2

KvGetSectionName for mapsFile and KvGetString for mapsName.
__________________
FaTony is offline
Matheus28
Senior Member
Join Date: Aug 2009
Old 11-20-2010 , 14:13   Re: Problem with keyvalues
Reply With Quote #3

KvGetString requires a key.

Last edited by Matheus28; 11-20-2010 at 14:28.
Matheus28 is offline
Silvers
SourceMod Plugin Approver
Join Date: Aug 2010
Location: SpaceX
Old 11-20-2010 , 14:20   Re: Problem with keyvalues
Reply With Quote #4

"cp_dustbowl" would be your key. http://wiki.alliedmods.net/KeyValues...d_Scripting%29
__________________
Silvers is offline
Matheus28
Senior Member
Join Date: Aug 2009
Old 11-20-2010 , 14:26   Re: Problem with keyvalues
Reply With Quote #5

The problem is: I don't know the key because it will change based on what the user puts there.

Also, it needs to be keyvalues, because this is only a part of the file, the rest is working fine.

Last edited by Matheus28; 11-20-2010 at 14:30.
Matheus28 is offline
FaTony
Veteran Member
Join Date: Aug 2008
Old 11-20-2010 , 14:42   Re: Problem with keyvalues
Reply With Quote #6

Pass NULL_STRING to get current section value.
__________________
FaTony is offline
Matheus28
Senior Member
Join Date: Aug 2009
Old 11-20-2010 , 14:49   Re: Problem with keyvalues
Reply With Quote #7

Doesn't work:

PHP Code:
if(!KvJumpToKey(kv"maps")){
    
ThrowError("List contains no maps");
}

new 
count=0;
do{
    new 
i=count++;
    
KvGetString(kvNULL_STRINGmapsName[i], sizeof(mapsName[]));
    
KvGetSectionName(kvmapsFile[i], sizeof(mapsFile[]));
}while(
KvGotoNextKey(kv));

KvGoBack(kv); 
Matheus28 is offline
Thrawn2
Veteran Member
Join Date: Apr 2009
Old 11-20-2010 , 14:49   Re: Problem with keyvalues
Reply With Quote #8

PHP Code:
#pragma semicolon 1
#include <sourcemod>

#define MAX_ENTRIES 64

new String:g_sMapFile[MAX_ENTRIES][64];
new 
String:g_sMapName[MAX_ENTRIES][64];
new 
g_iCount;

public 
OnPluginStart() {
    
ReadKV("mapnames.cfg");
}

public 
ReadKV(const String:sFile[]) {
    new 
String:sPath[PLATFORM_MAX_PATH];

    
BuildPath(Path_SMsPathsizeof(sPath), "configs/%s"sFile);

    if(!
FileExists(sPath)) {
        
LogMessage("File does not exist");
        return;
    }

    new 
Handle:hKV CreateKeyValues("maps");
    
FileToKeyValues(hKVsPath);

    
g_iCount 0;
    if(
KvGotoFirstSubKey(hKVfalse)) {
        do {
            new 
String:sKey[64];
            
KvGetSectionName(hKVsKeysizeof(sKey));

            new 
String:sValue[64];
            
KvGetString(hKVNULL_STRINGsValuesizeof(sValue));

            
strcopy(g_sMapFile[g_iCount], 64sKey);
            
strcopy(g_sMapName[g_iCount], 64sValue);
            
LogMessage("%s is %s"g_sMapFile[g_iCount], g_sMapName[g_iCount]);
            
g_iCount++;
        } while (
KvGotoNextKey(hKVfalse));
    } else {
        
LogMessage("No map names specified");
    }

    return;

-->
Code:
L 11/20/2010 - 20:47:46: [read_kv.smx] cp_dustbowl is Dustbowl
L 11/20/2010 - 20:47:46: [read_kv.smx] cp_gravelpit is Gravel Pit
L 11/20/2010 - 20:47:46: [read_kv.smx] cp_steel is Steel
L 11/20/2010 - 20:47:46: [read_kv.smx] pl_badwater is Badwater Basin
L 11/20/2010 - 20:47:46: [read_kv.smx] pl_goldrush is Gold Rush
L 11/20/2010 - 20:47:46: [read_kv.smx] pl_hoodoo_final is Hoodoo
__________________
einmal mit profis arbeiten. einmal.
Thrawn2 is offline
Matheus28
Senior Member
Join Date: Aug 2009
Old 11-20-2010 , 14:55   Re: Problem with keyvalues
Reply With Quote #9

It works! Thanks
Matheus28 is offline
rhelgeby
Veteran Member
Join Date: Oct 2008
Location: 0x4E6F72776179
Old 11-20-2010 , 17:00   Re: Problem with keyvalues
Reply With Quote #10

Just for future reference; this concept is called key/value iterating, which is used when you don't know the keys' names.
__________________
Richard Helgeby

Zombie:Reloaded | PawnUnit | Object Library
(Please don't send private messages for support, they will be ignored. Use the forum.)
rhelgeby is offline
Send a message via MSN to rhelgeby
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 16:03.


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