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

Send command by Handle


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Fuck For Fun
Veteran Member
Join Date: Nov 2013
Old 05-04-2020 , 20:49   Send command by Handle
Reply With Quote #1

how can I want do some commands that can be sent in chat (and will appear as server cmd or client_cmd)

That I would make an array of it and who would have access to it for example
command level

commandprintmsg

commandsayinchat

PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>

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

enum _:Commands
{
    
RESTART_ROUND// how can hook that for public
    
ALLTALK
}

new const 
CommandsNameCommands ] [ ] =
{
    
"Restart Round",
    
"Alltalk" // that command will print in colorchat when i say !alltalk 1/0
}

new const 
InChatCommands ] [ ] =
{
    
"rr",
    
"alltalk"
}

new const 
AccessLevelCommands ] =
{
    
ADMIN_KICK,
    
ADMIN_KICK
}

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd"say""HandleSay" );
}

public 
HandleSay(client)
{
    new 
said[32];
    
read_argv(1said31);

    for (new 
0Commandsi++)
    {
                 
//
    
}
    return 
PLUGIN_CONTINUE;


public 
CmdRoundRestart(client)
{
    
set_cvar_num"sv_restart"str_to_num( ??? ) > str_to_num( ??? ) : );


public 
CmdTalk(client)
{
    new 
AdminSz32 ], NameSz32 ]; // is only example namesz
    
get_user_nameclientAdminSzcharsmax(AdminSz))
    
get_user_nameclientNameSzcharsmax(NameSz))
    
    
set_cvar_num"sv_alltalk"str_to_num( ??? ) > );
    
client_print_color(0print_team_red"^3%s^1 has used ^4Alltalk^1 command.",AdminSz)
    
client_print_color(clientprint_team_red"You changed the^4 All Talk^1 to: %d"get_cvar_num"sv_alltalk" ) );


Last edited by Fuck For Fun; 05-05-2020 at 03:46.
Fuck For Fun is offline
Send a message via Skype™ to Fuck For Fun
+ARUKARI-
AlliedModders Donor
Join Date: Jul 2004
Location: Japan
Old 05-04-2020 , 21:06   Re: Send command by Handle
Reply With Quote #2

