• SWEP help
    3 replies, posted
[lua]local choices = {"models/props_c17/FurnitureChair001a.mdl", "models/props/cs_office/Chair_office.mdl"} if SERVER then AddCSLuaFile ("shared.lua") SWEP.Weight = 5 SWEP.AutoSwitchTo = false SWEP.AutoSwitchFrom = false net.Receive("ChoseAChair", function(len, ply) ply.ChairChoice = net.ReadUInt(8) end) elseif CLIENT then SWEP.PrintName = "Chair throwing gun" SWEP.Slot = 4 SWEP.SlotPos = 1 SWEP.DrawAmmo = false SWEP.DrawCrosshair = false language.Add("Undone_Thrown_SWEP_Entity","Undone Thrown SWEP Entity") end SWEP.Author = "MrPlonker" SWEP.Contact = "plonkeronpc@gmail.com" SWEP.Purpose = "Throw chairs around!" SWEP.Instructions = "Right click to bring up a menu of props, left click to fire!" SWEP.Category = "Category" SWEP.Spawnable = true SWEP.AdminSpawnable = true SWEP.ViewModel = "models/weapons/v_RPG.mdl" SWEP.WorldModel = "models/weapons/w_rocket_launcher.mdl" SWEP.Primary.ClipSize = -1 SWEP.Primary.DefaultClip = -1 SWEP.Primary.Automatic = false SWEP.Primary.Ammo = "none" SWEP.Secondary.ClipSize = -1 SWEP.Secondary.DefaultClip = -1 SWEP.Secondary.Automatic = false SWEP.Secondary.Ammo = "none" local ShootSound = Sound("Metal.SawbladeStick") function SWEP:Reload() end function SWEP:Think() end function SWEP:throw_attack (model_file) local tr = self.Owner:GetEyeTrace() self:EmitSound(ShootSound) self.BaseClass.ShootEffects(self) if (!SERVER) then return end local ent = ents.Create("prop_physics") ent:SetModel(model_file) ent:SetPos(self.Owner:EyePos() + (self.Owner:GetAimVector() * 16)) ent:SetAngles(self.Owner:EyeAngles()) ent:Spawn() local phys = ent:GetPhysicsObject() if !(phys && IsValid(phys)) then ent:Remove() return end phys:ApplyForceCenter(self.Owner:GetAimVector():GetNormalized() * math.pow(tr.HitPos:Length(), 3)) cleanup.Add(self.Owner, "props", ent) undo.Create ("Thrown_SWEP_Entity") undo.AddEntity (ent) undo.SetPlayer (self.Owner) undo.Finish() end function SWEP:PrimaryAttack() self:throw_attack("models/props/cs_office/Chair_office.mdl") end function SWEP:SecondaryAttack() Chair = vgui.Create("DFrame") ChairButton = vgui.Create("DButton") local selection = 1 button.DoClick = function() net.Start("ChoseAChair") net.WriteUInt(selection, 8) net.SendToServer() end end[/lua] So I've been playing around with vgui recently and come up with this chair gun similar to garrys except on Swep:SecondaryAttack() I want to bring up a gui menu where I can choose 2 choices on a centered screen which chair I want to use and then fire. Any ideas where I can go with this? [editline]5th March 2014[/editline] [lua]function SWEP:SecondaryAttack() local Panel = vgui.Create("DFrame") Panel:SetPos(200,200) Panel:SetSize(200,200) Panel:SetTitle( "Choose a chair! -Plonker" ) Panel:Center() Panel:SetVisible(true) Panel:SetDraggable(false) Panel:ShowCloseButton(true) Panel:MakePopup() local Icon = vgui.Create("Button", Panel) Icon:SetSize( 150,,50 ) Icon:SetPos(50,50) Icon:SetText("Chair 1") Icon:SetVisisble(true) function button:OnMousePressed() SWEP:Reload() end local Icon2 = vgui.Create("Button", Panel) Icon2:SetSize( 150,,50 ) Icon2:SetPos(200,200) Icon2:SetText("Chair 1") Icon2:SetVisisble(true) function button:OnMousePressed() SWEP:Reload() end end[/lua] Ok so I have this now, but the menu doesn't show. Why?
SecondaryAttack() is a shared hook, you are executing it both serverside and clientside, while all vgui are clientside.
Primary and SecondaryAttack functions are [b]NOT[/b] called on client when you are in singleplayer.
Thank you!
Sorry, you need to Log In to post a reply to this thread.