• Beginner Question about creating UI
    3 replies, posted
So, I am trying to create a weapon that shoots various objects at high velocities. I want to be able to change what item you are shooting by pasting the model into the context menu, but when I run my code I get this error: [CODE][ERROR] addons/chairlauncher/lua/weapons/chairgungui.lua:44: attempt to index upvalue 'frameUI' (a nil value) 1. Call - addons/chairlauncher/lua/weapons/chairgungui.lua:44 2. unknown - gamemodes/base/gamemode/cl_spawnmenu.lua:63 3. unknown - lua/includes/modules/concommand.lua:54[/CODE] Here is my source [CODE] local ply = LocalPlayer() local frameExists = false function ChairGunUI() //Creates a canvas to work on local Frame = vgui.Create("DFrame") frameExists = true Frame:SetPos(1920, 1080) Frame:SetSize(300,150) Frame:SetTitle("Chairgun Settings") Frame:SetVisible(true) Frame:SetDraggable(false) Frame:ShowCloseButton(false) Frame:MakePopup() Frame:SetKeyboardInputEnabled(true) Frame:SetMouseInputEnabled(true) Frame:SetKeyboardInputEnabled(false) Frame:SetMouseInputEnabled(false) /*Textbox for choosing your model */ local ModelNameInput = vgui.Create("DTextEntry", Frame) ModelNameInput:SetPos(25, 50) ModelNameInput:SetSize(75,85) ModelNameInput:SetText(ShootModel) ModelNameInput.OnEnter = function(self) ShootModel = self:GetValue() end end function GAMEMODE:OnContextMenuOpen() print( ply:GetActiveWeapon():GetClass() ) //Checking to make sure the hook works. It does :D if ((ply:GetActiveWeapon():GetClass() == 'chairgun') && (!frameExists)) then ChairGunUI() end else if ((ply:GetActiveWeapon():GetClass() == 'chairgun')) && (frameExists) then Frame:Show() end end function GAMEMODE:OnContextMenuClose() Frame:Hide() end[/CODE]
You have 'local' in front of the frame, so it only exists inside the function. Either change that, or create a function within ChairGunUI() that hides/removes it
Okay, so I changed a lot in my code. I found it works much better when I use a chat command to open up the GUI. Problem is, the GUI code is running serverside, not clientside and I have no idea how to fix this. Here is my code now: [CODE] SWEP.PrintName = "Chair Gun" SWEP.Author = "Kim Jong Bitch" SWEP.Instructions = "LMB: Single fire, RMB: Automatic" //Spawn Info SWEP.Spawnable = true SWEP.AdminOnly = false //Ammo Info //Primary Ammo SWEP.Primary.ClipSize = -1 SWEP.Primary.DefaultClip = -1 SWEP.Primary.Automatic = false SWEP.Primary.Ammo = "none" //Secondary Ammo SWEP.Secondary.ClipSize = -1 SWEP.Secondary.DefaultClip = -1 SWEP.Secondary.Automatic = true SWEP.Secondary.Ammo = "none" SWEP.Weight = 5 SWEP.AutoSwitchTo = true SWEP.AutoSwitchFrom = true SWEP.Slot = 1 SWEP.SlotPos = 1 SWEP.DrawAmmo = false SWEP.DrawCrosshair = true //models SWEP.ViewModel = "models/weapons/v_pistol.mdl" SWEP.WorldModel = "models/weapons/w_pistol.mdl" //The Model to shoot with. !!THIS IS A GLOBAL VARIABLE!! ShootModel = "models/props_combine/combine_train02a.mdl" //Precache Sounds - Experiment with this local ShootSound = Sound("Metal.SawBladeStick") function SWEP:PrimaryAttack() //Rate of fire self.Weapon:SetNextPrimaryFire( CurTime() + 0.5 ) //Call 'ThrowChair' self:ThrowModel( ShootModel ) end function SWEP:SecondaryAttack() self:ThrowModel( ShootModel ) self.Weapon:SetNextSecondaryFire( CurTime() + 0.1) end function SWEP:ThrowModel( model_file ) self:EmitSound( ShootSound ) //Play Precached Sounds if ( CLIENT ) then return end //If you are the client then STOP //Creates prop_physics entity --local ent = ents.Create( "prop_ragdoll" ) local ent = ents.Create( "prop_physics" ) //Set the entity's model_file ent:SetModel( model_file ) //Set ent spawn pos ent:SetPos( self.Owner:EyePos() + (self.Owner:GetAimVector() * 16) ) ent:SetAngles( self.Owner:EyeAngles() ) ent:Spawn() //Get Physics obj local phys = ent:GetPhysicsObject() if ( !IsValid( phys ) ) then ent:Remove() return end //Apply Force local velocity = self.Owner:GetAimVector() velocity = velocity * 100000000 velocity = velocity + ( VectorRand() * 10 ) --Random element? phys:ApplyForceCenter( velocity ) //Undo list cleanup.Add( self.Owner, "props", ent ) undo.Create( "that_fucking_bitch." ) undo.AddEntity( ent ) undo.SetPlayer( self.Owner ) undo.Finish() //Prevents the game from getting overwhelmed by props end /*GUI Elements*/ function ChairGunUI() //Creates a canvas to work on print(CLIENT) local ChairGunMenu = vgui.Create("DFrame") ChairGunMenu:SetPos(1920, 1080) ChairGunMenu:SetSize(300,150) ChairGunMenu:SetTitle("Chairgun Settings") ChairGunMenu:SetVisible(true) ChairGunMenu:SetDraggable(true) ChairGunMenu:ShowCloseButton(true) ChairGunMenu:MakePopup() /*Textbox for choosing your model */ local ModelNameInput = vgui.Create("DTextEntry", ChairGunMenu) ModelNameInput:SetPos(25, 50) ModelNameInput:SetSize(75,85) ModelNameInput:SetText(ShootModel) ModelNameInput.OnEnter = function(self) ShootModel = self:GetValue() end end hook.Add( "PlayerSay", "/chairgunmenu", ChairGunUI)[/CODE]
Did you try putting AddCSLuaFile() at the start (sends the file to the client)?
Sorry, you need to Log In to post a reply to this thread.