• Create VGUI on Primary Attack
    21 replies, posted
Hello, I am a complete beginner on the LUA language and I need a little help with one of my attempts. Actually I'd like to create a swep and put it on a test server. This swep consists of when we use the Primary Attack, that it creates a DFrame and an HTML panel. I managed to write the code and execute it with the console, but I would like to execute it with a swep (no matter what the swep model is, I would change that later) with a left click, and it works on a server. I've been told about managing between init.lua and cl_init.lua, but I can't do it. Any leads? Here's the code (same as the tutorial) : local frame = vgui.Create( "DFrame" ) frame:SetTitle( "VGUI HTML SWEP TEST" ) frame:SetSize( 810, 634 ) frame:Center() frame:MakePopup() local html = vgui.Create( "HTML", frame ) html:Dock( FILL ) html:OpenURL( "https://www.google.fr" )
vgui_swep.lua That should do what you need, check the SWEP:PrimaryAttack function for the menu creation.
Couldn't you send a net message serverside to the swep owner, to open the VGUI?
I put it in the "weapons" folder, but it didn't do anything when I left clicked with the swep in hand :/
Theres not really any need for that though. Just use the .lua file I posted, that should work fine.
I put it in the "weapons" folder, but it didn't do anything when I left clicked with the swep in hand :/
Works perfectly fine for me, whats your file structure? I have it as "garrysmod/addons/testaddon/lua/weapons/vgui_swep.lua" and it works fine.
Here it is : AddCSLuaFile() if CLIENT then     SWEP.PrintName = "VGUI Opener"     SWEP.Slot = 1     SWEP.SlotPos = 1     SWEP.DrawAmmo = false     SWEP.DrawCrosshair = false end -- Variables that are used on both client and server SWEP.Author = "Name" SWEP.Instructions = "FF" SWEP.Contact = "" SWEP.Purpose = "FF" SWEP.ViewModel = Model( "" ) -- just change the model  SWEP.WorldModel = ( "" ) SWEP.ViewModelFOV = 85 SWEP.UseHands = true SWEP.Spawnable = true SWEP.AdminOnly = true SWEP.Category = "Custom Stuff" SWEP.Primary.ClipSize = -1      -- Size of a clip SWEP.Primary.DefaultClip = 0        -- Default number of bullets in a clip SWEP.Primary.Automatic = false      -- Automatic/Semi Auto SWEP.Primary.Ammo = "" SWEP.Secondary.ClipSize = -1        -- Size of a clip SWEP.Secondary.DefaultClip = -1     -- Default number of bullets in a clip SWEP.Secondary.Automatic = false        -- Automatic/Semi Auto SWEP.Secondary.Ammo = "" --[[------------------------------------------------------- Name: SWEP:Initialize() Desc: Called when the weapon is first loaded ---------------------------------------------------------]] function SWEP:Initialize()     self:SetHoldType("normal") end function SWEP:SetupDataTables() end --[[------------------------------------------------------- Name: SWEP:PrimaryAttack() Desc: +attack1 has been pressed ---------------------------------------------------------]] function SWEP:PrimaryAttack() if( CLIENT ) then if( not IsValid( VGUI_MENU_SWEP ) ) then VGUI_MENU_SWEP = vgui.Create( "DFrame" ) VGUI_MENU_SWEP:SetTitle( "VGUI HTML SWEP TEST" ) VGUI_MENU_SWEP:SetSize( 810, 634 ) VGUI_MENU_SWEP:Center() VGUI_MENU_SWEP:MakePopup() local html = vgui.Create( "HTML", VGUI_MENU_SWEP ) html:Dock( FILL ) html:OpenURL( "https://www.google.fr" ) else VGUI_MENU_SWEP:SetVisible( true ) end end end function SWEP:Holster() return true end function SWEP:Think() end function SWEP:DrawHUD() end function SWEP:SecondaryAttack() end (Sorry it's too long for code balise)
No, the file structure, where is the .lua file located.
Oh okay, I misunderstood ^^" The file is located at "garrysmod\addons\CTGTools\lua\weapons\vgui_swep.lua"
"CTGTools", your addon folders should not be capitalised or contain spaces. Change it to "ctgtools".
Same thing in lowercase. The swep appears well in the menu, and when I have it in my hand and I left-click, nothing happens.
Write down all your file paths of ctgtools folder
Is that a single file in folder? Next time: 99% you will be asked for relative path (not from D:/...Steam...etc) because everyone understand that it's in your GMod folder
Okay, I'll write for next time: p And yes, it's the only file in the folder.
So, I've recreated your folder on my machine. What's the problem you're having now?
So, the problem is that the category is created, the swep is there, I can give it to myself, I see it in hand with the model I chose, but when I left click to call the Primary Attack, nothing happens, really nothing, no error message that appears in the console when clicking.  As if the Primary Attack does not run.
I used this code and it works
Well, well, I guess I have a curse.
Try use again this code and restart server
Ok I know why the script wasn't working, it's because i was in singleplayer game and not in multiplayer game. What a noob ! It works now, thx !
Sorry, you need to Log In to post a reply to this thread.