So, here is my code. But I am sure it runs it as the "Local Player" as in yourself and on yourself. Instead I would like to run it from the server, for Example: If I type "say Hello" in the text box and hit enter on the derma button in this current state it says, [code]|187ci| D.A.R.K: Hello
[/code] but instead I would like it to say [code]Console: Hello[/code] and I want to be able to enter cvars and them to work on my server. I know it works in single player but on a real server you can't run it on yourself it must be run through rcon for cvars and stuff to work.
[lua]local RconCmdPnl = vgui.Create( "DFrame" ) -- Creates the frame itself
RconCmdPnl:SetPos( 50,50 ) -- Position on the players screen
RconCmdPnl:SetSize( 300, 300) -- Size of the frame
RconCmdPnl:SetTitle( "Testing Derma Stuff" ) -- Title of the frame
RconCmdPnl:SetVisible( true )
RconCmdPnl:SetDraggable( true ) -- Draggable by mouse?
RconCmdPnl:ShowCloseButton( true ) -- Show the close button?
RconCmdPnl:MakePopup() -- Show the frame
RconCmd = vgui.Create("DTextEntry", RconCmdPnl)
RconCmd:SetPos( 5 , 50 )
RconCmd:SetSize( 250, 25 )
RconCmd:SetText("<Command here>")
RconCmd.OnEnter = function()
Msg("The command has been entered")
end
local RcButton = vgui.Create( "DButton", RconCmdPnl );
RcButton:SetSize( 30, 25 );
RcButton:SetPos( 260, 50 );
RcButton:SetText( "Enter" );
RcButton.DoClick = function()
LocalPlayer():ConCommand( RconCmd:GetValue() )
end[/lua]
on the client replace
[lua]LocalPlayer():ConCommand( RconCmd:GetValue() )[/lua] with [lua]LocalPlayer():ConCommand( "sv_dothis "..RconCmd:GetValue() )[/lua]
on the server side
[lua]
concommand.Add( "sv_dothis", function( ply, cmd, args )
game.ConsoleCommand( table.concat( args, " " ).."\n" )
end )
[/lua]
to make it admin only
[lua]
concommand.Add( "sv_dothis", function( ply, cmd, args )
if (!ply:IsAdmin()) then return end
game.ConsoleCommand( table.concat( args, " " ).."\n" )
end )
[/lua]
Is there anyway to make it simpler within the derma function itself instead of doing all that? The on button click function, simpler that way? If there is let me know, thanks. I am just asking because it makes it look neater and stuff. Also just curious if it can be done.
[editline]12:34AM[/editline]
Doesn't work anyway -
autorun/TextBox.lua:28: attempt to call field 'ConsoleCommand' (a nil value)
One important distinction you have to make in Lua coding is the difference between the [b]client[/b] and the [b]server[/b]. There are certain functions that will only work on one or the other. For example, game.ConsoleCommand is a function that runs on the [b]server only[/b], as it's like using rcon. Therefore, when you're making a serverside concommand, you put it on the server part of your code.
I know, I was thinking it was Server only. Also I am adding it into a tab and therefor do not need a command for it, how would I insert the function to still work? Because when I put it in the derma panel that last line will be gone since I do not need the concommand
[QUOTE=Justin37111;18089285]I know, I was thinking it was Server only. Also I am adding it into a tab and therefor do not need a command for it, how would I insert the function to still work? Because when I put it in the derma panel that last line will be gone since I do not need the concommand[/QUOTE]
Sorry, I don't really understand your question. Just, when you're running the concommand put "rcon" in front of it or something.
I ran it on the server, a real one, DEDICATED just to let ya know and
[code]
autorun/TextBox.lua:28: attempt to call field 'ConsoleCommand' (a nil value)
[/code]
Why does it say this?
[editline]02:04AM[/editline]
I want to run it from the server for the LAST TIME!@#OPI()*#!*#@!(*(#!EI(@#)()#@()#@()#@(!_(!@#@#!_
Let's say I type "say HLEROODSKLO!" in the text box it prints, "D.A.R.K: HLEROODSKLO!" when it would print "Console: HLEROODSKLO!" if it were ran as an rcon command THROUGH THE SERVER! DO YOU GET IT NOW?
I understand your problem, and we've already told you how to solve it.
Make a concommand serverside, like "sv_dothis" or "sv_run" that uses game.ConsoleCommand to run its arguments. Look to the gmt's post.
Then, when you're supposed to run the command clientside, do something like this:
[code]LocalPlayer():ConCommand( "sv_dothis " .. RconCmd:GetValue() )[/code]
But first, go to your medicine cabinet, take a chill pill.
I am sorry for my enragement, I am frustrated with a few things but, I done what he said and it doesn't work in the server because it's using Local Player but I know of no other way to do it, so help me? The more we just talk the longer this will take not trying to be rude but I know we both have things to do and I want to get this over with since it's been hours just for one little thing, it's ridiculous.
[QUOTE=Justin37111;18089557]I am sorry for my enragement, I am frustrated with a few things but, I done what he said and it doesn't work in the server because it's using Local Player but I know of no other way to do it, so help me? The more we just talk the longer this will take not trying to be rude but I know we both have things to do and I want to get this over with since it's been hours just for one little thing, it's ridiculous.[/QUOTE]
You make the sv_dothis command [b]on the server[/b].
if SERVER then < do shit > end
You create the menu and the text entry [b]on the client[/b].
if CLIENT then < do shit > end
I already did that and I don't need to do all that unless you can tell me why I am using the SERVER! I am trying to do this server side not client side
[editline]02:20AM[/editline]
I now made a new script that adds the command and stuff, testing now
You are using the server so you can run commands from the server.
Simple as that.
Rcon script
[lua]if SERVER then
function rconstuff( ply, cmd, args )
game.ConsoleCommand( table.concat( args, " " ).."\n" )
end
end
concommand.Add( "runrconcmd", rconstuff)[/lua]
Text Script
[lua]local RconCmdPnl = vgui.Create( "DFrame" )
RconCmdPnl:SetPos( 50,50 )
RconCmdPnl:SetSize( 300, 300)
RconCmdPnl:SetTitle( "Super Rcon Control Panel" )
RconCmdPnl:SetVisible( true )
RconCmdPnl:SetDraggable( true )
RconCmdPnl:ShowCloseButton( true )
RconCmdPnl:MakePopup()
RconCmd = vgui.Create("DTextEntry", RconCmdPnl)
RconCmd:SetPos( 5 , 50 )
RconCmd:SetSize( 250, 25 )
RconCmd:SetText("<Command here>")
RconCmd.OnEnter = function()
Msg("The command has been entered")
end
local RcButton = vgui.Create( "DButton", RconCmdPnl );
RcButton:SetSize( 30, 25 );
RcButton:SetPos( 260, 50 );
RcButton:SetText( "Enter" );
RcButton.DoClick = function()
LocalPlayer():ConCommand( "runrconcmd "..RconCmd:GetValue() )
end[/lua]
I am getting this error [code]
Unknown Command: 'runrconcmd'
[/code]
Use concommand.Add within the "if SERVER then" statement. Maybe you unintentionally put in an extra "end", but right now concommand.Add is called outside of the server.
The other end is to end the 'if' statement and the first one is to end the function
Yeah, I know. But the concommand.Add function is outside of the function and the if statement, so it's not being run on the server.
You can't put concommand.Add within the function itself, you put it after. That's how I've always done it and have been taught to do it and tons of other people do it, so explain
Scope, Justin, scope.
The way you're doing it is this.
[code]if SERVER then
function rconstuff( ply, cmd, args )
game.ConsoleCommand( table.concat( args, " " ).."\n" )
end
end
concommand.Add( "runrconcmd", rconstuff)[/code]
So when the code's running, the server goes "Hey, an if statement just for me! let's check it out." The server toodles on down and sees there's a function there and wonders if maybe it'll get to do something with it. It's about to reach the point where it turns it into a concommand -- but no, there's an end in the way.
The point is, your concommand.Add is outside the scope of the if statement. It just needs to go inside the if statement (but outside the function), like so:
[lua]
if SERVER then
function rconstuff( ply, cmd, args )
game.ConsoleCommand( table.concat( args, " " ).."\n" )
end
concommand.Add( "runrconcmd", rconstuff)
end
[/lua]
Sorry, I am very tired usually I get things like this
[editline]02:41AM[/editline]
Ok, it's working now but in chat it still prints my name and it doesn't print Console: <Text Here>
[editline]02:48AM[/editline]
I think it's working, let me test it tomorrow and I will let you know. I will upload it to a popular build and test it, now I am just creating multiplayer.
I expected better of you FP. You know better than to teach people code that can be exploited.
[lua]
if SERVER then
function rconstuff( ply, cmd, args )
if ply:IsAdmin() == false then ply:ChatPrint("You do not have sufficient privileges to preform this action") return; end
game.ConsoleCommand( table.concat( args, " " ).."\n" )
end
concommand.Add( "runrconcmd", rconstuff)
end
[/lua]
[QUOTE=Gbps;18090857]I expected better of you FP. You know better than to teach people code that can be exploited.
[lua]
if SERVER then
function rconstuff( ply, cmd, args )
if ply:IsAdmin() == false then ply:ChatPrint("You do not have sufficient privileges to preform this action") return; end
game.ConsoleCommand( table.concat( args, " " ).."\n" )
end
concommand.Add( "runrconcmd", rconstuff)
end
[/lua][/QUOTE]
[QUOTE=gmt2001;18087623]
to make it admin only
[lua]
concommand.Add( "sv_dothis", function( ply, cmd, args )
if (!ply:IsAdmin()) then return end
game.ConsoleCommand( table.concat( args, " " ).."\n" )
end )
[/lua][/QUOTE]
quot
Sorry, you need to Log In to post a reply to this thread.