• Running client-side console command upon loading into a server
    7 replies, posted
Greetings, I'd like to be able to run a command in my console when I load into a server, the script should be client-side, the objecitve is to be able to type something like Hello, if I can figure out how to run a console command upon loading into a server (automatically) it would be helpful. Thanks for your assistance, I've searched the boards to no avail, the closest I can find is this: [lua] hook.Add( "InitPostEntity", "join_con_commands", function() RunConsoleCommand( "con_filter_enable", "1" ) RunConsoleCommand( "con_filter_text_out", "text" ) end ) [/lua] And it dosen't seem to work for me, do I need to edit sv_allowcslua within the server for it to function? regarless of that, any help would be appreciated with the main question.
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/PlayerConnect]GM:PlayerConnect[/url] [editline]11th March 2017[/editline] Actually, that might not work... there's probably a better way to do what you're trying to do [editline]11th March 2017[/editline] I have no clue what con_filter_text_out actually does but maybe it needs cheats to work or something? Maybe you could use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/PlayerInitialSpawn]GM:PlayerInitialSpawn[/url] if it's possible to do that serverside? I have no idea
snip, read that wrong.
[QUOTE=MPan1;51943875][img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/PlayerConnect]GM:PlayerConnect[/url] [editline]11th March 2017[/editline] Actually, that might not work... there's probably a better way to do what you're trying to do [editline]11th March 2017[/editline] I have no clue what con_filter_text_out actually does but maybe it needs cheats to work or something? Maybe you could use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/PlayerInitialSpawn]GM:PlayerInitialSpawn[/url] if it's possible to do that serverside? I have no idea[/QUOTE] I don't wanna do this server-side, I want it to be client-side. Thanks for your attempt of assistance however, that was just some code I found which was intended to write a message upon joining a server but dosen't seem to work for me.
You require the PlayerInitialSpawn which is server-side. Out of interest, why don't you want to do it server-side?
InitPostEntity is essentially the clientsided PlayerInitialSpawn but better. It will be called when the player is valid and can start interacting with the server. When you attempt to send messages from the server to the client in PlayerInitialSpawn, it is possible that the client will not be fully initialized which may result in them not getting what you're trying to send them. If you're looking to just print a message in the console then you can use the print function with the InitPostEntity hook in the client realm [code]hook.Add("InitPostEntity","SaySomething",function() RunConsoleCommand("say","I am alive!") -- Say something ingame print("I am alive in the console too!") -- Say something in the console end) [/code]
If it needs to be done clientside then it doesn't need any hooks. Just do RunConsoleCommand("cmd") or LocalPlayer():ConCommand("cmd") in an autorun file.
[IMG]http://wiki.garrysmod.com/favicon.ico[/IMG] [URL="http://wiki.garrysmod.com/page/GM/Think"]GM:Think[/URL] is the first to initialize when the client spawns into the gameserver. [code] local function WelcomeMsg () hook.Remove ("Think", "SaySomething") LocalPlayer ():ConCommand ("say I am alive!") print ("I am alive in the console too!") end hook.Add ("Think","SaySomething", WelcomeMsg) [/code]
Sorry, you need to Log In to post a reply to this thread.