AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   client_cmd() vs. console_cmd() (https://forums.alliedmods.net/showthread.php?t=25590)

capndurk 03-16-2006 15:45

client_cmd() vs. console_cmd()
 
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. :)

Twilight Suzuka 03-16-2006 17:07

They do the same thing, in different ways.

capndurk 03-16-2006 18:11

Wait so... what are the different ways, and why were there two different commands created to do the same thing?

Xanimos 03-16-2006 18:53

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.

capndurk 03-16-2006 19:20

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...

Xanimos 03-16-2006 19:27

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;
}


capndurk 03-16-2006 20:14

Whoa! Where did you get that information?!

Twilight Suzuka 03-16-2006 20:16

That would be the source code to AMXx.

capndurk 03-16-2006 20:30

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.

Twilight Suzuka 03-16-2006 20:38

All of them are explained in depth.


All times are GMT -4. The time now is 16:42.

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