Read certain part of chat message
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.
|
Re: Read certain part of chat message
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(). |
Re: Read certain part of chat message
Thanks alot! :) I can't believe i didn't know this, it will be VERY useful in alot of plugins.
|
Re: Read certain part of chat message
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) ? |
Re: Read certain part of chat message
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. |
Re: Read certain part of chat message
Quote:
|
Re: Read certain part of chat message
You can. Just use read_args() and strbreak(), parse() or strtok() to single out the first argument from the rest.
|
Re: Read certain part of chat message
Quote:
Code: PHP Code:
Edit: I gotta register_clcmd("say ", "PlayerReport" ) only, and check if contains /report? that could work |
Re: Read certain part of chat message
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:
|
Re: Read certain part of chat message
Quote:
|
| All times are GMT -4. The time now is 05:56. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.