PHP Code:
public HandleSay(client)
{
    new 
said[32];
    
read_argv(1said31);

    for (new 
0Commandsi++)
    {
        if (
equali(saidCommandsInChat[i]))
        {
            
// Chat Logic.
            
switch(i)
            {
                case 
ALLTALK// Command Level.
                    // ex
                    
break;
                default:
                    break;
            }
            return 
PLUGIN_HANDLED;
        }
    }
    return 
PLUGIN_CONTINUE;

__________________
GitHub
SteamWishlist

六四天安門事件

Last edited by +ARUKARI-; 05-04-2020 at 21:15.
+ARUKARI- is offline
Fuck For Fun
Veteran Member
Join Date: Nov 2013
Old 05-04-2020 , 21:18   Re: Send command by Handle
Reply With Quote #3

Quote:
Originally Posted by +ARUKARI- View Post
PHP Code:
public HandleSay(client)
{
    new 
said[32];
    
read_argv(1said31);

    for (new 
0Commandsi++)
    {
        if (
equali(saidCommandsInChat[i]))
        {
            
// Chat Logic.
            
switch(i)
            {
                case 
ALLTALK// Command Level.
                    // ex
                    
break;
                default:
                    break;
            }
            return 
PLUGIN_HANDLED;
        }
    }
    return 
PLUGIN_CONTINUE;

Okay I hope I've been able to do the right thing, but how advanced I want each command to be in PUBLIC is different by my definition and every approach will be in every order.
Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>

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

enum _:Commands
{
	RESTART_ROUND, // how can hook that for public
	ALLTALK
}

new const CommandsName[ Commands ] [ ] =
{
	"Restart Round",
	"Alltalk" // that command will print in colorchat when i say !alltalk 1/0
}

new const InChat[ Commands ] [ ] =
{
	"rr",
	"alltalk"
}

new const AccessLevel[ Commands ] =
{
	ADMIN_KICK,
	ADMIN_KICK
}

public plugin_init() {
	register_plugin(PLUGIN, VERSION, AUTHOR)
    
	register_clcmd( "say", "HandleSay" );
}

public HandleSay(client)
{
	new said[32];
	read_argv(1, said, 31);

	for (new i = 0; i < Commands; i++)
	{
		if (equali(said, InChat[i]))
		{
			// Chat Logic.
			return PLUGIN_HANDLED;
		}
	}
	return PLUGIN_CONTINUE;
} 

public CmdRoundRestart(client)
{
	set_cvar_num( "sv_restart", str_to_num( ??? ) > 0 ? str_to_num( ??? ) : 1 );
} 

public CmdTalk(client)
{
	new AdminSz[ 32 ], NameSz[ 32 ]; // is only example namesz
	get_user_name( client, AdminSz, charsmax(AdminSz))
	get_user_name( client, NameSz, charsmax(NameSz))
    
	set_cvar_num( "sv_alltalk", str_to_num( ??? ) > 0 ? 1 : 0 );
	client_print_color(0, print_team_red, "^3%s^1 has used ^4Alltalk^1 command.",AdminSz)
	client_print_color(client, print_team_red, "You changed the^4 All Talk^1 to: %d", get_cvar_num( "sv_alltalk" ) );
}
Fuck For Fun is offline
Send a message via Skype™ to Fuck For Fun
+ARUKARI-
AlliedModders Donor
Join Date: Jul 2004
Location: Japan
Old 05-04-2020 , 21:27   Re: Send command by Handle
Reply With Quote #4

How do you use CommandsName?

PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>

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

enum _:Commands
{
    
RESTART_ROUND// how can hook that for public
    
ALLTALK
}

new const 
CommandsNameCommands ] [ ] =
{
    
"Restart Round",
    
"Alltalk" // that command will print in colorchat when i say !alltalk 1/0
}

new const 
InChatCommands ] [ ] =
{
    
"rr",
    
"alltalk"
}

new const 
AccessLevelCommands ] =
{
    
ADMIN_KICK,
    
ADMIN_KICK
}

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd"say""HandleSay" );
}

public 
HandleSay(client)
{
    new 
said[32];
    new 
param[3];
    
read_argv(1said31);
    
read_argv(2param2);

    for (new 
0Commandsi++)
    {
        if (!(
get_user_flags(client) & AccessLevel[i]))
            continue;

        if (
equali(saidInChat[i]))
        {
            
// Chat Logic.
            
switch(i)
            {
                case 
RESTART_ROUND:
                    
CmdRoundRestart(clientparam);
                case 
ALLTALK:
                    
CmdTalk(clientparam);
            }
            return 
PLUGIN_HANDLED;
        }
    }
    return 
PLUGIN_CONTINUE;


public 
CmdRoundRestart(clientparam[])
{
    
set_cvar_num"sv_restart"str_to_numparam ) > str_to_numparam ) : );


public 
CmdTalk(clientparam[])
{
    new 
AdminSz32 ], NameSz32 ]; // is only example namesz
    
get_user_nameclientAdminSzcharsmax(AdminSz))
    
get_user_nameclientNameSzcharsmax(NameSz))
    
    
set_cvar_num"sv_alltalk"str_to_numparam ) > );
    
client_print_color(0print_team_red"^3%s^1 has used ^4Alltalk^1 command.",AdminSz)
    
client_print_color(clientprint_team_red"You changed the^4 All Talk^1 to: %d"get_cvar_num"sv_alltalk" ) );

__________________
GitHub
SteamWishlist

六四天安門事件
+ARUKARI- is offline
Fuck For Fun
Veteran Member
Join Date: Nov 2013
Old 05-04-2020 , 21:39   Re: Send command by Handle
Reply With Quote #5

