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

I can't read KeyValues corectly, help me!


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
kratoss1812
Senior Member
Join Date: May 2018
Location: Romānia
Old 04-28-2020 , 14:20   I can't read KeyValues corectly, help me!
Reply With Quote #1

For some reason my server console is spammed with KeyValues Error: LoadFromBuffer: missing { in file addons/sourcemod/configs/tags.cfg(*AdminGroupsColors*). The string from Steamid is read corectly but the colors are not. Below you have my code and my cfg.

PHP Code:
"Tags"
{
    
"76561198090457091"
    
{
        
"ctag"    "[{DARKRED}DEVELOPER{DEFAULT}]"
    
}
    
    
"AdminGroupsColors"
    
{
        
"FONDATOR"    "{DARKRED}"
        "ADMIN"        "{DARKBLUE}"
        "HELPER"    "{LIGHTGREEN}"
    
}
}


//"{DEFAULT}", "{DARKRED}", "{VIOLET}", "{DARKGREEN}", 
//"{LIGHTGREEN}", "{LIME}", "{LIGHTRED}", "{GREY}", 
//"{YELLOW}", "{LIGHTORANGE}", "{LIGHTBLUE}", 
//"{DARKBLUE}", "{PINK}", "{DARKORANGE}" 
__________________

Last edited by kratoss1812; 04-29-2020 at 14:47.
kratoss1812 is offline
8guawong
AlliedModders Donor
Join Date: Dec 2013
Location: BlackMarke7
Old 04-28-2020 , 23:21   Re: I can't read KeyValues corectly, help me!
Reply With Quote #2

Quote:
Originally Posted by kratoss1812 View Post
For some reason my server console is spammed with KeyValues Error: LoadFromBuffer: missing { in file addons/sourcemod/configs/tags.cfg(*AdminGroupsColors*). The string from Steamid is read corectly but the colors are not. Below you have my code and my cfg.

PHP Code:
#pragma semicolon 1

#define PLUGIN_AUTHOR "kRatoss"
#define PLUGIN_VERSION "1.00"

#include <sourcemod>
#include <sdktools>
#include <scp>
#include <vip_core>
#include <clientprefs>
#include <cstrike>

#pragma newdecls required

public Plugin myinfo 
{
    
name "Tags",
    
author PLUGIN_AUTHOR,
    
description "",
    
version PLUGIN_VERSION,
    
url ""
};

char g_sTabClantag[MAXPLAYERS 1][32], g_sChatClantag[MAXPLAYERS 1][32], g_sCustomChatClantag[MAXPLAYERS 1][32], g_sGroupColor[32], g_sConfigfile[1024];
static const 
char g_sVIPFeature[][] =  { "ChatTags_Prefix""ChatTags_Prefix_Color""ChatTags_Name_Color""ChatTags_TextColor" };
char g_sVIPConf[4][64];

KeyValues hKV;
Handle g_hDataBase INVALID_HANDLE;

enum{
    
PREFIX 0,
    
PREFIX_COLOR 1,
    
NAME_COLOR 2,
    
TEXT_COLOR 3
}

public 
void OnPluginStart()
{
    
RegConsoleCmd("sm_tag"CommandTags"");
    
RegConsoleCmd("sm_ctag"CommandCTag"");
    
    
SQL_TConnect(ConnectToDataBase"tags");
    
    if(
VIP_IsVIPLoaded())
        
VIP_OnVIPLoaded();
}

public 
void VIP_OnVIPLoaded()
{
    
VIP_RegisterFeature(g_sVIPFeature[PREFIX], STRINGHIDE);
    
VIP_RegisterFeature(g_sVIPFeature[PREFIX_COLOR], STRINGHIDE);
    
VIP_RegisterFeature(g_sVIPFeature[NAME_COLOR], STRINGHIDE);
    
VIP_RegisterFeature(g_sVIPFeature[TEXT_COLOR], STRINGHIDE);
}

public 
void OnPluginEnd()
{
    
VIP_UnregisterFeature(g_sVIPFeature[PREFIX]);
    
VIP_UnregisterFeature(g_sVIPFeature[PREFIX_COLOR]);
    
VIP_UnregisterFeature(g_sVIPFeature[NAME_COLOR]);
    
VIP_UnregisterFeature(g_sVIPFeature[TEXT_COLOR]);
}

public 
int ConnectToDataBase(Handle hOwnerHandle hHandlechar [] sErrorany Data)
{
    if(
hHandle == INVALID_HANDLE)
    {
        
SetFailState("Databases dont work. Error: %s"sError);
    }
    else
    {
        
g_hDataBase hHandle;
        
kQuery(g_hDataBase"CREATE TABLE IF NOT EXISTS `tags` (`steamid` varchar(32) PRIMARY KEY NOT NULL, `chat_tag` varchar(128), `tab_tag` varchar(128));""ConnectToDataBase");
    }
}

public 
Action CommandTags(int Clientint Args)
{
    if(!
IsValidClient(Client))
        return 
Plugin_Handled;
    
    
Menu menu = new Menu(TabHandler);
    
AdminId ClientAcces GetUserAdmin(Client);
    
    
menu.SetTitle("Selecteaza Un Tag");
    
    if(!
VIP_IsClientVIP(Client) && !ClientAcces){
        
menu.AddItem("""Nu Ai Nici Un Tag Disponibil \n Contacteaza Un Owner Pentru \n A Cumpara VIP Sau Admin \n Foloseste Comanda !owner");
    }
    
    if(
VIP_IsClientVIP(Client)){
        
menu.AddItem("vip""Tag De VIP");
    }
    
    if(
ClientAcces){
        
menu.AddItem("admin""Tag De Admin");
    }
    
    if(
VIP_IsClientVIP(Client) && ClientAcces){
        
menu.AddItem("both""Tag De VIP + Admin");
    }
    
    
menu.Display(ClientMENU_TIME_FOREVER);
    
    return 
Plugin_Handled;
}

public 
int TabHandler(Handle menuMenuAction actionsint iClientint iSelection)
{
    switch(
actions)
    {
        case 
MenuAction_Select:
        {
            
char sAdminTag[32], sAdminGroup[32], sBoth[32], item[12];
            
GetMenuItem(menuiSelectionitemsizeof(item));
            
AdminId ClientAccess GetUserAdmin(iClient);
            
int AdminGroupsCount GetAdminGroupCount(ClientAccess);
            
            for (
int x 0AdminGroupsCountx++)
            {
                if(
GetAdminGroup(ClientAccessxsAdminGroupsizeof(sAdminGroup)) != INVALID_GROUP_ID){
                    
FormatEx(sAdminTagsizeof(sAdminTag), "★ %s"sAdminGroup);
                    
FormatEx(sBothsizeof(sBoth), "★ VIP %s"sAdminGroup);
                }
            }
            
            if(
strcmp(item"vip") == 0){
                
CS_SetClientClanTag(iClient"★ VIP");
                
strcopy(g_sTabClantag[iClient], sizeof(g_sTabClantag[]), "★ VIP");
            }
            
            else if(
strcmp(item"admin") == 0){
                
CS_SetClientClanTag(iClientsAdminTag);
                
strcopy(g_sTabClantag[iClient], sizeof(g_sTabClantag[]), sAdminTag);
            }
            
            else if(
strcmp(item"both") == 0){
                
CS_SetClientClanTag(iClientsBoth);
                
strcopy(g_sTabClantag[iClient], sizeof(g_sTabClantag[]), sBoth);
            }
            
            
char Steam[64], sQuery[1000];
            
GetClientAuthId(iClientAuthId_SteamID64Steamsizeof(Steam));
            
Format(sQuerysizeof(sQuery), "UPDATE tags SET tab_tag = '%s' WHERE steamid = '%s';"g_sTabClantag[iClient], Steam);
            
kQuery(g_hDataBasesQuery"TabHandler(122)");
        }
        
        case 
MenuAction_Cancel:
        {
            
CloseHandle(menu);
        }
    }
}

public 
void OnClientPostAdminCheck(int Client)
{
    if(
IsValidClient(Client) && g_hDataBase != INVALID_HANDLE)
    {
        
LoadConfig();
        if(
hKV == INVALID_HANDLE)
            
SetFailState("invalid hndl");
        
/*
            Load From DataBase & Insert New Players
        */
        
char szQuery[500], szSteamID[32], szError[255];
        
GetClientAuthId(ClientAuthId_SteamID64szSteamIDsizeof(szSteamID));
        
Format(szQuerysizeof(szQuery), "SELECT tab_tag, chat_tag FROM tags WHERE steamid = '%s';"szSteamID);
        
DBResultSet hQuery SQL_Query(g_hDataBaseszQuery); 
        
        if(
hQuery == null){
            
SQL_GetError(g_hDataBaseszErrorsizeof(szError));
            
SetFailState("Query Error @ OnClientPostAdminCheck : %s"szError);
        }
        else{
            
SQL_FetchRow(hQuery);
            if(
SQL_GetRowCount(hQuery) == 0/* Check if it's the first time a player connects to server */{
                
char szInsertQuery[1000];
                
Format(szInsertQuerysizeof(szInsertQuery), "INSERT INTO tags(steamid, tab_tag, chat_tag) VALUES('%s', 'none', 'none');"szSteamID);
                
kQuery(g_hDataBaseszInsertQuery"OnClientPostAdminCheck");        
            }
            else{
                
SQL_FetchString(hQuery0g_sTabClantag[Client], 32);
                
SQL_FetchString(hQuery1g_sChatClantag[Client], 32);
            }
            
delete hQuery;
        }
        
        
/*
            Load Custom ChatTags
        */
        
char Steam[64];
        
GetClientAuthId(ClientAuthId_SteamID64Steamsizeof(Steam));
        
        if(
hKV.JumpToKey(Steam)){
            
hKV.GetString("ctag"g_sCustomChatClantag[Client], PLATFORM_MAX_PATH);    
            
//ProcessColors(g_sCustomChatClantag[Client], PLATFORM_MAX_PATH);
        
}
        
        
/*
            Load VIP Conf
        */
        
if(VIP_IsClientVIP(Client)){
            
            
VIP_GetClientFeatureString(Clientg_sVIPFeature[PREFIX], g_sVIPConf[PREFIX], 64);
            
            
VIP_GetClientFeatureString(Clientg_sVIPFeature[PREFIX_COLOR], g_sVIPConf[PREFIX_COLOR], 64);
            
//ProcessColors(g_sVIPConf[PREFIX_COLOR], 64);
            
            
VIP_GetClientFeatureString(Clientg_sVIPFeature[NAME_COLOR], g_sVIPConf[NAME_COLOR], 64);
            
//ProcessColors(g_sVIPConf[NAME_COLOR], 64);
            
            
VIP_GetClientFeatureString(Clientg_sVIPFeature[TEXT_COLOR], g_sVIPConf[TEXT_COLOR], 64);
            
//ProcessColors(g_sVIPConf[TEXT_COLOR], 64);
        
}
        
        
/*
            Load the Group Color 
        */
        
char sAdminGroup[64];
        
AdminId ClientAcces GetUserAdmin(Client);
        if(
ClientAcces){
            
int AdminGroupsCount GetAdminGroupCount(ClientAcces);
            
            for (
int x 0AdminGroupsCountx++)
            {
                if(
GetAdminGroup(ClientAccesxsAdminGroupsizeof(sAdminGroup)) == INVALID_GROUP_ID){
                    continue;
                }
            }
            if(
hKV.JumpToKey("AdminGroupsColors")){
                
hKV.GetString(sAdminGroupg_sGroupColor[Client], PLATFORM_MAX_PATH);
            }
        }
        
        
hKV.Rewind();
        
delete hKV;
    }
}

void ProcessColors(char[] szBufferint iSize)
{
    static 
char pName[][] = {     "{DEFAULT}""{DARKRED}""{VIOLET}""{DARKGREEN}", \
                                
"{LIGHTGREEN}""{LIME}""{LIGHTRED}""{GREY}", \
                                
"{YELLOW}""{LIGHTORANGE}""{LIGHTBLUE}", \
                                
"{DARKBLUE}""{PINK}""{DARKORANGE}" };

    static 
char pCode[][] = {     "\x01""\x02""\x03""\x04""\x05""\x06", \
                                
"\x07""\x08""\x09""\x10", \
                                
"\x0B""\x0C""\x0E""\x0F" };
    static 
int iIter 0;

    for (
iIter 0iIter sizeof(pName); iIter++)
    {
        
ReplaceString(szBufferiSizepName[iIter], pCode[iIter], false);
    }
}

public 
Action CommandCTag(int Clientint Args)
{
    if(!
IsValidClient(Client))
        return 
Plugin_Handled;
    
    
Menu menu = new Menu(ChatHandler);
    
AdminId ClientAcces GetUserAdmin(Client);
    
    
menu.SetTitle("Selecteaza Un CTag");
    
    if(!
VIP_IsClientVIP(Client) && !ClientAcces){
        
menu.AddItem("""Nu Ai Nici Un Tag Disponibil \n Contacteaza Un Owner Pentru \n A Cumpara VIP, Admin sau Chat Custom \n Foloseste Comanda !owner");
    }
    
    if(
VIP_IsClientVIP(Client)){
        
menu.AddItem("vip""Tag De VIP");
    }
    
    if(
ClientAcces){
        
menu.AddItem("admin""Tag De Admin");
    }
    if(
VIP_IsClientVIP(Client) && ClientAcces){
        
menu.AddItem("both""Tag De VIP + Admin");
    }
    if(
strlen(g_sCustomChatClantag[Client]) > 0){
        
menu.AddItem("custom""Tag Custom");
    }
    
    
menu.Display(ClientMENU_TIME_FOREVER);
    
    return 
Plugin_Handled;
}

public 
int ChatHandler(Handle menuMenuAction actionsint iClientint iSelection)
{
    switch(
actions)
    {
        case 
MenuAction_Select:
        {
            
char sAdminTag[32], sAdminGroup[32], sBoth[128], item[12];
            
GetMenuItem(menuiSelectionitemsizeof(item));
            
AdminId ClientAccess GetUserAdmin(iClient);
            
int AdminGroupsCount GetAdminGroupCount(ClientAccess);
            
            for (
int x 0AdminGroupsCountx++)
            {
                if(
GetAdminGroup(ClientAccessxsAdminGroupsizeof(sAdminGroup)) != INVALID_GROUP_ID){
                    
FormatEx(sAdminTagsizeof(sAdminTag), "★ %s"sAdminGroup);
                    
FormatEx(sBothsizeof(sBoth), "★ %s %s %s %s"g_sVIPConf[PREFIX_COLOR], g_sVIPConf[PREFIX], g_sGroupColor[iClient], sAdminGroup);
                }
            }
            
            if(
strcmp(item"vip") == 0){
                
strcopy(g_sChatClantag[iClient], sizeof(g_sChatClantag[]), g_sVIPConf[PREFIX]);
            }
            
            else if(
strcmp(item"admin") == 0){
                
strcopy(g_sChatClantag[iClient], sizeof(g_sChatClantag[]), sAdminTag);
            }
            
            else if(
strcmp(item"both") == 0){
                
strcopy(g_sChatClantag[iClient], sizeof(g_sChatClantag[]), sBoth);
            }
            else if(
strcmp(item"custom") == 0){
                
strcopy(g_sChatClantag[iClient], sizeof(g_sChatClantag[]), g_sCustomChatClantag[iClient]);
            }
            
            
char Steam[64], sQuery[1000];
            
GetClientAuthId(iClientAuthId_SteamID64Steamsizeof(Steam));
            
Format(sQuerysizeof(sQuery), "UPDATE tags SET chat_tag = '%s' WHERE steamid = '%s';"g_sChatClantag[iClient], Steam);
            
kQuery(g_hDataBasesQuery"ChatHandler");
        }
        
        case 
MenuAction_Cancel:
        {
            
CloseHandle(menu);
        }
    }
}

public 
void OnMapStart()
{
    
CreateTimer(10.0CheckClanTags_TIMER_REPEAT); 
    
LoadConfig();
}

public 
Action CheckClanTags(Handle pTimer)
{
    
int client_index;
    for (
client_index 0client_index <= MaxClientsclient_index++){
        if(
IsValidClient(client_index)){
            
CS_SetClientClanTag(client_indexg_sTabClantag[client_index]);
        }
    }
}

stock bool IsValidClient(int client)

    if (
client <= || client MaxClients || !IsClientConnected(client) || client 0)
    {
        return 
false
    }
    return 
IsClientInGame(client); 
}

void kQuery(Handle pDatabase, const char[] szQuery, const char[] Function)
{
    if (!
SQL_FastQuery(pDatabaseszQuery))
    {
        
char szError[255];
        
SQL_GetError(pDatabaseszErrorsizeof(szError));
        
SetFailState("MySQL Error @%s : %s", Function, szError);
    }
}

void LoadConfig()
{
    
BuildPath(Path_SMg_sConfigfile1024"configs/tags.cfg");
    
    if(!
FileExists(g_sConfigfile))
        
SetFailState("Can not find config file \"%s\"!"g_sConfigfile);
        
    
hKV CreateKeyValues("Tags");
    
hKV.ImportFromFile(g_sConfigfile);
}

public 
Action OnChatMessage(int &ClientHandle recipientschar[] szNamechar[] szText)
{
    if(
IsValidClient(Client))
    {
        
ProcessColors(g_sVIPConf[TEXT_COLOR], PLATFORM_MAX_PATH);
        
ProcessColors(g_sChatClantag[Client], PLATFORM_MAX_PATH);
        
        if(
VIP_IsClientVIP(Client)){
            
Format(szTextMAXLENGTH_NAME"%s %s"g_sVIPConf[TEXT_COLOR], szText);
        }
        
Format(szNameMAXLENGTH_NAME"%s %s"g_sChatClantag[Client], szName);
        return 
Plugin_Changed;
    }
    
    return 
Plugin_Continue

PHP Code:
"Tags"
{
    
"76561198090457091"
    
{
        
"ctag"    "[{DARKRED}DEVELOPER{DEFAULT}]"
    
}
    
    
"AdminGroupsColors"
    
{
        
"FONDATOR"    "{DARKRED}"
        "ADMIN"        "{DARKBLUE}"
        "HELPER"    "{LIGHTGREEN}"
    
}
}


//"{DEFAULT}", "{DARKRED}", "{VIOLET}", "{DARKGREEN}", 
//"{LIGHTGREEN}", "{LIME}", "{LIGHTRED}", "{GREY}", 
//"{YELLOW}", "{LIGHTORANGE}", "{LIGHTBLUE}", 
//"{DARKBLUE}", "{PINK}", "{DARKORANGE}" 
Is your config saved in UTF-8 without BOM? If not do it
__________________
8guawong is offline
Reply


Thread Tools
Display Modes

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:11.


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