F1 Help

Yes, it’s me again. And big surprise… I need help getting F1 working. :confused: 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?



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 )



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.

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]

Anybody?

Try and change


hook.Add( "ShowHelp", "commanding", checkRes )

to:


concommand.Add( "showhelp", checkRes )

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


function checkRes()
	if(ply.Team==2) then
		makeSupplyWindow()
		end
	if(ply.Team==1) then
		makeUndeadWindow()
		end
	end
end

Should turn into this:


function checkRes()
	if(ply:Team()==2) then
		makeSupplyWindow()
		end
	if(ply:Team()==1) then
		makeUndeadWindow()
		end
	end
end

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 **[DMultiChoice

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=DMultiChoice)**

EDIT

I changed the “changeres” function to GM:ShowHelp so it would call every time you press the F1 key.