AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   SayText problem. (https://forums.alliedmods.net/showthread.php?t=279040)

Craxor 02-14-2016 02:30

SayText problem.
 
I'm tryng to make a plugin who block multiple prints( an user who prints more times the same text ).


Problem is acting in the next way: Is check and let first propozition(when i entry to server) THEN IT's BLOCKING Everything without scan, or is a wrong formating string message, i realy dunno...

Here's the code:

Code:
/*     Credits:         ConnorMcLeod    - SayText code         Bugsy - string copy/formating for each client. */ #include <amxmodx> new const PLUGIN[]  =   "Block Multiple Prints",      VERSION[]  =   "v0.1",      AUTHOR[]   =   "Craxor" new gLastUserMessage[33][120], bool:StringCopied[33]; new const BlockMsg[]    =   "**** Multiple Prints Detected! ****"; public plugin_init( ) {     register_plugin     (         .plugin_name    =   PLUGIN,         .version    =   VERSION,         .author     =   AUTHOR     );     register_message(get_user_msgid("SayText"),"Message_SayText"); } public client_putinserver( id ) {     StringCopied[ id ] = false;     gLastUserMessage[id][0] = EOS; } public Message_SayText(msgId,msgDest,msgEnt) {     new Msg[65], id = get_msg_arg_int(1);     get_msg_arg_string(2, Msg, charsmax(Msg));     if( is_user_connected( id ) )         {         if( equal( Msg, gLastUserMessage[id] ) )             set_msg_arg_string(2, BlockMsg);         else             set_msg_arg_string(2, Msg );           if( StringCopied[ id ] == false )         {             copy( gLastUserMessage[id], charsmax( gLastUserMessage[] ), Msg );             StringCopied[ id ] = true;         }             else if( StringCopied[id] == true )         {             formatex( gLastUserMessage[id], charsmax( gLastUserMessage[] ), Msg );         }     } }

Craxor 02-14-2016 02:48

Re: SayText problem.
 
Solved.
Code:
public Message_SayText(msgId,msgDest,msgEnt) {     new Msg[192], id = get_msg_arg_int(1);     get_msg_arg_string(4, Msg, charsmax(Msg));     if( is_user_connected( id ) )         {         if( equali( Msg, gLastUserMessage[id] ) )             set_msg_arg_string(2, BlockMsg);         else             set_msg_arg_string(4, Msg );

siriusmd99 02-14-2016 03:24

Re: SayText problem.
 
[en] hey, why do you use boolean string copy to catch first say message?
[RO] Nu inteleg, de ce folosesti booleanul si copy, de ce nu folosesti deodata formatex, faci asta cu scopul ca sa fie eficient sau ...?

Craxor 02-14-2016 03:26

Re: SayText problem.
 
Quote:

Originally Posted by siriusmd99 (Post 2392777)
[en] hey, why do you use boolean string copy to catch first say message?
[RO] Nu inteleg, de ce folosesti booleanul si copy, de ce nu folosesti deodata formatex, faci asta cu scopul ca sa fie eficient sau ...?

https://forums.alliedmods.net/showpo...80&postcount=4

But you're right, in my case formatex() should be removed.

siriusmd99 02-14-2016 04:00

Re: SayText problem.
 
Yes, copy is more efficient than formatex because it only copies the string, not edits it.So ya, if you don't need to edit, it's better to use copy.
Also for better performance I suggest you to check if msg[0]!=EOS and not do copy string,just return continue,because empty message is not printed, being blocked by default client engine.

Craxor 02-14-2016 04:13

Re: SayText problem.
 
Quote:

Originally Posted by siriusmd99 (Post 2392790)
Also for better performance I suggest you to check if msg[0]!=EOS and not do copy string,just return continue,because empty message is not printed, being blocked by default client engine.

Not realy needed, working without this feature.

siriusmd99 02-14-2016 04:32

Re: SayText problem.
 
yes, its working without that but as I said it will be more efficient for amxx
There is no sense to copy empty string.

Craxor 02-14-2016 04:43

Re: SayText problem.
 
Quote:

Originally Posted by siriusmd99 (Post 2392797)
yes, its working without that but as I said it will be more efficient for amxx
There is no sense to copy empty string.

Something like:
Code:
    if( Msg[0] != EOS )         copy( gLastUserMessage[id], charsmax( gLastUserMessage[] ), Msg );

If Msg is not empty will be copyed. in gLastUserMessage..

Edit: is working perfect, for more suggestion please post here: https://forums.alliedmods.net/showthread.php?t=279042

siriusmd99 02-14-2016 05:51

Re: SayText problem.
 
yes, now it's pretty nice. :)


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

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