• Derma Opens for everyone!?
    9 replies, posted
Hey my Derma Is being dumb. When someone types !class it opens up for everyone. Not only the user, also sometimes if i open it ( first one in ) it doesnt open for them, but if they type it opens for me... This is weird. @crazy if you reading this then i think it has to do with what you said the other day but im not 100% sure. Here is the code in the cl_init.lua [code] //Class Picker function classpicker( ply, text, public ) if( string.sub( text, 1, 6 ) == "!class" ) then -- chat command to enter //The Base Menu local DermaPanel = vgui.Create( "DFrame" ) DermaPanel:SetPos( 100,25 ) -- Position on the players screen DermaPanel:SetSize( 1150, 610 ) -- Size of the frame DermaPanel:SetTitle( "Class Setup" ) -- Title of the frame DermaPanel:SetVisible( true ) -- Derp! DermaPanel:SetDraggable( false ) -- Draggable by mouse? DermaPanel:ShowCloseButton( true ) -- Show the close button? DermaPanel:MakePopup() -- Show the frame? //Buttons local DermaButton = vgui.Create( "DButton" ) DermaButton:SetParent( DermaPanel ) -- Set parent to our "DermaPanel" DermaButton:SetText( "Assault" ) DermaButton:SetPos( 25, 50 ) DermaButton:SetSize( 150, 50 ) DermaButton.DoClick = function ( ply ) RunConsoleCommand("class1") end local DermaButton = vgui.Create( "DButton" ) DermaButton:SetParent( DermaPanel ) -- Set parent to our "DermaPanel" DermaButton:SetText( "Scout" ) DermaButton:SetPos( 25, 100 ) DermaButton:SetSize( 150, 50 ) DermaButton.DoClick = function () RunConsoleCommand("class2") end local DermaButton = vgui.Create( "DButton" ) DermaButton:SetParent( DermaPanel ) -- Set parent to our "DermaPanel" DermaButton:SetText( "Gunner" ) DermaButton:SetPos( 25, 150 ) DermaButton:SetSize( 150, 50 ) DermaButton.DoClick = function () RunConsoleCommand( "class3" ) -- What happens when you press the button end local DermaButton = vgui.Create( "DButton" ) DermaButton:SetParent( DermaPanel ) -- Set parent to our "DermaPanel" DermaButton:SetText( "Sniper" ) DermaButton:SetPos( 25, 200 ) DermaButton:SetSize( 150, 50 ) DermaButton.DoClick = function () RunConsoleCommand( "kill" ) -- What happens when you press the button end local DermaButton = vgui.Create( "DButton" ) DermaButton:SetParent( DermaPanel ) -- Set parent to our "DermaPanel" DermaButton:SetText( "Assassin" ) DermaButton:SetPos( 25, 250 ) DermaButton:SetSize( 150, 50 ) DermaButton.DoClick = function () RunConsoleCommand( "kill" ) -- What happens when you press the button end local DermaButton = vgui.Create( "DButton" ) DermaButton:SetParent( DermaPanel ) -- Set parent to our "DermaPanel" DermaButton:SetText( "Majors Assault" ) DermaButton:SetPos( 25, 300 ) DermaButton:SetSize( 150, 50 ) DermaButton.DoClick = function () ply:PrintMessage( HUD_PRINTTALK, "Not Unlocked" ) -- What happens when you press the button end local DermaButton = vgui.Create( "DButton" ) DermaButton:SetParent( DermaPanel ) -- Set parent to our "DermaPanel" DermaButton:SetText( "Advanced Scout" ) DermaButton:SetPos( 25, 350 ) DermaButton:SetSize( 150, 50 ) DermaButton.DoClick = function () ply:PrintMessage( HUD_PRINTTALK, "Not Unlocked" ) -- What happens when you press the button end local DermaButton = vgui.Create( "DButton" ) DermaButton:SetParent( DermaPanel ) -- Set parent to our "DermaPanel" DermaButton:SetText( "Mega Gunner" ) DermaButton:SetPos( 25, 400 ) DermaButton:SetSize( 150, 50 ) DermaButton.DoClick = function () ply:PrintMessage( HUD_PRINTTALK, "Not Unlocked" ) -- What happens when you press the button end local DermaButton = vgui.Create( "DButton" ) DermaButton:SetParent( DermaPanel ) -- Set parent to our "DermaPanel" DermaButton:SetText( "Officer Sniper" ) DermaButton:SetPos( 25, 450 ) DermaButton:SetSize( 150, 50 ) DermaButton.DoClick = function () ply:PrintMessage( HUD_PRINTTALK, "Not Unlocked" ) -- What happens when you press the button end local DermaButton = vgui.Create( "DButton" ) DermaButton:SetParent( DermaPanel ) -- Set parent to our "DermaPanel" DermaButton:SetText( "Pro Player" ) DermaButton:SetPos( 25, 500 ) DermaButton:SetSize( 150, 50 ) DermaButton.DoClick = function () ply:PrintMessage( HUD_PRINTTALK, "Not Unlocked" ) -- What happens when you press the button end end end hook.Add( "OnPlayerChat", "classpicker", classpicker ) [/code]
OnPlayerChat is called whenever someone types in chat. So if one person types !class the hook is called for all players. You would need to check if the typer is the local player.
[QUOTE=ms333;45847501]OnPlayerChat is called whenever someone types in chat. So if one person types !class the hook is called for all players. You would need to check if the typer is the local player.[/QUOTE] ahhh thanks ill see if that fixes it thanks :) [editline]30th August 2014[/editline] [QUOTE=ms333;45847501]OnPlayerChat is called whenever someone types in chat. So if one person types !class the hook is called for all players. You would need to check if the typer is the local player.[/QUOTE] Wait this is the hook, im not sure how to change the hook functions, and what ones there are to do it only on the local player typing this.
[QUOTE=Vizik;45847523]ahhh thanks ill see if that fixes it thanks :) [editline]30th August 2014[/editline] Wait this is the hook, im not sure how to change the hook functions, and what ones there are to do it only on the local player typing this.[/QUOTE] [lua] if (SERVER) then function openClass(ply, text, public) if (string.sub(text, 1, 6) == "!class") then ply:ConCommand("Your Console Command Here") return false end end hook.Add("PlayerSay", "classmenu", openClass) end [/lua]
[QUOTE=shadowslayer9;45847558][lua] if (SERVER) then function openClass(ply, text, public) if (string.sub(text, 1, 6) == "!class") then ply:ConCommand("Your Console Command Here") return false end end hook.Add("PlayerSay", "classmenu", openClass) end [/lua][/QUOTE] So your saying that i need to make the Derma open with a command, then use string.sub to make it to where if !class is typed then it runs the command. btw im not to familiar with ConCommand. The wiki was hard to understand with that. Thanks :)
[QUOTE=Vizik;45847592]So your saying that i need to make the Derma open with a command, then use string.sub to make it to where if !class is typed then it runs the command. btw im not to familiar with ConCommand. The wiki was hard to understand with that. Thanks :)[/QUOTE] You can use console commands if you want or you can use usermessages. It really doesn't make any difference.
It's an unneeded solution. Just check if ply (which is the typer in this case) is LocalPlayer()
[QUOTE=ms333;45847625]It's an unneeded solution. Just check if ply (which is the typer in this case) is LocalPlayer()[/QUOTE] Im unsure how to do that to a hook? and already know that with a regular function like this [lua] local ply = LocalPlayer() [/lua] but whtas up with the hook? Would this be the solution? [lua] local ply = LocalPlayer( OnPlayerChat ) [/lua] Or is that like a dumb answer :P
[lua] if ply == LocalPlayer() then [/lua] [sp]Indeed it was.[/sp] [editline]n[/editline] Oh, and yeah, as I mentioned earlier, you don't have to make the hook run a function, but you can make the hook the function itself. (I find this alot cleaner and orginized, but thats just me) [lua] hook.Add("hook", "name", function(arguments) ... end) [/lua]
[QUOTE=Author.;45848038][lua] if ply == LocalPlayer() then [/lua] [sp]Indeed it was.[/sp] [editline]n[/editline] Oh, and yeah, as I mentioned earlier, you don't have to make the hook run a function, but you can make the hook the function itself. (I find this alot cleaner and orginized, but thats just me) [lua] hook.Add("hook", "name", function(arguments) ... end) [/lua][/QUOTE] Yea ive actually started using hooks running functions, i actually like it more looks cleaner. :)
Sorry, you need to Log In to post a reply to this thread.