Raised This Month: $ Target: $400
 0% 

Solved Help with config file!


Post New Thread Reply   
 
Thread Tools Display Modes
KennYSwe
Member
Join Date: Nov 2016
Old 01-30-2017 , 16:17   Re: Help with config file!
Reply With Quote #11

PHP Code:
public Action:OnChatMessage(&ClientHandle:recipientsString:name[], String:message[])
{        
    
Chat[Client] = true;
    {
    
Format(nameMAXLENGTH_NAME" %s%s\x01 %s%s"Item_Color[ChatTag[Client]], Item_Name[ChatTag[Client]], Item_Color[NameColor[Client]], name);
    }

    return 
Plugin_Changed;

PHP Code:
{    
    
decl String:file[PLATFORM_MAX_PATH];
    
BuildPath(Path_SMfilesizeof(file), "configs/MarketItems.txt");
    new 
Handle:kv CreateKeyValues("MarketItems");
    
FileToKeyValues(kvfile);
    
    if (
KvGotoFirstSubKey(kv))
    {
        
decl String:Num[12], String:ItemName[256], String:ItemModel[256], String:ItemNumber[12], String:ItemPrice[256], String:ItemColor[256], String:itemtradeCheck[8];
            do
            {
                
KvGetSectionName(kvNumsizeof(Num));
                
KvGetString(kv"name"ItemNamesizeof(ItemName));
                
KvGetString(kv"model"ItemModelsizeof(ItemModel));
                
KvGetString(kv"type"ItemNumbersizeof(ItemNumber));
                
KvGetString(kv"price"ItemPricesizeof(ItemPrice));
                
KvGetString(kv"color"ItemColorsizeof(ItemColor));
                
KvGetString(kv"trade"itemtradeChecksizeof(itemtradeCheck));
                
CreateItem(StringToInt(Num), ItemNameItemModelKvGetNum(kv"type"), KvGetNum(kv"price"), KvGetNum(kv"color"), StrEqual(itemtradeCheck"true"));
            }
            while(
KvGotoNextKey(kv));
    } 
    
CloseHandle(kv);

PHP Code:
new NameColor[MAXPLAYERS+1];
new 
ChatTag[MAXPLAYERS+1];
new 
MsgColor[MAXPLAYERS+1];
new 
String:Item_Name[MAX_ITEM][256];
new 
String:Item_Model[MAX_ITEM][256];
new 
Item_Number[MAX_ITEM];
new 
Item_Price[MAX_ITEM];
new 
Item_Color[MAX_ITEM];
new 
Item[MAXPLAYERS+1][MAX_ITEM];
new 
bool:Item_trade[MAX_ITEM]; 

Last edited by KennYSwe; 01-30-2017 at 16:18.
KennYSwe is offline
KissLick
Veteran Member
Join Date: Nov 2012
Location: void
Old 01-30-2017 , 17:37   Re: Help with config file!
Reply With Quote #12

Global variable
PHP Code:
new Handle:g_hColors// global variable for color list 
New function for colors - call this function before loading the config (OnPluginStart ?)
PHP Code:
CreateColors() // create and fill color list
{
    if (
g_hColors == INVALID_HANDLE)
    {
        
g_hColors CreateTrie();
        
        
SetTrieString(g_hColors"color name 1""\x01");
        
SetTrieString(g_hColors"color name 2""\x02");
        
SetTrieString(g_hColors"color name 3""\x03");
        
SetTrieString(g_hColors"color name 4""\x04");
        
// .
        // .
        // .
    
}

And edit the config loading
PHP Code:
if (KvGotoFirstSubKey(kv))
{
    
decl String:Num[12], String:ItemName[256], String:ItemModel[256], String:ItemNumber[12], String:ItemPrice[256], String:ItemColorName[256], String:ItemColor[8], String:itemtradeCheck[8];
        do
        {
            
KvGetSectionName(kvNumsizeof(Num));
            
KvGetString(kv"name"ItemNamesizeof(ItemName));
            
KvGetString(kv"model"ItemModelsizeof(ItemModel));
            
KvGetString(kv"type"ItemNumbersizeof(ItemNumber));
            
KvGetString(kv"price"ItemPricesizeof(ItemPrice));
            
KvGetString(kv"color"ItemColorNamesizeof(ItemColorName));
            
KvGetString(kv"trade"itemtradeChecksizeof(itemtradeCheck));
            
            
strcopy(ItemColorsizeof(ItemColor), ItemColorName); // default value (if color name is not found)
            
            
if (g_hColors != INVALID_HANDLE)
            {
                
GetTrieString(g_hColorsItemColorNameItemColorsizeof(ItemColor)); // get color code from hashmap ("color name" -> "color code")
            
}
            
            
CreateItem(StringToInt(Num), ItemNameItemModelKvGetNum(kv"type"), KvGetNum(kv"price"), ItemColorStrEqual(itemtradeCheck"true")); // not sure about this ItemColor though...
        
}
        while(
KvGotoNextKey(kv));

CloseHandle(kv); 
edited
__________________
Plugins: TeamGames
Includes: Menu stocks, ColorVariables, DownloadTableConfig

> No help through PM, make a topic.

Last edited by KissLick; 01-30-2017 at 17:41.
KissLick is offline
KennYSwe
Member
Join Date: Nov 2016
Old 01-30-2017 , 18:08   Re: Help with config file!
Reply With Quote #13

Thanks KissLick, i'll test it tommorow!

And thanks to everyone else who helped me, now i have learned something new and it's gratefully that you want to help!
KennYSwe 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 18:47.


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