AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved How to get executors name in chat (https://forums.alliedmods.net/showthread.php?t=309267)

blAck. 07-19-2018 13:44

How to get executors name in chat
 
Code:

#include <amxmodx>
#include <amxmisc>
#include <colorchat>

public plugin_init() {
        register_plugin(PLUGIN, VERSION, AUTHOR)
       
        register_clcmd("say /test", "test")
}

public test()
{
    ColorChat(0, GREEN, "Player (player name) used /test command."); 
}

How can I get a name of player who typed /test.
Replace it with (player name)

iceeedr 07-19-2018 13:56

Re: How to get executors name in chat
 
PHP Code:


#include <amxmodx>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "author"


public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("say""Say_Hook")
    
register_clcmd("say_team""Say_Hook")
}

public 
Say_Hook(id)
{
    new 
szMessage[36
    
read_args(szMessagecharsmax(szMessage)) 
    
remove_quotes(szMessage)
    
    if(
equali(szMessage,".test") || equali(szMessage,"/test"))
    {
        new 
szName[32]
        
get_user_name(idszNamecharsmax(szName))
        
        
client_print(0print_chat"[AMXX] My name is %s."szName)
        return 
PLUGIN_HANDLED
    
}
    return 
PLUGIN_CONTINUE



Celena Luna 07-19-2018 13:59

Re: How to get executors name in chat
 
PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <colorchat>

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
register_clcmd("say /test""test")
    
register_clcmd("say_team /test""test")
}

public 
test(id)
{
    static 
szName[64]
    
get_user_name(idszNamecharsmax(szName))
    
ColorChat(0GREEN"Player %s used /test command."szName);  


@iceeedr: I don't think you need to hook say just for this

blAck. 07-19-2018 14:03

Re: How to get executors name in chat
 
Quote:

Originally Posted by iceeedr (Post 2604839)
PHP Code:


#include <amxmodx>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "author"


public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("say""Say_Hook")
    
register_clcmd("say_team""Say_Hook")
}

public 
Say_Hook(id)
{
    new 
szMessage[36
    
read_args(szMessagecharsmax(szMessage)) 
    
remove_quotes(szMessage)
    
    if(
equali(szMessage,".test") || equali(szMessage,"/test"))
    {
        new 
szName[32]
        
get_user_name(idszNamecharsmax(szName))
        
        
client_print(0print_chat"[AMXX] My name is %s."szName)
        return 
PLUGIN_HANDLED
    
}
    return 
PLUGIN_CONTINUE



Thanks buddy ^^

iceeedr 07-19-2018 14:54

Re: How to get executors name in chat
 
Quote:

Originally Posted by Celena Luna (Post 2604840)
PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <colorchat>

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
register_clcmd("say /test""test")
    
register_clcmd("say_team /test""test")
}

public 
test(id)
{
    static 
szName[64]
    
get_user_name(idszNamecharsmax(szName))
    
ColorChat(0GREEN"Player %s used /test command."szName);  


@iceeedr: I don't think you need to hook say just for this

Yes, I also agree, but I like to always have a "more complete" function, in case they want to implement with others "says".

fysiks 07-19-2018 22:11

Re: How to get executors name in chat
 
Register each command individually if you can, it will be more efficient.

There are a few cases where the only method is to hook "say" and/or "say_team" but only use it if there is no other way to do it.

Natsheh 07-19-2018 22:24

Re: How to get executors name in chat
 
Quote:

Originally Posted by Celena Luna (Post 2604840)
PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <colorchat>

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
register_clcmd("say /test""test")
    
register_clcmd("say_team /test""test")
}

public 
test(id)
{
    static 
szName[64]
    
get_user_name(idszNamecharsmax(szName))
    
ColorChat(0GREEN"Player %s used /test command."szName);  


@iceeedr: I don't think you need to hook say just for this

Max name characters are 32 and not 64.

iceeedr 07-19-2018 22:40

Re: How to get executors name in chat
 
Quote:

Originally Posted by fysiks (Post 2604969)
Register each command individually if you can, it will be more efficient.

There are a few cases where the only method is to hook "say" and/or "say_team" but only use it if there is no other way to do it.

Could you explain better? Is it because of performance issues?

fysiks 07-19-2018 22:44

Re: How to get executors name in chat
 
Quote:

Originally Posted by iceeedr (Post 2604978)
Could you explain better? Is it because of performance issues?

That is what I said.

Quote:

Originally Posted by fysiks (Post 2604969)
Register each command individually if you can, it will be more efficient.

Plus it will be simpler code.

iceeedr 07-19-2018 23:13

Re: How to get executors name in chat
 
Quote:

Originally Posted by fysiks (Post 2604979)
That is what I said.



Plus it will be simpler code.

Oops sorry, I do not speak fluent English, the translation from efficient to Brazilian leads to more interpretations, but I understood your explanation. Thank you.


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

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