Raised This Month: $51 Target: $400
 12% 

CreateKeyValues() issue


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Doc-Holiday
AlliedModders Donor
Join Date: Jul 2007
Old 03-26-2013 , 18:55   CreateKeyValues() issue
Reply With Quote #1

So Im trying to create a KeyValue file that contains some info I need to save each map change.

Below is the code I use to create the KeyValue file.
g_szModConfigFilePath = cfg/votemod/nextmod.txt

PHP Code:
stock CreateModFile(iNextMod)
{
    new 
Handle:hDataPack GetArrayCell(g_hModArrayiNextMod);    
    
decl String:szModName[32], String:szModDir[PLATFORM_MAX_PATH], String:szModCfg[32], String:szModMap[32], String:szModPlugin[32];
    
    
/* Read the Mod Info from the data pack */
    
ReadPackString(hDataPackszModNamesizeof(szModName));
    
ReadPackString(hDataPackszModDirsizeof(szModDir));
    
ReadPackString(hDataPackszModCfgsizeof(szModCfg));
    
ReadPackString(hDataPackszModMapsizeof(szModMap));
    
ReadPackString(hDataPackszModPluginsizeof(szModPlugin));
    
    
CloseHandle(hDataPack);
    
    
/* Create the KeyValue File */
    
new Handle:hKeyValue CreateKeyValues("NextMod");
    
    
KvJumpToKey(hKeyValueszModNametrue);
    
KvSetString(hKeyValue"dir"szModDir);
    
KvSetString(hKeyValue"cfg"szModCfg);
    
KvSetString(hKeyValue"map"szModMap);
    
KvSetString(hKeyValue"plugin"szModPlugin);
    
KeyValuesToFile(hKeyValueg_szModConfigFilePath);
    
CloseHandle(hKeyValue);
    
    
/* Show Next Mod to Players */
    
PrintToChatAll("[%s] The next mod will be: %s"szModName);
    
PrintToServer("[%s] The next mod will be: %s"szModName);

And this is the output file. Its not creating the root of the KV but the section its creating has the correct info.

Code:
"Outlaws" //Menu Item
{
	"dir"		"outlaws"
	"cfg"		"outlaws-config.cfg"
	"map"		"outlaws-maps.txt"
	"plugin"	"outlaws-plugins.ini"
}

Last edited by Doc-Holiday; 03-26-2013 at 18:55.
Doc-Holiday is offline
Bimbo1
Senior Member
Join Date: Jan 2010
Location: brazil
Old 03-26-2013 , 19:23   Re: CreateKeyValues() issue
Reply With Quote #2

let me understand this. you are reading info from a data pack, writing it on a keyvalues file and, then, reading the keyvalues file. why don't you just use a data pack? handles and variables aren't destroyed on map change.
__________________
sie sind das essen und wir sind die jäger!
Bimbo1 is offline
Doc-Holiday
AlliedModders Donor
Join Date: Jul 2007
Old 03-26-2013 , 20:14   Re: Re: CreateKeyValues() issue
Reply With Quote #3

Quote:
Originally Posted by Bimbo1 View Post
let me understand this. you are reading info from a data pack, writing it on a keyvalues file and, then, reading the keyvalues file. why don't you just use a data pack? handles and variables aren't destroyed on map change.
Interesting. . And no I read a kv file to get the info pack it into the data pack. Then read it using the pack. I thought it wouldn't save on map changes.. If they don't change I can just store the next mod in s variable and access the array that way.. Thanks.


And back to my question... Why isn't it creating the root? Ill need it for the spawn point creator i am using for my deathmatch spawns on csgo.

Last edited by Doc-Holiday; 03-26-2013 at 20:29.
Doc-Holiday is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 03-27-2013 , 02:06   Re: CreateKeyValues() issue
Reply With Quote #4

Call KvRewind or KvGoBack before KeyValuesToFile.

Basically, you need a KvGoBack for every KvJumpToKey or KvGotoFirstSubKey.

From the docs for KeyValuesToFile: "The tree is dumped from the current position." meaning that if you don't go back, you don't get the root in there.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 03-27-2013 at 02:10.
Powerlord is offline
Doc-Holiday
AlliedModders Donor
Join Date: Jul 2007
Old 03-27-2013 , 03:04   Re: Re: CreateKeyValues() issue
Reply With Quote #5

Quote:
Originally Posted by Powerlord View Post
Call KvRewind or KvGoBack before KeyValuesToFile.

Basically, you need a KvGoBack for every KvJumpToKey or KvGotoFirstSubKey.

From the docs for KeyValuesToFile: "The tree is dumped from the current position." meaning that if you don't go back, you don't get the root in there.
So go to the first key and then rewind from there?
Doc-Holiday is offline
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 09:48.


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