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

Solved Case Insensitive StringMap.GetString


Post New Thread Closed Thread   
 
Thread Tools Display Modes
Author Message
ThatKidWhoGames
Veteran Member
Join Date: Jun 2013
Location: IsValidClient()
Old 05-19-2018 , 09:39   Case Insensitive StringMap.GetString
#1

The issue has been resolved. Thanks anyways!

If you want to know how to accomplish this, I won't go into detail since it is evident from the code. Here is the modified code:
PHP Code:
#pragma semicolon 1
#define PLUGIN_VERSION "1.1"
#define CONFIG "addons/sourcemod/configs/messagefilter.cfg"

#include <sourcemod>
#include <scp>

StringMap hHashMap;

public 
Plugin myinfo = {
    
name        "Message Filter",
    
author      "Sgt. Gremulock",
    
description "Allows server operators to modify messages that are said in chat to include different text (configured via a config file).",
    
version     PLUGIN_VERSION,
    
url         "grem-co.com"
};

public 
void OnPluginStart()
{
    
CreateConVar("sm_messagefilter_version"PLUGIN_VERSION"Plugin's version."FCVAR_NOTIFY);
}

public 
void OnMapStart()
{
    
BrowseKeyValues();
}

public 
Action OnChatMessage(int &authorArrayList recipientschar[] namechar[] message)
{
    
char buffer[2][256];
    
strcopy(buffer[0], 256message);
    
RemoveCapitalLetters(buffer[0], 256);
    if (
hHashMap.GetString(buffer[0], buffer[1], 256))
    {
        
ReplaceString(message256messagebuffer[1]);
        return 
Plugin_Changed;
    }

    return 
Plugin_Continue;
}

void RemoveCapitalLetters(char[] bufferint max)
{
    
ReplaceString(buffermax"A""a");
    
ReplaceString(buffermax"B""b");
    
ReplaceString(buffermax"C""c");
    
ReplaceString(buffermax"D""d");
    
ReplaceString(buffermax"E""e");
    
ReplaceString(buffermax"F""f");
    
ReplaceString(buffermax"G""g");
    
ReplaceString(buffermax"H""h");
    
ReplaceString(buffermax"I""i");
    
ReplaceString(buffermax"J""j");
    
ReplaceString(buffermax"K""k");
    
ReplaceString(buffermax"L""l");
    
ReplaceString(buffermax"M""m");
    
ReplaceString(buffermax"N""n");
    
ReplaceString(buffermax"O""o");
    
ReplaceString(buffermax"P""p");
    
ReplaceString(buffermax"Q""q");
    
ReplaceString(buffermax"R""r");
    
ReplaceString(buffermax"S""s");
    
ReplaceString(buffermax"T""t");
    
ReplaceString(buffermax"U""u");
    
ReplaceString(buffermax"V""v");
    
ReplaceString(buffermax"W""w");
    
ReplaceString(buffermax"X""x");
    
ReplaceString(buffermax"Y""y");
    
ReplaceString(buffermax"Z""z");
}

void BrowseKeyValues()
{
    
KeyValues kv = new KeyValues("Message Filter");
    if (!
FileExists(CONFIG))
    {
        
kv.JumpToKey("Example"true);
        
kv.SetString("replacement""guy");
        
kv.Rewind();
        
kv.ExportToFile(CONFIG);
        
LogMessage("Generated config file: %s\nEdit the file to your liking and then reload the plugin!"CONFIG);
        
kv.Close();
        return;
    }

    if (!
kv.ImportFromFile(CONFIG))
        
SetFailState("Cannot load the config file (%s)!"CONFIG);
    if (!
kv.GotoFirstSubKey())
        
SetFailState("Failure navigating to the first key in the config file (%s)!"CONFIG);

    if (
hHashMap != null && hHashMap.Size 0)
    {
        
hHashMap.Clear();
        
hHashMap null;
    }

    
hHashMap = new StringMap();
    
char buffer[2][256];
    do {
        
kv.GetSectionName(buffer[0], 256);
        
kv.GetString("replacement"buffer[1], 256);
        
LogMessage("Successfully added replacement for message: '%s' (Replacement: '%s')."buffer[0], buffer[1]);
        
RemoveCapitalLetters(buffer[0], 256);
        
hHashMap.SetString(buffer[0], buffer[1]);
    } while 
kv.GotoNextKey();
    
kv.Close();

Cheers,
Grant
Spoiler

Last edited by ThatKidWhoGames; 05-19-2018 at 10:17.
ThatKidWhoGames is offline
headline
SourceMod Moderator
Join Date: Mar 2015
Old 05-20-2018 , 01:52   Re: Case Insensitive StringMap.GetString
#2

don't do repeated calls to ReplaceString to just handle lowercase-ing your string.

PHP Code:
char[] str "test";
for (
int i 0strlen(str); i++)
{
    
str[i] = CharToLower(str[i]);


Last edited by headline; 05-20-2018 at 01:53.
headline is offline
psychonic

BAFFLED
Join Date: May 2008
Old 05-20-2018 , 20:31   Re: Case Insensitive StringMap.GetString
#3

Quote:
Originally Posted by Headline View Post
don't do repeated calls to ReplaceString to just handle lowercase-ing your string.

PHP Code:
char[] str "test";
for (
int i 0strlen(str); i++)
{
    
str[i] = CharToLower(str[i]);

don't do repeated calls to strlen to just handle getting the length of your string.

PHP Code:
char[] str "test";
int len strlen(str);
for (
int i 0leni++)
{
    
str[i] = CharToLower(str[i]);


Last edited by psychonic; 05-20-2018 at 20:32. Reason: coolface didn't go through the first time
psychonic is offline
headline
SourceMod Moderator
Join Date: Mar 2015
Old 05-20-2018 , 20:46   Re: Case Insensitive StringMap.GetString
#4

Quote:
Originally Posted by psychonic View Post
don't do repeated calls to strlen to just handle getting the length of your string.

PHP Code:
char[] str "test";
int len strlen(str);
for (
int i 0leni++)
{
    
str[i] = CharToLower(str[i]);

don't do repeated calls to CharToLower and assume that every char is a multi-byte character

PHP Code:
char[] str "test"
int len strlen(str);
int bytes 0;
for (
int i 0leni++) 
{
    
bytes IsCharMB(str[i]);
    if (
bytes == 0)
    {
        
str[i] = CharToLower(str[i]);
    }
    else
    {
        
+= (bytes -1);
    }

😎
headline is offline
psychonic

BAFFLED
Join Date: May 2008
Old 05-20-2018 , 21:08   Re: Case Insensitive StringMap.GetString
#5

Quote:
Originally Posted by Headline View Post
don't do repeated calls to CharToLower and assume that every char is a multi-byte character
Just copy/pasting from you/above.

Also, *isn't. "isn't a multi-byte character". FTFY brotato chip.
psychonic is offline
Closed Thread


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 03:50.


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