Raised This Month: $ Target: $400
 0% 

Solved Redefine client_print function with a condition


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 03-19-2017 , 15:48   Re: Redefine client_print function with a condition
Reply With Quote #1

Have an editor that can do a Find & Replace with Regex. Then search for
Code:
client_print\s*\((.+?),\s*print_chat\s*,(.+?)\)
and replace with
Code:
CC_SendMessage($1,$2)
Just tested in Sublime Text 3.
klippy is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 03-19-2017 , 18:10   Re: Redefine client_print function with a condition
Reply With Quote #2

Quote:
Originally Posted by KliPPy View Post
Have an editor that can do a Find & Replace with Regex. Then search for
Code:
client_print\s*\((.+?),\s*print_chat\s*,(.+?)\)
and replace with
Code:
CC_SendMessage($1,$2)
Just tested in Sublime Text 3.
You mean users will need to use a different editor in order to do that? What I want to do is simply add a #include which will contain a #define or something like that which will replace all print_chat messages with a custom function. If it requires down loading/using additional files, I can live without it. The point is to keep it simple and easy for people to use.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 03-19-2017 , 19:17   Re: Redefine client_print function with a condition
Reply With Quote #3

Quote:
Originally Posted by OciXCrom View Post
You mean users will need to use a different editor in order to do that? What I want to do is simply add a #include which will contain a #define or something like that which will replace all print_chat messages with a custom function. If it requires down loading/using additional files, I can live without it. The point is to keep it simple and easy for people to use.
Regex a very powerful tool that can be used to make many things much easier and quicker. I actually use it several times a week. Therefore, for me, this is a simple task.

If you really want to do it as you suggest with a simple precompiler definition, you'll need to have a function with the same prototype. In that function, you need to check if the second parameter is print_chat. If it is, do the modified functionality otherwise call client_print() like normal.
__________________

Last edited by fysiks; 03-19-2017 at 19:20.
fysiks is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 03-19-2017 , 19:28   Re: Redefine client_print function with a condition
Reply With Quote #4

You could distribute a simple script that will do the Regex work for you on provided files.
klippy is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 03-19-2017 , 19:47   Re: Redefine client_print function with a condition
Reply With Quote #5

I could, but with no regex knowledge, I doubt it.
I'll do as fysiks suggested - custom function with print_chat check.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
PRoSToTeM@
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 03-20-2017 , 16:29   Re: Redefine client_print function with a condition
Reply With Quote #6

PHP Code:
stock CC_PrintTransform(clientprintType, const format[], const any:...) {
    
#pragma unused client
    #pragma unused printType
    #pragma unused format
    
new bool:sendCustom = (printType == print_chat);
    {
        new 
argCount numargs();
        if (
argCount == 0) {
            
client_print(00"");
            
CC_SendMessage(0"");
        }
        const 
cellbytes cellbits/8;
        new 
argBytes = (sendCustom ? (argCount 1) : argCount) * cellbytes;
        new 
i;
        for (
argCount 1>= 0i--) {
            if (
sendCustom && == 1) {
                continue;
            }
            
            
*= cellbytes;
            
#emit addr.pri 0xC
            #emit load.s.alt i
            #emit add
            #emit load.i
            #emit push.pri
            
/= cellbytes;
        }
        
#emit push.s argBytes
        
if (sendCustom) {
            
#emit sysreq.c CC_SendMessage
        
} else {
            
#emit sysreq.c client_print
        
}
        
#emit stack 0x4
        
for (0argCounti++) {
            if (
sendCustom && == 1) {
                continue;
            }
            
            
#emit stack 0x4
        
}
    }
}
#define client_print CC_PrintTransform 
__________________

Last edited by PRoSToTeM@; 03-20-2017 at 16:31.
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 03-20-2017 , 16:35   Re: Redefine client_print function with a condition
Reply With Quote #7

uatafak dude, gfj.
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo
EFFx is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 03-20-2017 , 16:49   Re: Redefine client_print function with a condition
Reply With Quote #8

PRoSToTeM@, please no. :p
klippy is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 03-21-2017 , 19:51   Re: Redefine client_print function with a condition
Reply With Quote #9

Wow. No words needed.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
PRoSToTeM@
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 03-23-2017 , 11:30   Re: Redefine client_print function with a condition
Reply With Quote #10

And the solution without emit:
PHP Code:
stock CC_PrintTransform(clientprintType, const format[], const any:...) {
    const 
MaxMessageSize 256;
    static 
message[MaxMessageSize];
    new 
bool:sendCustom = (printType == print_chat);
    
    if (
client != 0) {
        new 
player client;
        
        
SetGlobalTransTarget(player);
        
vformat(messagecharsmax(message), format4);
        
        if (
sendCustom)
            
CC_SendMessage(player"%s"message);
        else
            
client_print(playerprintType"%s"message);
    } else {
        static 
players[MAX_PLAYERS];
        new 
playerCount;
        
get_players(playersplayerCount"c" /* Skip bots */);
        
        for (new 
0playerCounti++) {
            new 
player players[i];
            
            
SetGlobalTransTarget(player);
            
vformat(messagecharsmax(message), format4);
            
            if (
sendCustom)
                
CC_SendMessage(player"%s"message);
            else
                
client_print(playerprintType"%s"message);
        }
    }
}
#define client_print CC_PrintTransform 
__________________
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
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 17:56.


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