Raised This Month: $ Target: $400
 0% 

Reverse the writing in chat


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
xElior
Junior Member
Join Date: Sep 2013
Old 07-09-2015 , 07:06   Reverse the writing in chat
Reply With Quote #1

Hi,
When you update your server with SteamCMD to the newest version (whose right now 48/1.1.2.7/Stdio 6153), the server now supports all keyboard symbols and all languages in chat or in player's name.
As if it's eastern languages (Arabic or Hebrew) which the writing goes from right to left differs from all the other languages which goes from left to right, when you register words with your keyboard with their normal order, the word goes backwards and gets messed up.
What I am asking for, is a plugin which reverse the words in chat, so if the word is inverted it will reverse the letters so it will perform as it should be.

I think that plugin will be really useful to many servers in Counter-Strike 1.6.
Thanks ahead!
__________________
Sincerely, Elior

Last edited by xElior; 07-09-2015 at 07:12.
xElior is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 07-09-2015 , 07:17   Re: Reverse the writing in chat
Reply With Quote #2

So,
Code:
Player: Word1 Word2 Word3 WordN
should become
Code:
Player: WordN Word3 Word2 Word1
?

Just asking, because I don't know anything about Arabic or Hebrew languages.
klippy is offline
xElior
Junior Member
Join Date: Sep 2013
Old 07-09-2015 , 07:21   Re: Reverse the writing in chat
Reply With Quote #3

Quote:
Originally Posted by KliPPy View Post
So,
Code:
Player: Word1 Word2 Word3 WordN
should become
Code:
Player: WordN Word3 Word2 Word1
?

Just asking, because I don't know anything about Arabic or Hebrew languages.
kinda, yes.
I will give you example in English because it's the same principle.

if I want to write bottle, I type it in it's regular order of letters, and it shows elttob.
Then it's means that if I want that it will show it in the correct way, I have to register the word from the first place as backwards. I write in chat elttob and then it shows bottle.
So my requested plugin is that if I will write bottle, it will show bottle. It will reverse back the elttob and it will perfrom correctly.
__________________
Sincerely, Elior

Last edited by xElior; 07-09-2015 at 07:23.
xElior is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 07-09-2015 , 08:39   Re: Reverse the writing in chat
Reply With Quote #4

PHP Code:
#include <amxmodx>

#pragma semicolon 1

new PLUGIN[]  = "";
new 
AUTHOR[]  = "";
new 
VERSION[] = "0.00";

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR);
    
    
register_message(get_user_msgid("SayText"), "msgSayText");
}

// Checks if a given string contains Eastern Languages' characters
fnEasternLanguageString(const szString[])
{
    new 
0;
    new 
ch;
    while((
ch szString[i]) != EOS)
    {
        
// Information from Unicode wiki page, not sure if this is the actual character range
        // Actually, I've never worked with non-ASCII characters in Pawn, not sure if it's even supported
        
if(0x590 <= ch <= 0x7BF)
            return 
true;
        
        
i++;
    }
    
    return 
false;
}

public 
msgSayText(iIdiDestpEnt)
{
    static 
szText[192];
    
// I think the 4th arg is the actual message, can't remember
    
get_msg_arg_string(4szTextcharsmax(szText));
    
    if(!
fnEasternLanguageString(szText))
        return 
PLUGIN_CONTINUE;
    
    new 
ch// Cache a character, array indexing is slower
    
new 0j;
    new 
boolbSkipWord false;
    new 
iWordStart = -1;
    new 
iMid;
    new 
boolisEOS// Eliminate a need to check for EOS twice
    
new iTemp;
    
    for(;; 
i++) // We'll loop until we reach end of string (condition for breaking down below)
    
{
        if(
isspace((ch szText[i])) || (isEOS = (ch == EOS)))
        {
            
bSkipWord false;
            
            
// Reached the end of a word that should get reversed
            
if(iWordStart != -1)
            {
                
i--; // So I don't have to do "i - 1" each time, restored to original value later
                
iMid = (iWordStart) / 2// Get number of chars to middle of a word
                
                // Reverse the word
                
for(0iMidj++)
                {
                    
iTemp szText[iWordStart];
                    
szText[iWordStart j] = szText[j];
                    
szText[j] = iTemp;
                }
                
                
iWordStart = -1;
                
i++;
            }
            
            
// End of string, we're done
            
if(isEOS)
                break;
            
            continue;
        }
        else if(
bSkipWord)
            continue;
            
        
// Found start position of a word that should get reversed
        
if(iWordStart != -1)
        {
            
// Should not get reversed if starts with a number (I guess)
            
if('0' <= ch <= '9')
            {
                
bSkipWord true;
                continue;
            }
            
            
iWordStart i;
        }
    }
    
    
set_msg_arg_string(4szText);
    
    return 
PLUGIN_CONTINUE;

You gave me an example with only 1 word, so I can't guess if you want something like (as appears in a chat message)
Code:
thing stuff amxx
to become
Code:
xxma ffuts gniht
or become
Code:
gniht ffuts xxma
The code above does the latter (reverses each word individually, not the whole string). It also checks if the message contains any Arabic characters before reversing it.
It probably could be written more efficient, but I don't have a lot of time to spend right now. I think it's good enough. I haven't tested it though, I don't have HLDS installed on Windows, and I am too lazy to boot to Linux right now. Compiles fine at least.

Last edited by klippy; 07-09-2015 at 08:40.
klippy is offline
xElior
Junior Member
Join Date: Sep 2013
Old 07-09-2015 , 10:00   Re: Reverse the writing in chat
Reply With Quote #5

Quote:
Originally Posted by KliPPy View Post
PHP Code:
#include <amxmodx>

#pragma semicolon 1

new PLUGIN[]  = "";
new 
AUTHOR[]  = "";
new 
VERSION[] = "0.00";

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR);
    
    
register_message(get_user_msgid("SayText"), "msgSayText");
}

