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

Solved define replace


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
KiLLeR.
Senior Member
Join Date: Jul 2014
Location: Bulgaria
Old 09-08-2017 , 17:09   define replace
Reply With Quote #1

Is there any way to replace core native in the whole code with define?!

Example:
Code:
#define client_print(%1, print_chat, %2)     color_print(%1, true, %2) // this is my custom stock

Last edited by KiLLeR.; 09-18-2017 at 15:03.
KiLLeR. is offline
kristi
Senior Member
Join Date: Nov 2016
Old 09-08-2017 , 17:20   Re: define replace
Reply With Quote #2

Don't add spaces in the first one and it should work
Code:
#define client_print(%1,print_chat,%2)     color_print(%1, true, %2)

Last edited by kristi; 09-08-2017 at 17:21.
kristi is offline
Send a message via Skype™ to kristi
siriusmd99
Veteran Member
Join Date: Oct 2013
Location: Republic of Moldova
Old 09-09-2017 , 14:13   Re: define replace
Reply With Quote #3

It's a good idea actually but compiler will throw you a error "already defined"

Because there is client_print already defined as native.
You can actually modify some symbols like replacing client_print with clientprint.

Something like

#define clientprint(%1, 0, %2) ColorChat(%1, GREEN, %2)

But I am not sure you can do here" any:" parameter so you can format the string inside the function call.

Last edited by siriusmd99; 09-09-2017 at 14:13.
siriusmd99 is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 09-09-2017 , 14:23   Re: define replace
Reply With Quote #4

Quote:
Originally Posted by siriusmd99 View Post
But I am not sure you can do here" any:" parameter so you can format the string inside the function call.
In your case %2 will contain all arguments after the second one, so variadic functions are possible.
klippy is offline
siriusmd99
Veteran Member
Join Date: Oct 2013
Location: Republic of Moldova
Old 09-09-2017 , 14:29   Re: define replace
Reply With Quote #5

Quote:
Originally Posted by KliPPy View Post
In your case %2 will contain all arguments after the second one, so variadic functions are possible.
Thanks for the info, didn't know it has such cool thing...

Also, Killer. It is possible.. I didn't read attentively...
If you want to use only your stock than it's simple.
Just go do amxmodx.inc from includes folder, find line
native client_print (blabla...)
and add double slash to comment it //

So it won't be used by compiller and won't throw error after you add your define.

So yes, it's possible, but only in case you are planning to use only your stock, without native client_print.
siriusmd99 is offline
kristi
Senior Member
Join Date: Nov 2016
Old 09-09-2017 , 14:37   Re: define replace
Reply With Quote #6

Quote:
Originally Posted by siriusmd99 View Post
Thanks for the info, didn't know it has such cool thing...

Also, Killer. It is possible.. I didn't read attentively...
If you want to use only your stock than it's simple.
Just go do amxmodx.inc from includes folder, find line
native client_print (blabla...)
and add double slash to comment it //

So it won't be used by compiller and won't throw error after you add your define.

So yes, it's possible, but only in case you are planning to use only your stock, without native client_print.
This compiles fine so I guess you don't need to do that.
PHP Code:
#include <amxmodx>

#define client_print(%1,print_chat,%2)    color_print(%1, true, %2) // this is my custom stock 

public client_putinserver(id)
{
    
client_print(idprint_chat"Hello, World!")
}


stock color_print(const id, const bool:x, const msg[]) {} 

Last edited by kristi; 09-09-2017 at 14:38.
kristi is offline
Send a message via Skype™ to kristi
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 09-09-2017 , 14:45   Re: define replace
Reply With Quote #7

And you can do
Code:
#define client_print(%0) whatever(%0)
without getting any errors. The preprocessor just performs find-and-replace with given patterns, it has no knowledge of symbols (meaning it doesn't care if they were already defined) as far as I am aware.

However, your example
Code:
#define client_print(%1,print_chat,%2)     color_print(%1, true, %2)
won't work well as it won't match text like:
Code:
client_print(0, print_chat, "");
client_print(0,print_chat ,"");
because the pattern also takes whitespace into account, meaning that if there isn't exactly ",print_chat," in there, it won't match. Probably the best way to deal with that is to do
Code:
#define client_print(%0,%9print_chat%8,%1) color_print(%0, true, %1)
macro parameters pretty much work like ".*" expression in Regex.

Last edited by klippy; 09-09-2017 at 14:45.
klippy is offline
Old 09-09-2017, 14:46
siriusmd99
This message has been deleted by siriusmd99. Reason: nvm
kristi
Senior Member
Join Date: Nov 2016
Old 09-09-2017 , 15:58   Re: define replace
Reply With Quote #8

@KliPPy, Yes, you are right
Code:
#define client_print(%0,%9print_chat%8,%1) color_print(%0, true, %1)
matches most of the cases
PHP Code:
    // all match
    
client_print(id,print_chat,"string")
    
client_print(idprint_chat"string")
    
client_print(idprint_chat"string");
    
client_printidprint_chat"string")
    
client_print (idprint_chat"string"
except for:
PHP Code:
client_print(id print_chat     "string"

I tested this and it matches all of the examples.
Code:
#define client_print(%0print_chat%1) color_print(%0true%1)
code

Last edited by kristi; 09-09-2017 at 16:58.
kristi is offline
Send a message via Skype™ to kristi
KiLLeR.
Senior Member
Join Date: Jul 2014
Location: Bulgaria
Old 09-10-2017 , 09:49   Re: define replace
Reply With Quote #9

The example that i had given seems to work but it's just that I hadn't tested it out yet.
@kristi, you are right and I will use your example, because it gonna match everything, thanks you.
Code:
#define client_print(%0print_chat%1) color_print(%0true%1)

But I have another problem now. Actually I want to replace client_print native from war3ft mode with my custom stock for color message with included prefix instead to do it manually, cuz #define directive seems be easiest and fastest way. All chat message in the mode or at least those I've tested(when buying items) have added prefix, but isn't colored. Then И decided to do smoke test and added this in the test function provided by the plugin:
Code:
color_print( 0, true, "Testing: %L", id, "INFO_SHOPMENU_2", 20.0 ); client_print( 0, print_chat, "Testing: %L",id, "INFO_SHOPMENU_2", 20.0 );
It works, there is colored prefix.

But when I added this in the checks for user has enough money to buy an item even there was no prefix.
Code:
client_print( id, print_chat, "test");

WTF is happening guys?!

Last edited by KiLLeR.; 09-10-2017 at 10:03.
KiLLeR. is offline
KiLLeR.
Senior Member
Join Date: Jul 2014
Location: Bulgaria
Old 09-18-2017 , 15:04   Re: define replace
Reply With Quote #10

Thanks to helping me ;/
I found solution, #define must be in front of all includes.
KiLLeR. 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 20:17.


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