Raised This Month: $ Target: $400
 0% 

Key value help


Post New Thread Reply   
 
Thread Tools Display Modes
dirka_dirka
Veteran Member
Join Date: Nov 2009
Old 08-03-2010 , 11:11   Re: Key value help
Reply With Quote #11

the code i posted is similar to something used in multiple plugins.. the do { } while loop is the primary difference. the other plugin i can think of off hand is witch crown stats - that plugin, as mentioned above, tracks the number of entries and uses a for loop to get all the info.

if its not printing anything, then perhaps its not reading in the file. where exactly is the file stored? you dont have a path..

how about you replace the FileToKeyValues(hKV, "sm_tlist.ini"); line with..
PHP Code:
decl String:sBannedDB[PLATFORM_MAX_PATH];
BuildPath(Path_SMsBannedDBPLATFORM_MAX_PATH"configs/sm_tlist.ini");
FileToKeyValues(hKVsBannedDB); 
and make sure the sm_tlist.ini is in sourcemod/configs
dirka_dirka is offline
Steell
SourceMod Donor
Join Date: Mar 2009
Old 08-03-2010 , 14:11   Re: Key value help
Reply With Quote #12

Code:
PHP Code:
#pragma semicolon 1
#include <sourcemod>
 
public OnPluginStart()
{
    
RegConsoleCmd("tester"Tester);
}
 