Quote:
Originally Posted by +ARUKARI- View Post
How do you use CommandsName?

PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>

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

enum _:Commands
{
    
RESTART_ROUND// how can hook that for public
    
ALLTALK
}

new const 
CommandsNameCommands ] [ ] =
{
    
"Restart Round",
    
"Alltalk" // that command will print in colorchat when i say !alltalk 1/0
}

new const 
InChatCommands ] [ ] =
{
    
"rr",
    
"alltalk"
}

new const 
AccessLevelCommands ] =
{
    
ADMIN_KICK,
    
ADMIN_KICK
}

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd"say""HandleSay" );
}

public 
HandleSay(client)
{
    new 
said[32];
    new 
param[3];
    
read_argv(1said31);
    
read_argv(2param2);

    for (new 
0Commandsi++)
    {
        if (!(
get_user_flags(client) & AccessLevel[i]))
            continue;

        if (
equali(saidInChat[i]))
        {
            
// Chat Logic.
            
switch(i)
            {
                case 
RESTART_ROUND:
                    
CmdRoundRestart(clientparam);
                case 
ALLTALK:
                    
CmdTalk(clientparam);
            }
            return 
PLUGIN_HANDLED;
        }
    }
    return 
PLUGIN_CONTINUE;


public 
CmdRoundRestart(clientparam[])
{
    
set_cvar_num"sv_restart"str_to_numparam ) > str_to_numparam ) : );


public 
CmdTalk(clientparam[])
{
    new 
AdminSz32 ], NameSz32 ]; // is only example namesz
    
get_user_nameclientAdminSzcharsmax(AdminSz))
    
get_user_nameclientNameSzcharsmax(NameSz))
    
    
set_cvar_num"sv_alltalk"str_to_numparam ) > );
    
client_print_color(0print_team_red"^3%s^1 has used ^4Alltalk^1 command.",AdminSz)
    
client_print_color(clientprint_team_red"You changed the^4 All Talk^1 to: %d"get_cvar_num"sv_alltalk" ) );

something like that:
Code:
%n use %s", CommandsName[ command ]
how could is can be in public?

If I have access to alltalk by enum, as I write in say
!alltalk 1
I want it to send a command through CMD that it will run and then I print it in chat
Code:
myname has set allalk to "1"
Or do I want to do slay me or someone?
So I also have to do a test if the player exists
blabla has slayed blabla.
Code:
			new player = find_player( "bl", szName );
			
			if( ! player )//i guess it wont check the szName is not true some how i did it before and it failed
			{
				player = find_player( "cl", szName );
		
				if( ! player )
				{
					player = find_player( "dl", szName );
			
					if( ! player )
					{
						ColorChat(client, "^3Error^1: You must write a valid player.");
						return PLUGIN_HANDLED;
					}
				}
			}

Last edited by Fuck For Fun; 05-04-2020 at 21:55.
Fuck For Fun is offline
Send a message via Skype™ to Fuck For Fun
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-04-2020 , 22:06   Re: Send command by Handle
Reply With Quote #6

If you're trying to hook for example "!rr" and you have "rr" as the command in your array, try:
PHP Code:
if (equali(said], InChat[i])) 
__________________
Bugsy is offline
+ARUKARI-
AlliedModders Donor
Join Date: Jul 2004
Location: Japan
Old 05-04-2020 , 22:37   Re: Send command by Handle
Reply With Quote #7

PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>
#pragma semicolon 1

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

enum _:Commands
{
    
RESTART_ROUND// how can hook that for public
    
ALLTALK,
    
SLAY,
};

new const 
CommandsNameCommands ] [ ] =
{
    
"Restart Round",
    
"Alltalk"// that command will print in colorchat when i say !alltalk 1/0
    
"Slay"
};

new const 
InChatCommands ] [ ] =
{
    
"rr",
    
"alltalk",
    
"slay"
};

