• F1 Help
    14 replies, posted
Yes, it's me again. And big surprise... I need help getting F1 working. :/ Anyways, here's my code to cl_init.lua , I'm trying to get this window to come up when the button is pressed but it isn't working, what am I doing wrong? [code] include( 'shared.lua' ) function makeSupplyWindow() checkSupplies = vgui.Create("DFrame") checkSupplies:SetPos( ScrW() / 1, ScrH() / 1 ) checkSupplies:SetSize( 800, 600 ) checkSupplies:SetVisible( true ) checkSupplies:SetDraggable( true ) checkSupplies:ShowCloseButton( true ) checkSupplies:MakePopup() barricade = vgui.Create("DButton") barricade:SetParent( checkSupplies ) barricade:SetText( "Baricades" ) barricade:SetPos( 50, 40 ) barricade:SetSize( 40, 30 ) barricade.DoClick = function ( btn ) local options = DermaMenu() options:AddOption("Short Plank", function() RunConsoleCommand( "makeWoodBoardSmall" ) end) end end function makeUndeadWindow() function checkRes() if(ply.Team==2) then makeSupplyWindow() end if(ply.Team==1) then makeUndeadWindow() end end end hook.Add( "ShowHelp", "commanding", checkRes ) [/code]
Check console for an error and report it here
I did... There was no error reported. XP [editline]07:33PM[/editline] WAIT... If the player isn't in a team, then nothing will happen will it? >_> Whoops. Sorry to have troubled you all if that is indeed the case.
ShhowHelp() is serversided. You're attempting to run it on the client.
[QUOTE=Jo The Shmo;22543827]ShhowHelp() is serversided. You're attempting to run it on the client.[/QUOTE] Oh, well that explains something. But wouldn't it also not show up if the player were not on a team?
No, it shows up regardless Also, what's with the completely open makeUndeadWindow?
D'OUGH! I haven't gotten around to that yet, but also I forgot to at least add an end. >_> [editline]08:22PM[/editline] Well I moved the hook into init.lua, but it's still not working. Can somebody please help? [editline]08:23PM[/editline] [QUOTE=TheNerdPest14;22544167]D'OUGH! I haven't gotten around to that yet, but also I forgot to at least add an end. >_> [editline]08:22PM[/editline] Well I moved the hook into init.lua, but it's still not working. Can somebody please help?[/QUOTE] Anybody?
Try and change [code]hook.Add( "ShowHelp", "commanding", checkRes )[/code] to: [code]concommand.Add( "showhelp", checkRes )[/code]
Instead of hook.Add( stuff here ), do this at the end of the function: [lua]usermessage.Hook( "UniqueName", checkRes )[/lua] Then, in init.lua, do this: [lua]function GM:ShowHelp( pl ) umsg.Start( "UniqueName", pl ) umsg.End() end[/lua]
It still isn't working, after I added the command. And I added a hook for good measure.
Did you try mine, TheNerdPest14? That works for me.
Ah, I found a problem, to get a players team, its ply:Team() and not ply.Team, so this [code]function checkRes() if(ply.Team==2) then makeSupplyWindow() end if(ply.Team==1) then makeUndeadWindow() end end end[/code] Should turn into this: [code]function checkRes() if(ply:Team()==2) then makeSupplyWindow() end if(ply:Team()==1) then makeUndeadWindow() end end end[/code] That is if ent.Team is not defined anywhere else (on the client).
Ahhh... I'll try that, thanks.
Scrap that, try this: [lua]function checkRes() local ply = LocalPlayer() if ply:Team() == 2 then makeSupplyWindow() end if ply:Team() == 1 then makeUndeadWindow() end end[/lua]
cl_init [lua]function makeSupplyWindow() checkSupplies = vgui.Create("DFrame") checkSupplies:SetPos( ScrW() / 1, ScrH() / 1 ) checkSupplies:SetSize( 800, 600 ) checkSupplies:SetVisible( true ) checkSupplies:SetDraggable( true ) checkSupplies:ShowCloseButton( true ) checkSupplies:MakePopup() barricade = vgui.Create("DButton") barricade:SetParent( checkSupplies ) barricade:SetText( "Baricades" ) barricade:SetPos( 50, 40 ) barricade:SetSize( 40, 30 ) barricade.DoClick = function ( btn ) local options = DermaMenu() options:AddOption("Short Plank", function() RunConsoleCommand( "makeWoodBoardSmall" ) end) end end function makeUndeadWindow() -- there's no code you gave us for this window, so im assuming you have some for it end usermessage.Hook("SupplyWindow", makeSupplyWindow) usermessage.Hook("UndeadWindow", makeUndeadWindow)[/lua] init [lua]function GM:ShowHelp() if(ply:Team() == 2) then umsg.Start("SupplyWindow") umsg.End() elseif(ply:Team() == 1) then umsg.Start("UndeadWindow") umsg.End() end end[/lua] You forgot the "()" after "Team" You called an if function, inside another if function when it was better to use elseif in this case It's best to do it this way, because you can use hooks to determine different instances Also, you defined options as a DermaMenu, why did you do that, surely you meant to define it as [b][url=http://wiki.garrysmod.com/?title=DMultiChoice]DMultiChoice [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] [b]EDIT[/b] I changed the "changeres" function to GM:ShowHelp so it would call every time you press the F1 key.
Sorry, you need to Log In to post a reply to this thread.