Facepunch / garrysmod-requests

Feature requests for Garry's Mod
84 stars 24 forks source link

Change ShowHelp, ShowTeam, ShowSpare1, & ShowSpare2 to shared or client #100

Open ghost opened 11 years ago

ghost commented 11 years ago

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.

Acecool commented 11 years ago

I support this, I also think a lot of the KeyPress / BindPress stuff needs to be completely revamped.

ghost commented 9 years ago

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.

Sandbox

function GM:ShowHelp( ply )

     ply:SendLua( "hook.Run( 'StartSearch' )" );

end

Base

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.

handsomematt commented 9 years ago

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.

Sandbox https://github.com/garrynewman/garrysmod/blob/master/garrysmod/gamemodes/sandbox/gamemode/init.lua#L109

function GM:ShowHelp( ply )

 ply:SendLua( "hook.Run( 'StartSearch' )" );

end

Base https://github.com/garrynewman/garrysmod/blob/4eb9bb19dcfac06007691376ecaf2dbc56efa6b2/garrysmod/gamemodes/base/gamemode/init.lua#L92

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 .

robotboy655 commented 9 years ago

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
ghost commented 9 years ago

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.

robotboy655 commented 9 years ago

@vonspot, unlikely. You shouldn't use net/umsg for this, you should use the method I posted, it's better.

Acecool commented 9 years ago

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 ).

robotboy655 commented 9 years ago

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.

Kefta commented 8 years ago

You can just check in StartCommand