new const 
AccessLevelCommands ] =
{
    
ADMIN_KICK,
    
ADMIN_KICK,
    
ADMIN_SLAY,
};

public 
plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR);
    
    
register_clcmd"say""HandleSay" );
}

public 
HandleSay(client)
{
    new 
said[32];
    new 
param[3];
    
read_argv(1said31);
    
read_argv(2param2);

    for (new 
0Commandsi++)
    {
        if (!(
get_user_flags(client) & AccessLevel[i]))
            continue;

        
// @Bugsy Supported: said[0] is "!"
        
if (equali(said[1], InChat[i]))
        {
            
// Chat Logic.
            
switch(i)
            {
                case 
RESTART_ROUND:
                    
CmdRoundRestart(clientparam);
                case 
ALLTALK:
                    
CmdTalk(clientparam);
                case 
SLAY:
                    
CmdSlay(clientparam);
            }
            return 
PLUGIN_CONTINUE;
        }
    }
    return 
PLUGIN_CONTINUE;


CmdRoundRestart(clientparam[])
{
    new 
num str_to_num(param);
    
set_cvar_num("sv_restart"num num 1);

    
client_print_color(0,      print_chat,      "^3%n ^1has used ^4%s command.",     clientCommandsName[RESTART_ROUND]);
    
client_print_color(0,      print_chat,      "^3%n ^1has set ^4%s ^1to ^4^"%i^""clientCommandsName[RESTART_ROUND], num);
    
client_print_color(clientprint_team_red,  "You changed the^4 %s^1 to: %d",             CommandsName[RESTART_ROUND], num);


CmdTalk(clientparam[])
{
    new 
num str_to_num(param);

    
set_cvar_num"sv_alltalk"num );

    
client_print_color(0,      print_chat,      "^3%n ^1has used ^4%s command.",     clientCommandsName[ALLTALK]);
    
client_print_color(0,      print_chat,      "^3%n ^1has set ^4%s ^1to ^4^"%i^""clientCommandsName[ALLTALK], num);
    
client_print_color(clientprint_team_red,  "You changed the^4 %s^1 to: %d",             CommandsName[ALLTALK], num);
}

CmdSlay(clientparam[])
{
    new 
player cmd_target(clientparamCMDTARGET_OBEY_IMMUNITY CMDTARGET_ALLOW_SELF CMDTARGET_ONLY_ALIVE);

    if (!
player)
    {
        
client_print_color(clientprint_chat"^3Error^1: You must write a valid player.");
        return 
PLUGIN_CONTINUE;
    }

    
server_cmd("amx_slay %s"param);
    new 
target get_user_userid(player);
    
client_print_color(0print_chat"^3%n ^1has used ^4%s command.",  clientCommandsName[SLAY]);
    
client_print_color(0print_chat"^3%n ^1has slayed ^4%n"clienttargetCommandsName[SLAY]);

    return 
PLUGIN_CONTINUE;

__________________
GitHub
SteamWishlist

六四天安門事件
+ARUKARI- is offline
Old 05-04-2020, 23:01
Fuck For Fun
This message has been deleted by Fuck For Fun. Reason: mistage
+ARUKARI-
AlliedModders Donor
Join Date: Jul 2004
Location: Japan
Old 05-05-2020 , 00:06   Re: Send command by Handle
Reply With Quote #8

this one.
PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>

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

new const PREFIX[] = "^4[System]^1";

enum _:Commands
{
    
RESTART_ROUND// how can hook that for public
    
ALLTALK,
    
ROUND_TIME,
    
SLAY
};

new const 
CommandsNameCommands ] [ ] =
{
    
"Restart Round",
    
"Alltalk",
    
"RoundTime",
    
"Slay"
};

new const 
InChatCommands ] [ ] =
{
    
"rr",
    
"alltalk",
    
"rt",
    
"slay"
};

new const 
AccessLevelCommands ] =
{    
    
ADMIN_KICK,    // flag = c
    
ADMIN_KICK,
    
ADMIN_LEVEL_C,    // flag o
    
ADMIN_SLAY
};

