AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved define replace (https://forums.alliedmods.net/showthread.php?t=301120)

KiLLeR. 09-08-2017 17:09

define replace
 
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

kristi 09-08-2017 17:20

Re: define replace
 
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)

siriusmd99 09-09-2017 14:13

Re: define replace
 
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.

klippy 09-09-2017 14:23

Re: define replace
 
Quote:

Originally Posted by siriusmd99 (Post 2547800)
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.

siriusmd99 09-09-2017 14:29

Re: define replace
 
Quote:

Originally Posted by KliPPy (Post 2547802)
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.

kristi 09-09-2017 14:37

Re: define replace
 
Quote:

Originally Posted by siriusmd99 (Post 2547805)
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[]) {} 


klippy 09-09-2017 14:45

Re: define replace
 
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.

kristi 09-09-2017 15:58

Re: define replace
 
@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

KiLLeR. 09-10-2017 09:49

Re: define replace
 
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?! :D

KiLLeR. 09-18-2017 15:04

Re: define replace
 
Thanks to helping me ;/
I found solution, #define must be in front of all includes.


All times are GMT -4. The time now is 09:55.

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