Player.ConCommand

From GMod Wiki

Jump to: navigation, search
Function
Syntax Player:ConCommand( String command )
Description:
Executes the passed string as a console command.
Returns: nil
In Object: Player
Realm: NewerShared.png
BBCode Link: [b][url=http://wiki.garrysmod.com/?title=Player.ConCommand]Player.ConCommand [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]



Examples

DescriptionThis will make all players disconnect.
Used onNewerServer.png
Code
for k,v in pairs(player.GetAll()) do
    v:ConCommand("disconnect")
end
OutputN/A


DescriptionThis will make the player the script is running on say something.
Used onNewerClient.png
Code
 
    LocalPlayer():ConCommand("say Hello, I didn't type this.") -- Deprecated
    RunConsoleCommand("say", "Hello, I didn't type this.")
 
OutputPlayer says "Hello, I didn't type this."


DescriptionThis example will create a console command serverside, and have a client run it. Our file name is "myscript.lua".
Used onNewerShared.png
Code
if SERVER then
    --Make sure clients download this script.
    AddCSLuaFile("myscript.lua")
 
    --Add a console command for clients to use.
    function recieveStuffFromPlayer(player,commandName,args)
        Msg("Recieved a message from "..player:Name().."! It says "..table.concat(args," ").."")
    end
    concommand.Add("recievestuff",recieveStuffFromPlayer)
end
if CLIENT then
   --When this script is loaded by the clients, have it run the console command we made on the server.
   LocalPlayer():ConCommand("recievestuff Hello! How are you?")
end
OutputServer says "Recieved a message from (player name)! It says Hello! How are you" whenever a client runs the script.


Additional Notes

See Also

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox