• Problems with VGUI panel and PlayerSpawn
    3 replies, posted
So, I've got two issues that I'm running into. The first is with a VGUI panel. The idea is to have players select a class when they join the server. At the moment, it's just a simple panel with some buttons. However, for whatever reason, the buttons don't show up. Additionally, this appears in console: WIP/gamemode/cl_init.lua:12: attempt to call method 'MakePopUp' (a nil value) The lua for the panel: [lua] function set_class() spawnmenu = vgui.Create( "DFrame" ) spawnmenu:SetPos( ScrW() / 2, ScrH() / 2 ) spawnmenu:SetSize( 340, 70 ) spawnmenu:SetTitle( "Set Class" ) spawnmenu:SetVisible( true ) spawnmenu:SetDraggable( true ) spawnmenu:ShowCloseButton( false ) spawnmenu:MakePopUp() class_scoot = vgui.Create( "DButton", spawnmenu ) class_scoot:SetPos( 10, 10 ) class_scoot:SetSize( 100, 50 ) class_scoot:SetText( "Fragile Speedster" ) class_scoot.DoClick = function() RunConsoleCommand( "vg_scout" ) end class_spah = vgui.Create( "DButton", spawnmenu ) class_spah:SetPos( 120, 10 ) class_spah:SetSize( 100, 50 ) class_spah:SetText( "Anti-Hero" ) class_spah.DoClick = function() RunConsoleCommand( "vg_spy" ) end class_havy = vgui.Create( "DButton", spawnmenu ) class_havy:SetPos( 230, 10 ) class_havy:SetSize( 100, 50 ) class_havy:SetText( "Husky Russkie" ) class_havy.DoClick = function() RunConsoleCommand( "vg_heavy" ) end end [/lua] Typing the commands into console works, however. The other issue is a problem with my PlayerSpawn. It works right except for the playermodels- I just get the unanimated, untextured model used for Gordon in Half-Life 2. Additionally, this appears in console: ERROR: GAMEMODE:'PlayerSpawn' Failed: WIP/gamemode/init.lua:60: attempt to index global 'GM' (a nil value) Again, the lua: [lua] function GM:PlayerSpawn( ply ) if ply:Team() == 1 then ply:SetWalkSpeed( 400 ) ply:SetJumpPower( 200 ) ply:SetMaxHealth( 100, true ) ply:SetHealth( 100 ) function GM:PlayerSetModel( ply ) util.PrechacheModel( "models/player/scout.mdl" ) ply:SetModel( "models/player/scout.mdl" ) end elseif ply:Team() ==2 then ply:SetWalkSpeed( 300 ) ply:SetJumpPower( 160 ) ply:SetMaxHealth( 125, true ) ply:SetHealth( 125 ) function GM:PlayerSetModel( ply ) util.PrechacheModel( "models/player/spy.mdl" ) ply:SetModel( "models/player/spy.mdl" ) end elseif ply:Team() == 3 then ply:SetWalkSpeed( 230 ) ply:SetJumpPower( 130 ) ply:SetMaxHealth( 200, true ) ply:SetHealth( 200 ) function GM:PlayerSetModel( ply ) util.PrechacheModel( "models/player/heavy.mdl" ) ply:SetModel( "models/player/heavy.mdl" ) end else ply:Spectate ( 6 ) end end [/lua] (I'm fully aware that TF2 models don't fit the HL2 bone structure and need work to animate properly. I'm using TF2 weapon models and plan on making them work. They fit well with the style I'm aiming for.)
[url]http://wiki.garrysmod.com/?title=Panel.MakePopup[/url] It's MakePop[b]u[/b]p, Lua is case sensitive. For your spawn question, it doesn't work like that, you should do this: [lua]function GM:PlayerSetModel( ply ) local model if ( ply:Team( ) == 1 ) then model = "scout" elseif ( ply:Team( ) == 2 ) then model = "spy" elseif ( ply:Team( ) == 3 ) then model = "heavy" end util.PrecacheModel( "models/player/" .. model .. ".mdl" ) ply:SetModel("models/player/" .. model .. ".mdl" ) end[/lua]
For your first question, it's MakePopup() not MakePop[b]U[/b]p()
Thanks. I've got the panel working now. I've still got a couple of problems, though. Now, the playermodel setting doesn't give me any errors, but I still get the floating untextured Gordon model. Also, PlayerSpawn seems to break my PlayerLoadout- the health and speed and such work right, but I don't spawn with any weapons.
Sorry, you need to Log In to post a reply to this thread.