public 
Action:Tester(client,args)
{
    
decl String:szAuth[32];
    
decl String:szReason[64];
    new 
Handle:hKV CreateKeyValues("Tlist");
    
FileToKeyValues(hKV"sm_tlist.ini");
    if (
KvGotoFirstSubKey(hKV))
    {
        if (
KvGotoFirstSubKey(hKV))
        {
            do
            {
                
KvGetSectionName(hKVszAuthsizeof(szAuth));
                
KvGetString(hKV"reason"szReasonsizeof(szReason));
                
PrintToChatAll("STEAM: %s REASON: %s"szAuthszReason);
            } while (
KvGotoNextKey(hKV));
        }
    } 
    
CloseHandle(hKV);

INI
Code:
"Tlist"
{
    "Banned"
    {
        "STEAM_0:0:1234"
        {
            "reason"         "free killing"
        }
        "STEAM_0:0:4321"
        {
            "reason"         "gun planting"
        }
    }
}
Your ini should be in the server's root directory. If it's somewhere else, see dirka's post above mine.

Last edited by Steell; 08-03-2010 at 14:49.
Steell is offline
Greyscale
SourceMod Plugin Approver
Join Date: Dec 2007
Location: strYoMommasHouse[you];
Old 08-03-2010 , 17:11   Re: Key value help
Reply With Quote #13

That do/while loop is unnecessary. There is only 1 key, and if there are multiple then you are just getting the value of "reason" multiple times.

Code:
KvGetSectionName(hKV, szAuth, sizeof(szAuth));
KvGetString(hKV, "reason", szReason, sizeof(szReason));
KvGetString(hKV, "nextkey", string, sizeof(string));
KvGetString(hKV, "nextkey2", string2, sizeof(string2));
// etc
PrintToChatAll("STEAM: %s REASON: %s", szAuth, szReason);

Not to mention that's only looking in the first steam id.
Use KvJumpToKey to jump to the steam id you want.
__________________
Greyscale is offline
Steell
SourceMod Donor
Join Date: Mar 2009
Old 08-03-2010 , 17:33   Re: Key value help
Reply With Quote #14

Well this is what my code outputs:
Code:
L 08/03/2010 - 17:33:15: [tester.smx] STEAM: STEAM_0:0:1234 REASON: free killing
L 08/03/2010 - 17:33:15: [tester.smx] STEAM: STEAM_0:0:4321 REASON: gun planting
(I changed PrintToChatAll to LogMessage so I can read it from the console).

I interpreted it as he wanted to iterate through the KV file and then print the steam id and reason for each section under "Banned".

Here's the same code with some documentation:
PHP Code:
#pragma semicolon 1
#include <sourcemod>
 
public OnPluginStart()
{
    
RegConsoleCmd("tester"Tester);
}
 
public 
Action:Tester(client,args)
{
    
//buffers
    
decl String:szAuth[32];
    
decl String:szReason[64];
    new 
Handle:hKV CreateKeyValues("Tlist");
    
FileToKeyValues(hKV"sm_tlist.ini");
    if (
KvGotoFirstSubKey(hKV)) //Take us inside "Banning" section
    
{
        if (
KvGotoFirstSubKey(hKV)) //Take us inside the first SteamID.
        
{
            do
            {
                
KvGetSectionName(hKVszAuthsizeof(szAuth)); //Get the SteamID
                
KvGetString(hKV"reason"szReasonsizeof(szReason)); //Get the reason for banning.
                
PrintToChatAll("STEAM: %s REASON: %s"szAuthszReason); //Print the message
            
} while (KvGotoNextKey(hKV)); //Goto the next SteamID
        
}
    } 
    
CloseHandle(hKV);


Last edited by Steell; 08-03-2010 at 17:35.
Steell is offline
bestmeth0ds
SourceMod Donor
Join Date: Jul 2010
Old 08-04-2010 , 06:38   Re: Key value help
Reply With Quote #15

Wow guys. Thank your so much for all your help. I will look over this and see what I get. You guys have been a really big help. I had no idea I was getting into something so complicated.

Last edited by bestmeth0ds; 08-04-2010 at 06:41.
bestmeth0ds is offline
Send a message via Skype™ to bestmeth0ds
bestmeth0ds
SourceMod Donor
Join Date: Jul 2010
Old 08-04-2010 , 06:55   Re: Key value help
Reply With Quote #16

I tried and nothing appeared in chat??? Did your method only work with log message?

Edit: Nvm I had to use Drika's code to build the filepath. Which is wierd because I never had to before.

Last edited by bestmeth0ds; 08-04-2010 at 07:06.
bestmeth0ds is offline
Send a message via Skype™ to bestmeth0ds
bestmeth0ds
SourceMod Donor
Join Date: Jul 2010
Old 08-04-2010 , 07:47   Re: Key value help
Reply With Quote #17

Ok now what I would like to do is either on plugin start or on client connect check if a user is on the ban list and and if they connect it shows to them the reason they are banned in chat. So would I want to make some kind of boolean and apply it to the users in sm_tlsit.ini? And I am trying to makeit so you can type sm_tlsit and it writes to sm_tlist.ini .... Also how do I donate?

Edit: Nvm found donate button on front page.... = )

Last edited by bestmeth0ds; 08-04-2010 at 07:49.
bestmeth0ds is offline
Send a message via Skype™ to bestmeth0ds
Monkeys
Veteran Member
Join Date: Jan 2010
Old 08-04-2010 , 11:56   Re: Key value help
Reply With Quote #18

PHP Code:
#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
static String:sBannedDB[PLATFORM_MAX_PATH];
 
public 
OnPluginStart()
{
    
BuildPath(Path_SMsBannedDBPLATFORM_MAX_PATH"configs/sm_tlist.ini"); //Build the path and store it in the global variable sBannedDB
    
RegConsoleCmd("sm_tlist",Command_tlist);
}

public 
OnClientPutInServer(Client)
{
    
decl String:Auth[64];
    
GetClientAuthString(Client,Auth,sizeof(Auth));
    
ShowBanReasonOfID(Client,Auth);
}

public 
bool:ShowBanReasonOfID(Client,const String:Auth[])
{
    new 
bool:Match false;
    
decl String:szAuth[32];
    
decl String:szReason[64];
    new 
Handle:hKV CreateKeyValues("Tlist");
    
FileToKeyValues(hKVsBannedDB);
    if (
KvGotoFirstSubKey(hKV)) //Take us inside "Banning" section
    
{
        if (
KvGotoFirstSubKey(hKV)) //Take us inside the first SteamID.
        
{
            do
            {
                
KvGetSectionName(hKVszAuthsizeof(szAuth)); //Get the SteamID
                
if(StrContains(Auth,szAuth,false) != -1)
                {
                    
KvGetString(hKV"reason"szReasonsizeof(szReason)); //Get the reason for banning.
                    
PrintToChatAll("STEAM: %s REASON: %s"szAuthszReason); //Print the message
                    
Match true;
                }
            } while (
KvGotoNextKey(hKV)); //Goto the next SteamID
        
}
    } 
    
CloseHandle(hKV);
    return 
Match;


public 
Action:Command_tlist(Client,Args)
{
    if( 
Args 2)
    {
        
ReplyToCommand(Client,"Syntax: sm_tlist <steamid> \"<reason>\"");
    }
    
decl String:SteamId[68];
    
GetCmdArg(1,SteamId,sizeof(SteamId));
    
    new 
Handle:Regex CompileRegex("STEAM_[0-9]:[0-9]:[0-9]{4,}");
    if(
MatchRegex(Regex,SteamId) != -1)
    {
        
decl String:Reason[255];
        
GetCmdArg(2,Reason,sizeof(Reason));
        
        new 
Handle:hKV CreateKeyValues("Tlist");
        
FileToKeyValues(hKVsBannedDB);
        
        
KvJumpToKey(hKV,"Banned",false);
        
KvJumpToKey(hKV,SteamId,true);
        
KvSetString(hKV,"reason",Reason);
        
        
KvRewind(hKV);
        
KeyValuesToFile(hKV,sBannedDB);
        
CloseHandle(hKV);
    }else{
        
ReplyToCommand(Client,"SteamId doesn't match normal SteamId format");
    }

Haven't compiled yet, so I probably forgot some things/made typos.

I haven't autokicked after ShowBanReason yet, I leave that up to you
__________________
Get a lid on that zombie,
he's never gonna be alri-i-ight.
Oooh get a lid on that zombie,
or he's gonna feed all night.
Monkeys is offline
Greyscale
SourceMod Plugin Approver
Join Date: Dec 2007
Location: strYoMommasHouse[you];
Old 08-04-2010 , 13:15   Re: Key value help
Reply With Quote #19

Sorry I guess I read it too quick. I thought your code went a level deeper than it does.
__________________
Greyscale is offline
bestmeth0ds
SourceMod Donor
Join Date: Jul 2010
Old 08-04-2010 , 13:56   Re: Key value help
Reply With Quote #20

Its spitting errors at me around the lines 55 and 56.

Code:
Undefined symbol "compileregex"
Code:
undefined symbol "matchregex"
Code:
symbol is assigned a value that is never used "regex"
bestmeth0ds is offline
Send a message via Skype™ to bestmeth0ds
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 14:20.


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