• Problems That Don't Need Their Own Thread v2.0
    5,020 replies, posted
[QUOTE=bran92don;45535501]I am trying to do a hook.add on every vehicle that is spawned but the only hook I have seen pertaining to vehicles is: [url]http://wiki.garrysmod.com/page/SANDBOX/PlayerSpawnVehicle[/url] I think this will only effect cars that the player spawns. Does anyone know of a hook that gets called every-time something is created both server side and player side. This way i can just simply check if it is a vehicle or not and then do a hook.add on it.[/QUOTE] [url=http://wiki.garrysmod.com/page/GM/OnEntityCreated]OnEntityCreated[/url] is run on both realms every time an entity is created, so you'll need to check the class of the entity that's passed in the hook.
[QUOTE=frietje2008;45532959]what is faster? [lua]FindMetatable("something") or getmetatable("something") or _R = debug.getregistry() _R.Player[/lua][/QUOTE] These do different things. FindMetaTable(x) will look for debug.getregistry()[x] where x is a string and if it is a table, return it. getmetatable(x) will return the metatable of the variable x.
Why this: [code] self.TexID = Material( "gms_resicons/" .. res .. ".png" ) if ( self.TexID:GetName() == "___error" ) then self.TexID = Material( "gms_icons/gms_none.png" ) end[/code] Is faster than this: [code] //Outside of hooks PANEL.TexID = Material( "gms_icons/gms_none.png" ) //Inside a PANEL hook if ( file.Exists( "materials/gms_resicons/" .. res .. ".png", "GAME" ) ) then self.TexID = Material( "gms_resicons/" .. res .. ".png" ) end[/code] The latter code produces noticeable delay with a few panels ( the code is called once per panel, ~7 panels ), while the first one doesn't.
How do I use render.DrawBeam? Which cam functions? What are the arguments for Start3D I should use?
[QUOTE=Ott;45536096]How do I use render.DrawBeam? Which cam functions? What are the arguments for Start3D I should use?[/QUOTE] You need 3D rendering context. cam.Start3D( EyePos(), EyeAngles() ) in a "2D" hook ( not recommended ), or just use 3D rendering hook. [url]http://wiki.garrysmod.com/page/Render_Order[/url]
[QUOTE=Robotboy655;45536068]Why this: [code] self.TexID = Material( "gms_resicons/" .. res .. ".png" ) if ( self.TexID:GetName() == "___error" ) then self.TexID = Material( "gms_icons/gms_none.png" ) end[/code] Is faster than this: [code] //Outside of hooks PANEL.TexID = Material( "gms_icons/gms_none.png" ) //Inside a PANEL hook if ( file.Exists( "materials/gms_resicons/" .. res .. ".png", "GAME" ) ) then self.TexID = Material( "gms_resicons/" .. res .. ".png" ) end[/code] The latter code produces noticeable delay with a few panels ( the code is called once per panel, ~7 panels ), while the first one doesn't.[/QUOTE] file.Exists is super-slow when looking up the GAME path. (Maybe not super, but it's slow enough)
[QUOTE=Robotboy655;45536068]Why this: [code] self.TexID = Material( "gms_resicons/" .. res .. ".png" ) if ( self.TexID:GetName() == "___error" ) then self.TexID = Material( "gms_icons/gms_none.png" ) end[/code] Is faster than this: [code] //Outside of hooks PANEL.TexID = Material( "gms_icons/gms_none.png" ) //Inside a PANEL hook if ( file.Exists( "materials/gms_resicons/" .. res .. ".png", "GAME" ) ) then self.TexID = Material( "gms_resicons/" .. res .. ".png" ) end[/code] The latter code produces noticeable delay with a few panels ( the code is called once per panel, ~7 panels ), while the first one doesn't.[/QUOTE] Wasn't there something about file.Exists mentioned a [I]long[/I] time about about how it does some excessive searching when you look for a file? EDIT: Tittysprinkles, I didn't see Willox's post...
Is there a way to turn off the default crosshair on clients? crosshair seems to be a blocked command :/
[QUOTE=Blasteh;45537981]Is there a way to turn off the default crosshair on clients? crosshair seems to be a blocked command :/[/QUOTE] HUDShouldDraw hook
[QUOTE=Blasteh;45537981]Is there a way to turn off the default crosshair on clients? crosshair seems to be a blocked command :/[/QUOTE] [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/vgui/proper_hud_creation.lua.html[/url] Should contain a list of most, if not all, of the HUDShouldDraw names; plus a few extras to show how to use HUDShouldDraw in custom HUD creations. [editline]30th July 2014[/editline] [QUOTE=Ott;45536096]How do I use render.DrawBeam? Which cam functions? What are the arguments for Start3D I should use?[/QUOTE] Here's an example of how to draw cubes: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/render_lasers_rendering_cubes.lua.html[/url]
There are so many different prop hunt versions available, which one should I pick?
You already made a thread. Why post here too?
[QUOTE=Robotboy655;45536068]Why this: [code] self.TexID = Material( "gms_resicons/" .. res .. ".png" ) if ( self.TexID:GetName() == "___error" ) then self.TexID = Material( "gms_icons/gms_none.png" ) end[/code] Is faster than this: [code] //Outside of hooks PANEL.TexID = Material( "gms_icons/gms_none.png" ) //Inside a PANEL hook if ( file.Exists( "materials/gms_resicons/" .. res .. ".png", "GAME" ) ) then self.TexID = Material( "gms_resicons/" .. res .. ".png" ) end[/code] The latter code produces noticeable delay with a few panels ( the code is called once per panel, ~7 panels ), while the first one doesn't.[/QUOTE] wouldn't that be because the first one checks the texture from cached memory but the second one runs a file check through your entire gmod folder? edit: didn't scroll down before replying, got ninja'd :tinfoil:
Making a little HUD. I'm using surface.DrawTexturedRect and draw.RoundedBox. This is what I have so far, but how I get the RoundedBox to be behind the texture? [img]http://puu.sh/axgbc/8a8e42564a.jpg[/img] I'm trying to do this instead, albeit not on MS Paint and shitty [img]http://puu.sh/axghA/179ba30906.png[/img] [editline]30th July 2014[/editline] Uhh, I moved the texture further to the right more so you can't actually notice, but this feels a bit hacky :v: is there a proper way to do this?
Draw the background texture first, then draw the circle and the icon textures.
That was embarrassingly simple, thank u
Multi-level tables/arrays, or whatever, are they slow to access? [lua] oftenCalledFunction( GM.Config.Items.maxItemCarry ) -- or is this faster? local cacheVar = GM.Config.Items.maxItemCarry oftenCalledFunction( cacheVar ) [/lua]
How do I track damage and physics collisions to non-scripted entities? Specifically ragdolls.
Figure I'll ask here. It's not a problem, but there's no general "ask a question about anything Gmod" I've been looking for a HL2DM gamemode for GMod, so far the only decent DM I've come across was Quake 3, but, it's Quake 3. The reason is mostly due to the fact I wanna play DM with a few friends, but they prefer Gmod. And almost any server I go to that has some sort of DM, the Context and Spawn menus are available, when they should be well.. locked out.
How can I get the value from DListView, OnRowSelected and OnClickLine returns the panel. DDListView:GetSectedLine() was what I needed.
[QUOTE=Commander11;45546536]How can I get the value from DListView, OnRowSelected and OnClickLine returns the panel.[/QUOTE] I think: [lua] local linePanel = listView:AddLine( "Col1", "Col2" ); linePanel.Columns[ 1 ].Value == "Col1" linePanel.Columns[ 2 ].Value == "Col2" [/lua] Generally, I put a table in the line. [lua] local line = list:AddLine( "Col1", "Col2", "Col3" ) line.myData = { "Some data that I want" } [/lua] Then on OnRowSelected, I just look at that table.
[QUOTE=Drak_Thing;45546614]I think: local linePanel = listView:AddLine( "Col1", "Col2" ); linePanel.Columns[ 1 ].Value == "Col1" linePanel.Columns[ 2 ].Value == "Col2" Generally, I put a table in the line. local line = list:AddLine( "Col1", "Col2", "Col3" ) line.myData = { "Some data that I want" } [/quote] Thanks, I was going to index a table and relate it to the list index. I was looking to gather the selected panels index within the list instead of just returning the panel. Then on OnRowSelected, I just look at that table.
Heres the problem: When admins are on another team or dead they cant hear other players on the opposing team talk. So I tried this and it doesn't work (Coded it myself. Pretty bad :L ) I need it so admins can here the other team talk can anyone fix whats wrong? [CODE]GM:PlayerCanHearPlayersVoice ( admin, team ) local admin = LocalPlayer() local team = !Player.Team if admin:IsUserGroup("admin") then if team then return team end end end [/CODE] Im pretty sure its more or less this [CODE]GM:PlayerCanHearPlayersVoice ( admin, team ) local admin = LocalPlayer() local team = !Player.Team if admin:IsUserGroup("admin") then return team end end [/CODE]
[QUOTE=Skate;45547385]Heres the problem: When admins are on another team or dead they cant hear other players on the opposing team talk. So I tried this and it doesn't work (Coded it myself. Pretty bad :L ) I need it so admins can here the other team talk can anyone fix whats wrong? [CODE]GM:PlayerCanHearPlayersVoice ( admin, team ) local admin = LocalPlayer() local team = !Player.Team if admin:IsUserGroup("admin") then if team then return team end end end [/CODE][/QUOTE] No offense, that's pretty ugly code. [code] local adminGroups = { ["admin"] = true, ["superadmin"] = true } hook.Add("PlayerCanHearPlayersVoice", "AdminHearsAll", function( ply1, ply2 ) if adminGroups[ply1:GetUserGroup()] then return true end) [/code]
[QUOTE=AnonTakesOver;45547440]No offense, that's pretty ugly code. [code] local adminGroups = { ["admin"] = true, ["superadmin"] = true } hook.Add("PlayerCanHearPlayersVoice", "AdminHearsAll", function( ply1, ply2 ) if adminGroups[ply1:GetUserGroup()] then return true end) [/code][/QUOTE] Thanks! Not very efficient yet in glua :L
p much as good as it gets [url]http://wiki.garrysmod.com/page/VGUI/Elements[/url] might find a few ones more/less on the old wiki
[QUOTE=Ehmmett;45547843]Oh good.[/QUOTE] you can look through the [url=https://github.com/garrynewman/garrysmod/tree/master/garrysmod/lua/vgui]github[/url] if the wiki doesn't have the element you want
I'm having issues with my custom HUD. It lags for everyone else but me. I might as well paste the whole thing [code] surface.CreateFont( "BurgerFont", { font = "Roboto-Black", size = 50, weight = 500, blursize = 0, scanlines = 0, antialias = true, underline = false, italic = false, strikeout = false, symbol = false, rotary = false, shadow = false, additive = false, outline = false, } ) --This hides the default HL2 HUD: function HUDHide( myhud ) if SERVER then return end for k, v in pairs{"CHudHealth","CHudBattery","CHudAmmo","CHudSecondaryAmmo"} do if myhud == v then return false end end end hook.Add( "HUDShouldDraw", "HUDHide", HUDHide ) --This draws the new hud: local function BurgerBulletHUD() if SERVER then return end local ply = LocalPlayer() if ply:Alive() then HP = ply:Health() ARM = ply:Armor() ammo = ply:GetActiveWeapon():Clip1() if ply:GetActiveWeapon():IsScripted() then maxammo=ply:GetActiveWeapon():GetTable().Primary.ClipSize else maxammo=120 end extraammo = ply:GetAmmoCount(ply:GetActiveWeapon():GetPrimaryAmmoType()) secondaryammo = ply:GetAmmoCount(ply:GetActiveWeapon():GetSecondaryAmmoType()) wep = ply:GetActiveWeapon() end -- I added if statements to check the resolution. Since the best quality size for the cricle is 256, I made it scale using halves and quarters -- Same goes for the Armor Width and Height if ScrW() == 640 then Scale = 0.5 elseif ScrW() == 800 then Scale = 0.75 elseif ScrW() == 1024 then Scale = 1 elseif ScrW() == 1280 then Scale = 1 else Scale = 1 end Basefade = 255 BaseTrig = 2 ConVert = math.pi/180 Size = (ScrH()/8)*Scale BarWidth=25*Scale BarHeight=25*Scale CenterX = ScrW()*0 + BarWidth*7 CenterX2 = ScrW() - BarWidth*7 CenterY = ScrH() - BarHeight*7 --surface.DrawCircle(ScrW()/2 + BarWidth/2 - 10,ScrH()/2 - BarHeight - 10,ScrW()*0.39,Color(255,255,255,255)) surface.SetFont( "BurgerFont" ) surface.SetTextColor( 255 - 2.25*HP,2.25*HP,(HP-100)*3,Basefade ) surface.SetTextPos( CenterX-(1/3)*100, CenterY-25) surface.DrawText( HP ) if ARM >= 1 then surface.SetFont( "BurgerFont" ) surface.SetTextColor( ARM-100,100,ARM*2.55,Basefade ) surface.SetTextPos( CenterX-(1/3)*100, CenterY+25) surface.DrawText( ARM ) end if extraammo >= 1 then surface.SetFont( "BurgerFont" ) surface.SetTextColor( 255, 255, 0, 255 ) surface.SetTextPos( CenterX2-25 , CenterY-25) surface.DrawText( extraammo ) end for i = 1, math.min(HP,100) do healthmod = 0.3 if ARM==0 then PosSet= 0 ; SizeMul=1 ; fixer= 0 else PosSet= 0 ; SizeMul=1; fixer = 0 end local RingX = math.sin(-(PosSet+i+fixer)*BaseTrig*ConVert*healthmod*2)*Size + CenterX - BarWidth/2 local RingY = math.cos(-(PosSet+i+fixer)*BaseTrig*ConVert*healthmod*2)*Size + CenterY surface.SetMaterial( Material("BurgerHUD/WhiteSquare.png") ) surface.SetDrawColor(255 - 2.25*HP,2.25*HP,(HP-100)*3,Basefade) surface.DrawTexturedRectRotated(RingX,RingY,BarWidth,(BarHeight+(i*SizeMul))*(Size/500), -(fixer+i+PosSet)*1.2) end if ARM >=1 then for i = 1, math.min(ARM,100) do healthmod = 0.3 local RingX = math.sin(i*BaseTrig*ConVert*healthmod*2)*Size + CenterX + BarWidth/2 local RingY = math.cos(i*BaseTrig*ConVert*healthmod*2)*Size + CenterY surface.SetMaterial( Material("BurgerHUD/WhiteSquare.png") ) surface.SetDrawColor((ARM-100),100,ARM*2.55,Basefade) surface.DrawTexturedRectRotated(RingX,RingY,BarWidth,(BarHeight+(i*SizeMul))*(Size/500),i*1.2) end end if ammo >= 1 then for i = 1, ammo do clipmod = 180/maxammo local RingX = math.sin(-i*BaseTrig*ConVert*clipmod)*Size + CenterX2 local RingY = math.cos(-i*BaseTrig*ConVert*clipmod)*Size + CenterY surface.SetMaterial( Material("BurgerHUD/WhiteCircle.png") ) surface.SetDrawColor(255,255,0,Basefade) surface.DrawTexturedRectRotated(RingX,RingY,BarWidth*math.Clamp(clipmod/2,1,10)/4,BarHeight*math.Clamp(clipmod/2,1,10)/4,0) --surface.DrawTexturedRectRotated(RingX,RingY,BarWidth,BarHeight,i*1.2) end end end hook.Add("HUDPaint", "BB_HUDPAINT", BurgerBulletHUD) [/code] I'm having issues with most clientside HUD things. They're basically made the same way. Finding out what's wrong will probably tell me whats wrong with everything else I made that is clientside.
[QUOTE=ROFLBURGER;45548563][code] surface.SetMaterial( Material("BurgerHUD/WhiteSquare.png") ) surface.SetMaterial( Material("BurgerHUD/WhiteSquare.png") ) surface.SetMaterial( Material("BurgerHUD/WhiteCircle.png") ) [/code] [/QUOTE] Material and surface.GetTextureID should only be called once and stored, outside of any drawing functions
Trying to accurately get FPS, I've tried mutliple numbers, the closest I've gotten was 1.25, can anyone help? Code: [CODE] timer.Create("fpstxt",0.1,0,function() fps:SetText(math.Round(1.2/FrameTime())) if math.Round(1.2/FrameTime()) < 30 then fps:SetColor(Color(255,0,0)) else fps:SetColor(Color(0,255,0)) end end) [/CODE]
Sorry, you need to Log In to post a reply to this thread.