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

KeyValues help


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Bis_
New Member
Join Date: Jul 2022
Old 07-26-2022 , 10:23   KeyValues help
Reply With Quote #1

Hello i would like to set the model from the config file when entering on the server, i have everything, but I don't know how to check if the player has the required flags (given in kv) to get model, could someone explain to me how to do it?

Code:
public void OnClientPutInServer(int client)
{
	kv.Rewind();
	char sModelID[16];
	char sFlags[40] = "";
	sFlags = "";
	IntToString(g_iModel[client], sModelID, sizeof(sModelID));
	if (!kv.JumpToKey(sClass))
		return;

	do 
	{
		kv.GetString("flags", sFlags, sizeof(sFlags));
		if (HasPlayerFlags(client, sFlags))
		{
			// if have required flags = set vip model
		}
		else 
		{
			// if not = set free model
		}
	} while(GotoNextKey());
}
Bis_ is offline
DiogoOnAir
Senior Member
Join Date: Jul 2018
Location: Portugal
Old 07-27-2022 , 11:11   Re: KeyValues help
Reply With Quote #2

If you are using flag letter or letters in the config you need to use FindFlagByChar function. If you have any more questions feel free to ask.
Anyway that question is asked quite a lot so there are other posts with a solution already, you can always check them, for some code examples.
__________________
I accept Private(Paid) plugins requests
If you like my job donate me Here
Feel free to add me on Steam
Feel free to add me on Discord DiogoOnAir | Config & Developer#7961
Check my website
If you want to buy any server, you can buy it from here!
Datacenters around the world!
DiogoOnAir is offline
Grafi_
Junior Member
Join Date: Apr 2022
Location: Poland
Old 07-27-2022 , 11:46   Re: KeyValues help
Reply With Quote #3

Quote:
Originally Posted by DiogoOnAir View Post
If you are using flag letter or letters in the config you need to use FindFlagByChar function. If you have any more questions feel free to ask.
Anyway that question is asked quite a lot so there are other posts with a solution already, you can always check them, for some code examples.

FindFlagByChar works like HasPlayerFlags in my code, I tried searching in other codes but I found nothing

and once again I would like to explain what I mean.

When the player enters the server, he may have the model of the previous player, which was a VIP and therefore I would like him to loop over all kv and check if the player has the required flag, if so, set the model, if not then go to the next key and check again.
Grafi_ is offline
Grey83
Veteran Member
Join Date: Dec 2014
Location: Ukraine
Old 07-27-2022 , 13:35   Re: KeyValues help
Reply With Quote #4

PHP Code:
public void OnClientPostAdminCheck(int client)
{
    if(
IsFakeClient(client))
        return;

    
char sModelID[16], sFlags[AdminFlags_TOTAL];
    
IntToString(g_iModel[client], sModelIDsizeof(sModelID));

    
kv.Rewind();
    if(!
kv.JumpToKey(sClass))
        return;

    
kv.GetString("flags"sFlagssizeof(sFlags));
    if(
ReadFlagString(sFlags) & GetUserFlagBits(client))
    {
        
// if have required flags = set vip model
    
}
    else
    {
        
// if not = set free model
    
}

__________________
Grey83 is offline
Grafi_
Junior Member
Join Date: Apr 2022
Location: Poland
Old 07-27-2022 , 14:24   Re: KeyValues help
Reply With Quote #5

Quote:
Originally Posted by Grey83 View Post
PHP Code:
public void OnClientPostAdminCheck(int client)
{
    if(
IsFakeClient(client))
        return;

    
char sModelID[16], sFlags[AdminFlags_TOTAL];
    
IntToString(g_iModel[client], sModelIDsizeof(sModelID));

    
kv.Rewind();
    if(!
kv.JumpToKey(sClass))
        return;

    
kv.GetString("flags"sFlagssizeof(sFlags));
    if(
ReadFlagString(sFlags) & GetUserFlagBits(client))
    {
        
// if have required flags = set vip model
    
}
    else
    {
        
// if not = set free model
    
}

Code:
void SetModelAfterJoin(int client)
{
	kv.Rewind();
	char sModelID[8};
	char sFlags[AdminFlags_TOTAL];
	int iClass = g_iClass[client];
	IntToString(iClass,sModelID, sizeof(sModelID));
	if (!kv.JumpToKey(sClass))
		return;

	kv.GetString("flags", sFlags, sizeof(sFlags))
	if (ReadFlagString(sFlags) & GetUserFlagBits(client)
	{
		g_iModel[client] = StringToInt(sModelID);
		return
	}

	else 
	{
		SetModelAfterJoin(client);
		kv.GotoNextKey();
	}
}
I know this code sucks but maybe it will give you what I mean


cfg file
HTML Code:
"Models"
{
    "1"
    {
    "model" "model path"
        "description" ""
    "flags" "p"
    }
    "2"
    {
    "model" "model path"
        "description" ""
    "flags" "a"
    }
    "3"
    {
    "model" "model path"
        "description" ""
    "flags" ""
    }
}
confused some random account (bis_) with mine

Last edited by Grafi_; 07-27-2022 at 14:48.
Grafi_ is offline
Grafi_
Junior Member
Join Date: Apr 2022
Location: Poland
Old 07-28-2022 , 08:45   Re: KeyValues help
Reply With Quote #6

done, thank you all for your help
Grafi_ 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 17:58.


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