Open ghost opened 11 years ago
I support this, I also think a lot of the KeyPress / BindPress stuff needs to be completely revamped.
To bump and further my point I'd like to point out that Base and Sandbox use GM:ShowHelp and GM:ShowTeam to have the client tell the server to tell the client to execute client code. In the end I imagine efficiency would be impacted marginally, but writing this down I can't understand the justification for having these functions networked.
function GM:ShowHelp( ply )
ply:SendLua( "hook.Run( 'StartSearch' )" );
end
function GM:ShowTeam( ply )
-- excluded stuff that could be controlled at a different point on the server
-- like in GM:PlayerRequestTeam which is trigger by changeteam <id>
-- it would actually make more sense to control the logic here in GM:PlayerRequestTeam,
-- but that's just my opinion
ply:SendLua( "GAMEMODE:ShowTeam()" )
end
I don't see why these functions shouldn't be moved to the Client. In my own code I end up doing this:
function GM:ShowHelp(oPlayer) oPlayer:SendLua('GAMEMODE:ShowHelp()') end
function GM:ShowTeam(oPlayer) oPlayer:SendLua('GAMEMODE:ShowTeam()') end
function GM:ShowSpare1(oPlayer) oPlayer:SendLua('GAMEMODE:ShowSpare1()') end
function GM:ShowSpare2(oPlayer) oPlayer:SendLua('GAMEMODE:ShowSpare2()') end
I'll see if I can't figure out how to make a pull request but GM:ShowHelp doesn't even need to be changed besides aliasing GM:StartSearch to GM:ShowHelp. If I can't figure the pull request out I'll end up replying to this ticket with another post.
Just use KeyPress client side. Should consider these deprecated honestly. On 29 Oct 2014 14:56, "Matt" notifications@github.com wrote:
To bump and further my point I'd like to point out that Base and Sandbox use GM:ShowHelp and GM:ShowTeam to have the client tell the server to tell the client to execute client code. In the end I imagine efficiency would be impacted marginally, but writing this down I can't understand the justification for having these functions networked.
function GM:ShowHelp( ply )
ply:SendLua( "hook.Run( 'StartSearch' )" );
end
function GM:ShowTeam( ply )
-- excluded stuff that could be controlled at a different point on the server -- like in GM:PlayerRequestTeam which is trigger by changeteam <id> -- it would actually make more sense to control the logic here in GM:PlayerRequestTeam, -- but that's just my opinion ply:SendLua( "GAMEMODE:ShowTeam()" )
end
I don't see why these functions shouldn't be moved to the Client. In my own code I end up doing this:
function GM:ShowHelp(oPlayer) oPlayer:SendLua('GAMEMODE:ShowHelp()') endfunction GM:ShowTeam(oPlayer) oPlayer:SendLua('GAMEMODE:ShowTeam()') endfunction GM:ShowSpare1(oPlayer) oPlayer:SendLua('GAMEMODE:ShowSpare1()') endfunction GM:ShowSpare2(oPlayer) oPlayer:SendLua('GAMEMODE:ShowSpare2()') end
I'll see if I can't figure out how to make a pull request but GM:ShowHelp doesn't even need to be changed besides aliasing GM:StartSearch to GM:ShowHelp. If I can't figure the pull request out I'll end up replying to this ticket with another post.
— Reply to this email directly or view it on GitHub https://github.com/Facepunch/garrysmod-requests/issues/100#issuecomment-60938211 .
Not KeyPress, but PlayerBindPress, this is what I do in GMS:
function GM:PlayerBindPress( ply, bind, pressed )
if ( bind == "gm_showhelp" ) then RunConsoleCommand( "gms_help" ) end
if ( bind == "gm_showspare1" ) then RunConsoleCommand( "gms_sleep" ) end
end
Cool, that's exactly what I was looking for! So, curiously speaking, will these functions ever be deprecated or moved to the client? I'm just thinking that if a developer really needed the client to tell the server that it pushed the F1-4 binds they would use the net/umsg library.
@vonspot, unlikely. You shouldn't use net/umsg for this, you should use the method I posted, it's better.
Here's another method: https://dl.dropboxusercontent.com/u/26074909/tutoring/vgui/open_vgui_based_on_keypress.lua.html
The KeyPress hook is flawed, it doesn't always report which is why you'd want to use PlayerBindPress. On top of that, it also allows players to rebind their keys and your code to automatically see that ( if you look for the bind as in how Robot posted it ).
You all are missing the point of why the F1-F4 keys have hooks - they are console commands, that means that I can rebind gm_showhelp from F1 to Alt and it will still work, while your methods would not.
You can just check in StartCommand
As far as I know the only time these functions are used is to open / close / toggle a client side Derma. So why are these functions server side only? It seems unnecessary to have the client tell the server to tell the client to toggle a menu.