This site is a testing version, but all data is shared with the live forum.


Raised This Month: $ Target: $400
 0% 

Hook saytext


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
.Dare Devil.
Veteran Member
Join Date: Sep 2010
Old 10-01-2012 , 17:48   Hook saytext
Reply With Quote #1

Hello, i found a code example here: http://wiki.alliedmods.net/Commands_...erver_Commands

Quote:
Hooking Commands

A common example is hooking the say command. Let's say we want to tell players whether FF is enabled when they say '/ff' in game.
Before we implement this, a common point of confusion with the 'say' command is that Half-Life 2 (and Half-Life 1), by default, send it with the text in one big quoted string. This means if you say "I like hot dogs," your command will be broken down as such:
Argument string: "I like hot dogs"
Argument count: 1
Argument #1: I like hot dogs
However, if a player types this in their console: say I like yams, it will be broken up as:
Argument string: I like yams
Argument count: 3
Argument #1: I
Argument #2: like
Argument #3: yams
Thus, to take into account both of these situations, we are going to use GetCmdArgString and manually parse the input.
PHP Code:
new Handle:ff INVALID_HANDLE
 
public OnPluginStart()
{
    
AddCommandListener(Command_Say"say")
    
AddCommandListener(Command_Say"say2")
    
AddCommandListener(Command_Say"say_team")
 
    
ff FindConVar("mp_friendlyfire")
}
 
public 
Action:Command_Say(client, const String:command[], argc)
{
    
decl String:text[192]
    new 
startidx 0
    
if (GetCmdArgString(textsizeof(text)) < 1)
    {
        return 
Plugin_Continue
    
}
 
    if (
text[strlen(text)-1] == '"')
    {
        
text[strlen(text)-1] = '\0'
        
startidx 1
    
}
 
    if (
strcmp(command"say2"false) == 0)
        
startidx += 4
 
    
if (strcmp(text[startidx], "ff"false) == 0)
    {
        if (
ff != INVALID_HANDLE)
        {
            if (
GetConVarBool(ff))
            {
                
PrintToChat(client"Friendly fire is enabled.")
            } else {
                
PrintToChat(client"Friendly fire is disabled.")
            }
            
/* Block the client's messsage from broadcasting */
            
return Plugin_Handled
        
}
    }
 
    
/* Let say continue normally */
    
return Plugin_Continue

As the text says in quote this hook will work if you say /ff
Im confused where are the code for "/" ?
I see only "ff" check. : S
.Dare Devil. is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 10-01-2012 , 17:54   Re: Hook saytext
Reply With Quote #2

Command that start with / and ! are automatically created when you use RegConsoleCmd.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 10-01-2012 at 17:55.
Powerlord is offline
.Dare Devil.
Veteran Member
Join Date: Sep 2010
Old 10-01-2012 , 18:16   Re: Hook saytext
Reply With Quote #3

Quote:
Originally Posted by Powerlord View Post
Command that start with / and ! are automatically created when you use RegConsoleCmd.
Right...
There comes my second question: how do i hook text without ! and / ? : P
( It's for in game ads blocker )
.Dare Devil. is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 10-01-2012 , 18:35   Re: Hook saytext
Reply With Quote #4

Quote:
Originally Posted by .Dare Devil. View Post
Right...
There comes my second question: how do i hook text without ! and / ? : P
( It's for in game ads blocker )
Exactly how you're doing it now. Either that or hook the SayText2 usermessage.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 10-01-2012 at 18:35.
Powerlord is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 10-02-2012 , 07:34   Re: Hook saytext
Reply With Quote #5

Look example from basetriggers.sp
__________________
Do not Private Message @me
Bacardi 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 17:20.


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