AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Catch say (https://forums.alliedmods.net/showthread.php?t=188619)

Artifact 06-28-2012 13:28

Catch say
 
How to catch when someone type in chat /playername
ex my name is wow and when someone type /wow to get information of my fps

Liverwiz 06-28-2012 13:40

Re: Catch say
 
I was actually just wondering this....I was thinking that maybe you can do a register_clcmd("say /", "HandleSay") then grab the name as the argument with arg[1]. But i'm not sure if "say /" will ever get called. If not....you can always do it as a console command....

Artifact 06-28-2012 14:06

Re: Catch say
 
Or register just say and arg[1] = "/" because "say /" be like this
Code:

say / wow
and we dont want space :p

Liverwiz 06-28-2012 16:41

Re: Catch say
 
here is some code to give you a hand....
Code:

//init
register_clmd("say", "cmdPM")

public cmdPM(id)
{
        if(!get_pcvar_num(toggle_pcvar) )
                return PLUGIN_CONTINUE
               
        new args[200]; read_args(args, charsmax(args) )
        remove_quotes(args)        // take the raw string
       
        if(args[0] == '/')        // make sure it starts with a /
        {
                                // This will get the player index from the defined name
                new player = cmd_target(id, args[1], CMDTARGET_NO_BOTS)
               
                (!player) ? client_print(id, print_chat, "%L", id, "INVALID_PLAYER", target[1]) : displayInfo(player, id)
        }

        return PLUGIN_HANDLED_MAIN
}

Quote:

/wow
This will print that it is a command, the user's ID, and the user's name. I'm still working on it....but that's what i have so far. (its going into one of my plugins as well) it should work fine for you.

EDIT: i edited above's code to be better looking, and working for your use. I C/P'd from my code (which includes ML tag- you can remove that) You'll have to define displayInfo(target, id) yourself to include what you want to display to the caller (id) about the person they want to know (target). It works beautifully, i must say.

fysiks 06-28-2012 18:46

Re: Catch say
 
Quote:

Originally Posted by Liverwiz (Post 1738256)
I was actually just wondering this....I was thinking that maybe you can do a register_clcmd("say /", "HandleSay") then grab the name as the argument with arg[1]. But i'm not sure if "say /" will ever get called. If not....you can always do it as a console command....

This will not work. Your second post is correct with the exception of registering the command. You should use register_clcmd() for "say".

Liverwiz 06-28-2012 19:00

Re: Catch say
 
Quote:

Originally Posted by fysiks (Post 1738492)
You should use register_clcmd() for "say".

Code Updated.

It should be noted that this will tamper with any other commands you have bound to say / w/e. I just found this out, and will be changing it to an ! as the key.

EDIT: code updated again. To mitigate the above mentioned issue.

ConnorMcLeod 06-29-2012 01:35

Re: Catch say
 
Quote:

// This will get the userID from the defined name
I think you randmoly wrote userID, this is confusing because of #userid thing that is a different thing.
Better to write 'player index'.

Liverwiz 06-29-2012 01:52

Re: Catch say
 
Quote:

Originally Posted by ConnorMcLeod (Post 1738707)
I think you randmoly wrote userID, this is confusing because of #userid thing that is a different thing.
Better to write 'player index'.

damnit, you know what cmd_target does. Though to someone who doesn't.....they shouldn't be dicking around in the code anyway. :P

ConnorMcLeod 06-29-2012 02:25

Re: Catch say
 
Quote:

Originally Posted by Liverwiz (Post 1738713)
damnit, you know what cmd_target does. Though to someone who doesn't.....they shouldn't be dicking around in the code anyway. :P

This is irrelevant since you are answering to someone asking help in scripting forum, your answer shouldn't be confusing.

<VeCo> 06-29-2012 07:39

Re: Catch say
 
PHP Code:

new args[200]; 

Just to mention - the maximum lenght of a chat message is 191 symbols (array size 192).


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

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