Raised This Month: $32 Target: $400
 8% 

Help with KeyValues (I'm n00b)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
kratoss1812
Senior Member
Join Date: May 2018
Location: Romānia
Old 07-02-2018 , 07:12   Help with KeyValues (I'm n00b)
Reply With Quote #1

I wanted to make a bool that get a song directory from .cfg file and then emit to all clients on an evnt, similar to quake sounds.
I tried using key values for a better & easier configuration.. But I can't understant keyvalues.. maybe I have a problem XD

PHP Code:
bool GetSank(const char[] directory, const char[] quake_sound_name)
{
    
KeyValues kv = new KeyValues("Sound List");
    
    if(
KvJumpToKey(kvsound_directorytrue))
    {
        
KvGetString(kv"sound_name"sank_sound_name64"");
    }

Usage of the bool (I hope is correct) :
Code:
GetSound(directory, sound_name);
The string "directory" and "sound_name" form second code is already created..
I hope someone will have time for me. Thanks!

The .cfg file:
Code:
"Sank_List"
{
	"file" "sound/kratos/kill.mp3"
	"name" "kill"
}

Last edited by kratoss1812; 07-02-2018 at 07:17.
kratoss1812 is offline
DJ Tsunami
DJ Post Spammer
Join Date: Feb 2008
Location: The Netherlands
Old 07-02-2018 , 07:45   Re: Help with KeyValues (I'm n00b)
Reply With Quote #2

You need to build the path to your .cfg file, and then import the file into your KeyValues object.

For example:
PHP Code:
char path[PLATFORM_MAX_PATH];
BuildPath(Path_SMpathsizeof(path), "configs/sank_list.cfg");

KeyValues kv = new KeyValues("Sank_List");
kv.ImportFromFile(path); 
__________________
Advertisements | REST in Pawn - HTTP client for JSON REST APIs
Please do not PM me with questions. Post in the plugin thread.

Last edited by DJ Tsunami; 07-02-2018 at 07:48.
DJ Tsunami is offline
kratoss1812
Senior Member
Join Date: May 2018
Location: Romānia
Old 07-02-2018 , 09:10   Re: Help with KeyValues (I'm n00b)
Reply With Quote #3

Quote:
Originally Posted by DJ Tsunami View Post
You need to build the path to your .cfg file, and then import the file into your KeyValues object.

For example:
PHP Code:
char path[PLATFORM_MAX_PATH];
BuildPath(Path_SMpathsizeof(path), "configs/sank_list.cfg");

KeyValues kv = new KeyValues("Sank_List");
kv.ImportFromFile(path); 

PHP Code:
    char path[PLATFORM_MAX_PATH];
    
BuildPath(Path_SMpathsizeof(path), "configs/sank_list.cfg");    

    
KeyValues kv = new KeyValues("Sanks");
    
kv.ImportFromFile(path);

    if (!
kv.JumpToKey(sank_directory))
    {
        
delete kv;
        return 
false;
    }

    
kv.GetString("name"sank_sound_namemaxvalue); //line with error
    
delete kv;
    return 
true
error 035: argument type mismatch (argument 3);

is ok the usage?
kratoss1812 is offline
backwards
AlliedModders Donor
Join Date: Feb 2014
Location: USA
Old 07-02-2018 , 09:35   Re: Help with KeyValues (I'm n00b)
Reply With Quote #4

maxvalue has to be defined as an int, it's saying that you have it as a string or something other than an int
__________________
I highly recommend joining the SourceMod Discord Server for real time support.
backwards is offline
Psyk0tik
Veteran Member
Join Date: May 2012
Location: Homeless
Old 07-02-2018 , 09:45   Re: Help with KeyValues (I'm n00b)
Reply With Quote #5

You could just replace "maxvalue" with "sizeof(sank_sound_name)" unless you want to use a different value as the length of the string. Personally I would use sizeof(string) so that you don't have to change 2 values if you want to increase/decrease the size of the buffer you use.
__________________
Psyk0tik is offline
kratoss1812
Senior Member
Join Date: May 2018
Location: Romānia
Old 07-04-2018 , 15:47   Re: Help with KeyValues (I'm n00b)
Reply With Quote #6

Quote:
Originally Posted by DJ Tsunami View Post
You need to build the path to your .cfg file, and then import the file into your KeyValues object.

For example:
PHP Code:
char path[PLATFORM_MAX_PATH];
BuildPath(Path_SMpathsizeof(path), "configs/sank_list.cfg");

KeyValues kv = new KeyValues("Sank_List");
kv.ImportFromFile(path); 

I still get this error: error 035: argument type mismatch (argument 3)

PHP Code:
LoadSanks(const char[] Sank_Chat_Trigger, const char[] Sank_Directory, const char[] Sank_File_Name)
{
    
char file[PLATFORM_MAX_PATH];
    
BuildPath(Path_SMfilePLATFORM_MAX_PATH"configs/kratos/vip_sanks.cfg");
    

    
KeyValues kv = new KeyValues("Sank_List");
    
kv.ImportFromFile(file); 
    
    if (!
kv.JumpToKey(Sank_Chat_Trigger))
    {
        
delete kv;
        return 
false;
    }
    
kv.GetString("directory"Sank_Directory128); //error line
    
kv.GetString("file"Sank_File_Name128);

    return 
true;
}
/*
"Sank_List"
{
    "rekt"
    {
        "directory" "sound/sank/rekt.mp3"
        "file" "rekt.mp3"
    }
}
*/ 

Last edited by kratoss1812; 07-04-2018 at 16:19.
kratoss1812 is offline
xerox8521
Senior Member
Join Date: Sep 2011
Old 07-04-2018 , 16:36   Re: Help with KeyValues (I'm n00b)
Reply With Quote #7

Sank_Directory and Sank_File_Name are const which you are trying to write to. So remove the const for Sank_Directory and Sank_File_Name and it will work.
xerox8521 is offline
kratoss1812
Senior Member
Join Date: May 2018
Location: Romānia
Old 07-04-2018 , 17:48   Re: Help with KeyValues (I'm n00b)
Reply With Quote #8

Quote:
Originally Posted by xerox8521 View Post
Sank_Directory and Sank_File_Name are const which you are trying to write to. So remove the const for Sank_Directory and Sank_File_Name and it will work.
and the .cfg file will be like I want?
kratoss1812 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 22:32.


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