// Checks if a given string contains Eastern Languages' characters
fnEasternLanguageString(const szString[])
{
    new 
0;
    new 
ch;
    while((
ch szString[i]) != EOS)
    {
        
// Information from Unicode wiki page, not sure if this is the actual character range
        // Actually, I've never worked with non-ASCII characters in Pawn, not sure if it's even supported
        
if(0x590 <= ch <= 0x7BF)
            return 
true;
        
        
i++;
    }
    
    return 
false;
}

public 
msgSayText(iIdiDestpEnt)
{
    static 
szText[192];
    
// I think the 4th arg is the actual message, can't remember
    
get_msg_arg_string(4szTextcharsmax(szText));
    
    if(!
fnEasternLanguageString(szText))
        return 
PLUGIN_CONTINUE;
    
    new 
ch// Cache a character, array indexing is slower
    
new 0j;
    new 
boolbSkipWord false;
    new 
iWordStart = -1;
    new 
iMid;
    new 
boolisEOS// Eliminate a need to check for EOS twice
    
new iTemp;
    
    for(;; 
i++) // We'll loop until we reach end of string (condition for breaking down below)
    
{
        if(
isspace((ch szText[i])) || (isEOS = (ch == EOS)))
        {
            
bSkipWord false;
            
            
// Reached the end of a word that should get reversed
            
if(iWordStart != -1)
            {
                
i--; // So I don't have to do "i - 1" each time, restored to original value later
                
iMid = (iWordStart) / 2// Get number of chars to middle of a word
                
                // Reverse the word
                
for(0iMidj++)
                {
                    
iTemp szText[iWordStart];
                    
szText[iWordStart j] = szText[j];
                    
szText[j] = iTemp;
                }
                
                
iWordStart = -1;
                
i++;
            }
            
            
// End of string, we're done
            
if(isEOS)
                break;
            
            continue;
        }
        else if(
bSkipWord)
            continue;
            
        
// Found start position of a word that should get reversed
        
if(iWordStart != -1)
        {
            
// Should not get reversed if starts with a number (I guess)
            
if('0' <= ch <= '9')
            {
                
bSkipWord true;
                continue;
            }
            
            
iWordStart i;
        }
    }
    
    
set_msg_arg_string(4szText);
    
    return 
PLUGIN_CONTINUE;

You gave me an example with only 1 word, so I can't guess if you want something like (as appears in a chat message)
Code:
thing stuff amxx
to become
Code:
xxma ffuts gniht
or become
Code:
gniht ffuts xxma
The code above does the latter (reverses each word individually, not the whole string). It also checks if the message contains any Arabic characters before reversing it.
It probably could be written more efficient, but I don't have a lot of time to spend right now. I think it's good enough. I haven't tested it though, I don't have HLDS installed on Windows, and I am too lazy to boot to Linux right now. Compiles fine at least.
Thanks, but it does not work.
__________________
Sincerely, Elior
xElior is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 07-09-2015 , 10:39   Re: Reverse the writing in chat
Reply With Quote #6

Quote:
Originally Posted by xElior View Post
Thanks, but it does not work.
Oh well, I'll have to test and debug it myself I guess. Will try to do it in next few days. I'm currently running Windows because of my job, if I happen to boot to Linux in next few days I'll take my time to test it.
klippy is offline
GoD-Tony
Veteran Member
Join Date: Jul 2005
Old 07-09-2015 , 10:45   Re: Reverse the writing in chat
Reply With Quote #7

A port of this SourceMod plugin may help: https://forums.alliedmods.net/showthread.php?t=178279
__________________
GoD-Tony is offline
xElior
Junior Member
Join Date: Sep 2013
Old 07-14-2015 , 03:09   Re: Reverse the writing in chat
Reply With Quote #8

Quote:
Originally Posted by GoD-Tony View Post
A port of this SourceMod plugin may help: https://forums.alliedmods.net/showthread.php?t=178279
How can I port this SourceMod plugin to AMX Mod X Plugin?
__________________
Sincerely, Elior
xElior 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 06:10.


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