Raised This Month: $ Target: $400
 0% 

Read certain part of chat message


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Buckshot
Senior Member
Join Date: Mar 2014
Location: Sweden
Old 03-29-2014 , 16:13   Read certain part of chat message
Reply With Quote #1

So, i am making this plugin where a player types "/command playername description", and i want to get the playername and string separately and place each of them in a separate variable which i am going to use, which does not work with read_args since read_args reads everything after the command at once. How do i do this? I guess you gotta read the information before the space, and then put the rest in description variable.. but i don't know how.
__________________
PM me for private work.



Last edited by Buckshot; 03-29-2014 at 16:16.
Buckshot is offline
Send a message via Skype™ to Buckshot
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 03-29-2014 , 16:15   Re: Read certain part of chat message
Reply With Quote #2

read_argv(0, command, charsmax(command))
read_argv(1, arg1, charsmax(arg1))
read_argv(2, arg2, charsmax(arg2))

or separate them using parse() or strbreak().
__________________

Last edited by Black Rose; 03-29-2014 at 16:16.
Black Rose is offline
Buckshot
Senior Member
Join Date: Mar 2014
Location: Sweden
Old 03-29-2014 , 16:20   Re: Read certain part of chat message
Reply With Quote #3

Thanks alot! I can't believe i didn't know this, it will be VERY useful in alot of plugins.
__________________
PM me for private work.


Buckshot is offline
Send a message via Skype™ to Buckshot
Buckshot
Senior Member
Join Date: Mar 2014
Location: Sweden
Old 03-29-2014 , 16:42   Re: Read certain part of chat message
Reply With Quote #4

I think i got a problem though. After the second argv, the player is supposed to type a description, which most likely will have spaces. I think will only get the first word of the description with read_argv 2?

An example usage:

/report Player He was cheating!

And the "Player" should be put in my szName variable, and the "He was cheating" in String variable

If i would use read_argv, i would just get the player name, and "He" as the string?.. Or does it take ALL of the text if i don't have a read_argv(3) ?
__________________
PM me for private work.



Last edited by Buckshot; 03-29-2014 at 16:45.
Buckshot is offline
Send a message via Skype™ to Buckshot
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 03-29-2014 , 16:46   Re: Read certain part of chat message
Reply With Quote #5

It's normally solved by forcing the user to put the argument inside quotes. Like for example namechange
You can't write
name this is my name
because then it will end up being just "this".
But if you write:
name "this is my name"
you will get the full name.

But again, you could use strbreak() to part args at the first space, which will be between arg1 and arg2.
__________________

Last edited by Black Rose; 03-29-2014 at 16:47.
Black Rose is offline
Buckshot
Senior Member
Join Date: Mar 2014
Location: Sweden
Old 03-29-2014 , 16:48   Re: Read certain part of chat message
Reply With Quote #6

Quote:
Originally Posted by Black Rose View Post
It's normally solved by forcing the user to put the argument inside quotes. Like for example namechange
You can't write
name this is my name
because then it will end up being just "this".
But if you write:
name "this is my name"
you will get the full name.

But again, you could use strbreak() to part args at the first space, which will be between arg1 and arg2.
Yeah, thanks.
__________________
PM me for private work.



Last edited by Buckshot; 03-29-2014 at 16:49.
Buckshot is offline
Send a message via Skype™ to Buckshot
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 03-29-2014 , 16:49   Re: Read certain part of chat message
Reply With Quote #7

You can. Just use read_args() and strbreak(), parse() or strtok() to single out the first argument from the rest.
__________________
Black Rose is offline
Buckshot
Senior Member
Join Date: Mar 2014
Location: Sweden
Old 03-29-2014 , 17:32   Re: Read certain part of chat message
Reply With Quote #8

Quote:
Originally Posted by Black Rose View Post
You can. Just use read_args() and strbreak(), parse() or strtok() to single out the first argument from the rest.
Hm.. I just tried all this out, but i can't get it to work.. Nothing at all happens, it doesn't even seem to go to the Playerreport function when i type /report bla blablal.. I know why.. It is because "/report blablabla" isn't a command.. But i gotta make it one somehow, so it is a command whatever you type after the /report

Code:

PHP Code:
#include <amxmodx>

new const File[ ] = "addons/amxmodx/reportlog.txt"

public plugin_init( ) {
    
register_plugin"Report Player""1.0""BuckShot" )
    
register_clcmd"say /report""PlayerReport" )
}

public 
PlayerReportid )
{
    new 
FullMsg192 ], Reason161 ], Name32 ], WriteMsg192 ]
    
    
read_argsFullMsg31 )
    
read_argv1Name32 )
    
    new 
len sizeofName )
    
    
strbreakFullMsgNamelenReason160 )
    
formatexWriteMsg192"Player: %s\n Reason: %s"NameReason)
    
write_fileFileWriteMsg )
    


Edit: I gotta register_clcmd("say ", "PlayerReport" ) only, and check if contains /report? that could work
__________________
PM me for private work.



Last edited by Buckshot; 03-29-2014 at 17:42.
Buckshot is offline
Send a message via Skype™ to Buckshot
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 03-29-2014 , 18:10   Re: Read certain part of chat message
Reply With Quote #9

Say commands are different.
"say" is the command, everything else is the first argument.
So you have to manually parse that argument into the bits you want.

Code:
#include <amxmodx> public plugin_init( ) {     register_plugin( "Report Player", "1.0", "BuckShot" )     register_clcmd( "say", "PlayerReport" ) } public PlayerReport( id ) {     new FullMsg[ 192 ], Reason[ 161 ], Name[ 32 ], Command[ 32 ]         read_args( FullMsg, charsmax(FullMsg) )     strbreak(FullMsg, Command, charsmax(Command), FullMsg, charsmax(FullMsg))         if ( ! equali(Command, "/report") )         return;         strbreak(FullMsg, Name, charsmax(Name), Reason, charsmax(Reason))         server_print("%s, %s, %s", Command, Name, Reason); }
__________________

Last edited by Black Rose; 03-29-2014 at 18:11.
Black Rose is offline
Buckshot
Senior Member
Join Date: Mar 2014
Location: Sweden
Old 03-29-2014 , 18:36   Re: Read certain part of chat message
Reply With Quote #10

Quote:
Originally Posted by Black Rose View Post
Say commands are different.
"say" is the command, everything else is the first argument.
So you have to manually parse that argument into the bits you want.

Code:
#include <amxmodx> public plugin_init( ) {     register_plugin( "Report Player", "1.0", "BuckShot" )     register_clcmd( "say", "PlayerReport" ) } public PlayerReport( id ) {     new FullMsg[ 192 ], Reason[ 161 ], Name[ 32 ], Command[ 32 ]         read_args( FullMsg, charsmax(FullMsg) )     strbreak(FullMsg, Command, charsmax(Command), FullMsg, charsmax(FullMsg))         if ( ! equali(Command, "/report") )         return;         strbreak(FullMsg, Name, charsmax(Name), Reason, charsmax(Reason))         server_print("%s, %s, %s", Command, Name, Reason); }
Thank you By the way.. I think the "new len = sizeof( Name )" has to be there, and also len instead of charsmax(Name) i noticed you removed it. Otherwise it is going to strbreak after 32 characters, which is not what we want. All player names are not 32 characters long, so it might put some of the Message in there as well. Also the Command isn't 32 chars long.. Correct me if im wrong
__________________
PM me for private work.



Last edited by Buckshot; 03-29-2014 at 19:25.
Buckshot is offline
Send a message via Skype™ to Buckshot
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 05:56.


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