public 
plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR);
    
register_clcmd"say""HandleSay");
}

public 
HandleSay(client)
{
    new Array:
params;
    new 
said[64];
    new 
cmdline[64];
    new 
param[32];
    new 
0,iPos 0;
    
read_argv(1saidcharsmax(said));

    
params ArrayCreate(sizeof(param));
    
formatex(cmdlinecharsmax(cmdline), "%s "said);
    
    while(
iPos strlen(cmdline))
    {
        
split_string(cmdline[iPos += i], " "paramcharsmax(param));
        
ArrayPushString(paramsparam);
    }

    
ArrayGetString(params0cmdlinecharsmax(cmdline));
    
ArrayGetString(params1paramcharsmax(param));

    for (new 
0Commandsi++)
    {
        if (!(
get_user_flags(client) & AccessLevel[i]))
            continue;

        if (
equali(cmdline[1], InChat[i]))
        {
            
// Chat Logic.
            
switch(i)
            {
                case 
RESTART_ROUND:
                    
CmdRoundRestart(clientparam);
                case 
ALLTALK:
                    
CmdTalk(clientparam);
                case 
SLAY:
                    
CmdSlay(clientparam);    
                case 
ROUND_TIME:
                    
CmdRoundTime(clientparam);    
            }
            
ArrayDestroy(params);
            return 
PLUGIN_HANDLED// i want hide the command so HANDLED.
        
}
    }
    
ArrayDestroy(params);
    return 
PLUGIN_CONTINUE;


CmdRoundRestart(clientparam[])
{
    new 
num str_to_num(param);
    
set_cvar_num("sv_restart"num num 1);
    
    
client_print_color(0,      print_chat,      "^3%n ^1has set ^4%s ^1to ^4^"%i^""clientCommandsName[RESTART_ROUND], num);
    
client_print_color(clientprint_team_red,  "You changed the^4 %s^1 to: %d",             CommandsName[RESTART_ROUND], num);
}

CmdTalk(clientparam[])
{
    if (
strlen(param) <= 0)
    {
        
client_print_color(clientprint_team_red,  "Error: Not Parameter. ^4 %s^1 Requierd 0 or 1"CommandsName[ALLTALK]);
        return;
    }

    new 
num str_to_num(param);

    
set_cvar_num"sv_alltalk"num );

    
client_print_color(0,      print_chat,      "^3%n ^1has set ^4%s ^1to ^4^"%i^""clientCommandsName[ALLTALK], num);
    
client_print_color(clientprint_team_red,  "You changed the^4 %s^1 to: %d",             CommandsName[ALLTALK], num);
}

CmdSlay(clientparam[])
{
    new 
player find_player("afkl"param);
    if (!
player)
    {
        
client_print_color(clientprint_chat"^3Error^1: You must write a valid player.");
        return 
PLUGIN_CONTINUE;
    }

    new 
target get_user_userid(player);
    
client_cmd(client"amx_slay #%i"target);

    
client_print_color(0print_chat"^3%n ^1has slayed ^4%n"clienttargetCommandsName[SLAY]);
    return 
PLUGIN_CONTINUE;


CmdRoundTime(clientparam[])
{
    new 
num str_to_num(param);
    
    if ( 
str_to_floatparam ) >= 0.0 )
    {
        
client_print_color(0print_team_red"%s ^3%n^1 has changed the ^4Round Time^1."PREFIXclient);
        
client_print_color(clientprint_team_red"You changed the^4 Round Time^1 to: %.2f"str_to_floatparam ) );
        
        
set_cvar_num"mp_roundtime"num );
    }

Loops ArrayGetString when there are multiple parameters.
__________________
GitHub
SteamWishlist

六四天安門事件

Last edited by +ARUKARI-; 05-05-2020 at 00:07.
+ARUKARI- 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 16:02.


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