Raised This Month: $ Target: $400
 0% 

client_cmd() vs. console_cmd()


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
capndurk
Senior Member
Join Date: Feb 2006
Old 03-16-2006 , 15:45   client_cmd() vs. console_cmd()
Reply With Quote #1

I don't understand why one is more proper in a certain situation than another, unless they're interchangeable.

Quote:
Originally Posted by funcwiki
console_cmd - Sends a command to a player's console
Quote:
Originally Posted by funcwiki
client_cmd - Executes command on a player
From my understanding, console_cmd() would be used for any command executed as though the player were typing it into his own console himself, correct?

Examples: "voice_enable 0" (for instance, if you were to set this in info_changed to disable use of the microphone, through client-side)
"net_graph"
"cl_updaterate" etc...

From my understanding, console_cmd() would also be used to execute commands such as say and say_team in a certain situation, correct?

---

client_cmd(), on the other hand, would be used for things such as amx_slay or other commands that the server executes on the player, because the server has access to all commands, right?


I'd be grateful if someone were able to help me decipher these two commands.
capndurk is offline
Twilight Suzuka
bad
Join Date: Jul 2004
Location: CS lab
Old 03-16-2006 , 17:07  
Reply With Quote #2

They do the same thing, in different ways.
__________________
Twilight Suzuka is offline
Send a message via AIM to Twilight Suzuka Send a message via MSN to Twilight Suzuka
capndurk
Senior Member
Join Date: Feb 2006
Old 03-16-2006 , 18:11  
Reply With Quote #3

Wait so... what are the different ways, and why were there two different commands created to do the same thing?
capndurk is offline
Xanimos
Veteran Member
Join Date: Apr 2005
Location: Florida
Old 03-16-2006 , 18:53  
Reply With Quote #4

with console_cmd you can exec on players or server console by using 0 for id.
with client_cmd you can only exec on clients. The use of 0 for index will execute on all players.
Xanimos is offline
Send a message via AIM to Xanimos Send a message via MSN to Xanimos
capndurk
Senior Member
Join Date: Feb 2006
Old 03-16-2006 , 19:20  
Reply With Quote #5

Quote:
Originally Posted by Suicid3
with console_cmd you can exec on players or server console by using 0 for id.
with client_cmd you can only exec on clients. The use of 0 for index will execute on all players.
Well... that's not what the funcwiki says... console_cmd() with an index of 0 will still execute on all the players, not on the server console...
capndurk is offline
Xanimos
Veteran Member
Join Date: Apr 2005
Location: Florida
Old 03-16-2006 , 19:27  
Reply With Quote #6

Not true. If you look at the CVS you can see that it uses SERVER_COMMAND() when the index is less than 1

Code:
static cell AMX_NATIVE_CALL console_cmd(AMX *amx, cell *params) /* 2 param */
{
	int index = params[1];
	g_langMngr.SetDefLang(index);
	int len;
	char* cmd = format_amxstring(amx, params, 2, len);
	
	cmd[len++] = '\n';
	cmd[len] = 0;

	if (index < 1 || index > gpGlobals->maxClients)
	{
		SERVER_COMMAND(cmd);
	} else {
		CPlayer* pPlayer = GET_PLAYER_POINTER_I(index);
		
		if (!pPlayer->bot && pPlayer->initialized)
			CLIENT_COMMAND(pPlayer->pEdict, "%s", cmd);
	}

	return len;
}
Code:
static cell AMX_NATIVE_CALL client_cmd(AMX *amx, cell *params) /* 2 param */
{
	int len;
	char* cmd = format_amxstring(amx, params, 2, len);
	cmd[len++] = '\n';
	cmd[len] = 0;

	if (params[1] == 0)
	{
		for (int i = 1; i <= gpGlobals->maxClients; ++i)
		{
			CPlayer* pPlayer = GET_PLAYER_POINTER_I(i);
			if (!pPlayer->bot && pPlayer->initialized /*&& pPlayer->ingame*/)
				CLIENT_COMMAND(pPlayer->pEdict, "%s", cmd);
		}
	} else {
		int index = params[1];
		
		if (index < 1 || index > gpGlobals->maxClients)
		{
			LogError(amx, AMX_ERR_NATIVE, "Invalid player id %d", index);
			return 0;
		}
		
		CPlayer* pPlayer = GET_PLAYER_POINTER_I(index);
		
		if (!pPlayer->bot && pPlayer->initialized /*&& pPlayer->ingame*/)
			CLIENT_COMMAND(pPlayer->pEdict, "%s", cmd);
	}
	
	return len;
}
Xanimos is offline
Send a message via AIM to Xanimos Send a message via MSN to Xanimos
capndurk
Senior Member
Join Date: Feb 2006
Old 03-16-2006 , 20:14  
Reply With Quote #7

Whoa! Where did you get that information?!
capndurk is offline
Twilight Suzuka
bad
Join Date: Jul 2004
Location: CS lab
Old 03-16-2006 , 20:16  
Reply With Quote #8

That would be the source code to AMXx.
__________________
Twilight Suzuka is offline
Send a message via AIM to Twilight Suzuka Send a message via MSN to Twilight Suzuka
capndurk
Senior Member
Join Date: Feb 2006
Old 03-16-2006 , 20:30  
Reply With Quote #9

Jeez, I feel like a real noob asking this information... but...

Where can I find the source code to AMXx? Here? http://www.tcwonline.org/cgi-bin/viewcvs.cgi

This would greatly help me understand the commands that aren't explained very in-depth in the funcwiki.
capndurk is offline
Twilight Suzuka
bad
Join Date: Jul 2004
Location: CS lab
Old 03-16-2006 , 20:38  
Reply With Quote #10

All of them are explained in depth.
__________________
Twilight Suzuka is offline
Send a message via AIM to Twilight Suzuka Send a message via MSN to Twilight Suzuka
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:42.


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