Raised This Month: $ Target: $400
 0% 

SayText problem.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Craxor
Veteran Member
Join Date: Jan 2016
Location: Romania
Old 02-14-2016 , 02:30   SayText problem.
Reply With Quote #1

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 );         }     } }

Last edited by Craxor; 02-14-2016 at 03:56.
Craxor is offline
Send a message via ICQ to Craxor
Craxor
Veteran Member
Join Date: Jan 2016
Location: Romania
Old 02-14-2016 , 02:48   Re: SayText problem.
Reply With Quote #2

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 );
Craxor is offline
Send a message via ICQ to Craxor
siriusmd99
Veteran Member
Join Date: Oct 2013
Location: Republic of Moldova
Old 02-14-2016 , 03:24   Re: SayText problem.
Reply With Quote #3

[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 ...?
siriusmd99 is offline
Craxor
Veteran Member
Join Date: Jan 2016
Location: Romania
Old 02-14-2016 , 03:26   Re: SayText problem.
Reply With Quote #4

Quote:
Originally Posted by siriusmd99 View Post
[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.

Last edited by Craxor; 02-14-2016 at 03:38.
Craxor is offline
Send a message via ICQ to Craxor
siriusmd99
Veteran Member
Join Date: Oct 2013
Location: Republic of Moldova
Old 02-14-2016 , 04:00   Re: SayText problem.
Reply With Quote #5

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.
siriusmd99 is offline
Craxor
Veteran Member
Join Date: Jan 2016
Location: Romania
Old 02-14-2016 , 04:13   Re: SayText problem.
Reply With Quote #6

Quote:
Originally Posted by siriusmd99 View Post
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.
Craxor is offline
Send a message via ICQ to Craxor
siriusmd99
Veteran Member
Join Date: Oct 2013
Location: Republic of Moldova
Old 02-14-2016 , 04:32   Re: SayText problem.
Reply With Quote #7

yes, its working without that but as I said it will be more efficient for amxx
There is no sense to copy empty string.
siriusmd99 is offline
Craxor
Veteran Member
Join Date: Jan 2016
Location: Romania
Old 02-14-2016 , 04:43   Re: SayText problem.
Reply With Quote #8

Quote:
Originally Posted by siriusmd99 View Post
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

Last edited by Craxor; 02-14-2016 at 04:58.
Craxor is offline
Send a message via ICQ to Craxor
siriusmd99
Veteran Member
Join Date: Oct 2013
Location: Republic of Moldova
Old 02-14-2016 , 05:51   Re: SayText problem.
Reply With Quote #9

yes, now it's pretty nice.
siriusmd99 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 09:24.


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