• How to make a command run on startup
    12 replies, posted
How would I have a command run the moment the player joins the server? I want the player to see a menu the moment he spawns, this is the command: lua_run_cl CreateCharacterWindow()
Wouldn't it be easier to call the function without any commands? hook.Add("InitPostEntity" , "Delay until all entities are created" , CreateCharacterWindow)
When he first joins the server? Do this in init.lua: [lua] function GM:PlayerInitialSpawn( pl ) RunConsoleCommand( "Command Name" ) end [/lua] Or when he spawns every time: [lua] function GM:PlayerSpawn( pl ) RunConsoleCommand( "Command Name" ) end [/lua]
[QUOTE=wakeboarderCWB;23092640]When he first joins the server? Do this in init.lua: [lua] function GM:PlayerInitialSpawn( pl ) RunConsoleCommand( "Command Name" ) end [/lua] Or when he spawns every time: [lua] function GM:PlayerSpawn( pl ) RunConsoleCommand( "Command Name" ) end [/lua][/QUOTE] Best to use pl:ConCommand so it doesn't send it to all players everytime. :wink:
[QUOTE=Cubar;23092746]Best to use pl:ConCommand so it doesn't send it to all players everytime. :wink:[/QUOTE] That code wouldn't even work, as it's server-side. RunConsoleCommand would run the command on the server, not the clients. Best way to do what you want is this. [lua]hook.Add( "OnEntityCreated", "OpenCharMenu", function( ent ) if ent:IsValid() and ent == LocalPlayer() then CreateCharacterWindow() end end )[/lua] Completely client-side.
[QUOTE=raBBish;23093079]That code wouldn't even work, as it's server-side. RunConsoleCommand would run the command on the server, not the clients. Best way to do what you want is this. [lua]hook.Add( "OnEntityCreated", "OpenCharMenu", function( ent ) if ent:IsValid() and ent == LocalPlayer() then CreateCharacterWindow() end end )[/lua] Completely client-side.[/QUOTE] You don't even read do you, was talking about pl:ConCommand not RunConsoleCommand.. it would work because your sending the command to the player from the server, as long as the concommand.Add("Command Name") is valid. :wink:
[QUOTE=raBBish;23093079]That code wouldn't even work, as it's server-side. RunConsoleCommand would run the command on the server, not the clients. Best way to do what you want is this. [lua]hook.Add( "OnEntityCreated", "OpenCharMenu", function( ent ) if ent:IsValid() and ent == LocalPlayer() then CreateCharacterWindow() end end )[/lua] Completely client-side.[/QUOTE] InitPostEntity :eng101:
[QUOTE=Cubar;23103635]You don't even read do you, was talking about pl:ConCommand not RunConsoleCommand.. it would work because your sending the command to the player from the server, as long as the concommand.Add("Command Name") is valid. :wink:[/QUOTE] Sorry, I quoted the wrong post :eng99: But you were still wrong, RunConsoleCommand server-side would just run the command on server, not send it to all clients like you said. [editline]11:55PM[/editline] [QUOTE=|FlapJack|;23109408]InitPostEntity :eng101:[/QUOTE] I didn't know that works and I missed your first post, cool :v:
[QUOTE=raBBish;23110339]Sorry, I quoted the wrong post :eng99: But you were still wrong, RunConsoleCommand server-side would just run the command on server, not send it to all clients like you said. [editline]11:55PM[/editline] I didn't know that works and I missed your first post, cool :v:[/QUOTE] You're wrong, i wasn't talking about Running an console command server side, i was talking about using the pl:ConCommand serverside. I quoted his post period.
[QUOTE=Cubar;23112694]You're wrong, i wasn't talking about Running an console command server side, i was talking about using the pl:ConCommand serverside. I quoted his post period.[/QUOTE] In the code you quoted, wakeboarder used RunConsoleCommand server-side. In your post, [QUOTE=Cubar;23092746]Best to use pl:ConCommand so it doesn't send it to all players everytime. :wink:[/QUOTE] you're implying that RunConsoleCommand sends it to all players if it's called. I don't see where I'm wrong.
Kids, kids... You're both right.
[QUOTE=Busymonkey;23113957]Kids, kids... You're both right.[/QUOTE] I'm older than you :haw: Enough derailing now. OP, use Flapjack's solution in the first reply.
Probably. Im 16.
Sorry, you need to Log In to post a reply to this thread.