Raised This Month: $51 Target: $400
 12% 

cmdSay hook


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
deprale
Senior Member
Join Date: Oct 2018
Location: Leeds
Old 01-22-2019 , 09:50   cmdSay hook
Reply With Quote #1

EDIT: UMM WRONG SECTION! IF SOMEONE CAN MOVE THIS TO SCRIPTING HELP THAT WOULD BE GREAT, THANKS!

I want to hook cmdSay or something similar (whichever you guys think is best).
I looked at the source code of some chat manager plugins to get an idea of how to accomplish it.


Let's say I want that the player in question (ALL OF MY PLAYERS WILL HAVE <%s> [%0.2f] after their nickname %s being their assigned LETTER(SKILL) and %0.2f being their raw skill in numbers) :
Player <C+> <105.24>: blablabla
to become this:
Player: blablabla

The source code of the skill function thingy is:
PHP Code:
formatNameidstring[ ], len )  
{  
    new 
pos get_user_nameidstringlen ), temp posFloat:skillskill_id;
    
get_user_skillidskill );
    
skill_id =  aes_statsx_get_skill_id(skill);

    if( 
stringpos ] == ']' )  
        while( 
pos && string[ --pos ] != '<' ) { }  
      
    if( 
pos != && pos != temp )  
        return 
formatexstringpos ], len pos"<%s> [%.2f]"g_skill_letters[skill_id], skill );  
    else  
        return 
formatexstringlen"%.22s <%s> [%.2f]"stringg_skill_letters[skill_id], skill );

    return 
PLUGIN_CONTINUE;

I will use the say hook in my main pug plugin, not in the plugin that contains this function since the pug plugin is the first plugin to be loaded.

I haven't found anything of use on the internet, and on allied modders, I did use the search function but it yielded nothing, maybe I didn't search properly, dunno... Any tips/help is appreciated!
__________________

Last edited by deprale; 01-22-2019 at 12:12.
deprale is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 01-22-2019 , 13:32   Re: cmdSay hook
Reply With Quote #2

There's thousands of examples and plugins to take a look at (ultimate chat, e.g.)
https://forums.alliedmods.net/showthread.php?t=236576
https://forums.alliedmods.net/showthread.php?t=297952
__________________









Last edited by CrazY.; 01-22-2019 at 13:34.
CrazY. is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 01-22-2019 , 16:33   Re: cmdSay hook
Reply With Quote #3

Look into SayText message(that's what you should send).
__________________

Last edited by HamletEagle; 01-22-2019 at 16:33.
HamletEagle is offline
deprale
Senior Member
Join Date: Oct 2018
Location: Leeds
Old 01-24-2019 , 14:18   Re: cmdSay hook
Reply With Quote #4

Thanks, HamletEagle!
Very useful!

EDIT: For anyone looking in the future, here's how I've done what I searched for! (the "if" mess CAN BE IMPROVED, BUT I DO NOT CARE ABOUT IT THAT MUCH TBH)
PHP Code:
new sayText;

public 
plugin_init()
{
sayText get_user_msgid ("SayText")
register_clcmd("say""handle_say")
}

public 
handle_say(id

    new 
message[192
    
read_args(message191
    
remove_quotes(message)

    if(!
message[0])
        return 
PLUGIN_HANDLED;

    new 
len;
    new 
name[32]
    
get_user_name(idname31)
    
len strlen(name);
    if (
len)
    {
    
name[len 13] = 0;
    }
    new 
alive is_user_alive(id
     
    if(
alive && !is_user_admin(id)) 
        
format(message191"^1%s^1: %s"namemessage
    else if(
alive && is_user_admin(id))
        
format(message191"^1%s ^3%s^1: %s"TAGnamemessage
    else if(!
alive)
        
format(message191"^1*DEAD* ^3%s^1: %s"namemessage)
    else if(!
alive && is_user_admin(id))
        
format(message191"^1*DEAD* ^3%s^1: %s"namemessage)
    else
        return 
PLUGIN_HANDLED;
     
    for(new 
1<= MAX_PLAYERSi++) 
    { 
        if(!
is_user_connected(i)) 
            continue 
     
        if(
alive && is_user_alive(i) || !alive && !is_user_alive(i)) // Prints the message 
        

            
message_begin(MSG_ONEg_msgid_SayText, {000}, i
            
write_byte(id
            
write_string(message
            
message_end() 
        } 
    } 
    return 
PLUGIN_CONTINUE 

2ND EDIT: I ACTUALLY FOUND AN EVEN BETTER WAY OF DEALING WITH THIS SIMPLY JUST USE THIS STOCK TO SET "FAKE" NAMES, THEY'RE ONLY VISUAL.

PHP Code:
// From: https://dev-cs.ru/resources/189/ (CREDITS)
stock set_user_fake_name(const id, const name[])
{
    for(new 
1<= MaxClientsi++)
    {
        if(
is_user_connected(i) && !is_user_hltv(i))
        {
            
message_begin(MSG_ONESVC_UPDATEUSERINFO_i);
            
write_byte(id 1);
            
write_long(get_user_userid(id));
            
write_char('\');
            write_char('
n');
            write_char('
a');
            write_char('
m');
            write_char('
e');
            write_char('
\');
            write_string(name);
            for(new i; i < 4; i++) write_long(0);
            message_end();
        }
    }

3RD EDIT: XD FOUND ANOTHER EVEN EASIER WAY, THANKS HAMLETEAGLE HAMLETEAGLE OLD POST
__________________

Last edited by deprale; 01-24-2019 at 22:42.
deprale 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:47.


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