• Problems That Don't Need Their Own Thread v5
    4,111 replies, posted
[QUOTE=SkitZz;51996750]Separating something from a table and printing it out?. In this example, i only want to print out the value of "code" in the table, but i cannot seem to figure out how to. Thanks in advance. [code] generated = { code = string.random(5), prizeFunction = args[1], amount = args[2], usesLeft = tonumber(args[3]) } [/code][/QUOTE] [code] print(generated.code) -- Or print(generated["code"]) [/code] Only difference is the second allows you to have expressions between the brackets where as the first is literal.
[QUOTE=NeatNit;51996210]What position are you trying to get? I know you've solved it but I really want to understand this. Here are the possible things you might be trying to get, and how I think they should be found: 1. The direction that a certain point on the screen is pointing at. This is gui.ScreenToVector and you said you didn't want that. 2. The point the user sees on the specified pixel. This can be acquired with a traceline starting from the camera position and ending an arbitrary, large distance away in the direction of the vector. startpos = EyePos(), endpos = EyePos() + (gui.ScreenToVector(x, y) * 100000). HitPos of the trace result is the position. 3. A position in front of the screen a predefined distance away. This is just EyePos() + (gui.ScreenToVector(x, y) * 100) for a distance of 100 units with a spherical result, or something slightly more complicated involving vector math for a flat result. If you really need #3 with a flat result, you still just need EyePos and gui.ScreenToVector, but just need to mess around with Vector:Dot (I think) between the EyeVector and ScreenToVector. My vector knowledge is rusty but it's definitely doable. I guess I'm just curious, which one was it? Or something not listed above?[/QUOTE] After sleeping on it, I realise that my request isn't inherently possible due to the player's view being a pyramid, so there are an infinite number of world vectors that could be represented at a screen point. My goal here is to draw a mesh to the player's screen, but the issue is that dynamic meshes can only be drawn with world coords, so I'm not sure if I should just choose an arbitrary distance away from the player's view in 3 space or I should angle it in some sort of perspective. Any suggestions?
[QUOTE=bigdogmat;51996762][code] print(generated.code) -- Or print(generated["code"]) [/code] Only difference is the second allows you to have expressions between the brackets where as the first is literal.[/QUOTE] Well, that was pretty simple, thanks a lot!
What's the default farz? [img]http://i.imgur.com/8qRHmPl.png[/img] [editline]23rd March 2017[/editline] [QUOTE=code_gs;51996765]After sleeping on it, I realise that my request isn't inherently possible due to the player's view being a pyramid, so there are an infinite number of world vectors that could be represented at a screen point. My goal here is to draw a mesh to the player's screen, but the issue is that dynamic meshes can only be drawn with world coords, so I'm not sure if I should just choose an arbitrary distance away from the player's view in 3 space or I should angle it in some sort of perspective. Any suggestions?[/QUOTE] It would help if I knew exactly what you want to draw. If you want to draw something to the player's screen it usually means it should be 2D. However, given no context, I would suggest using cam.Start3D(Vector(0,0,0), Angle(0,0,0)) and then drawing the mesh in a constant location right in front of the origin. This should make things easy, but I've never tried it before.
[QUOTE=code_gs;51996765]After sleeping on it, I realise that my request isn't inherently possible due to the player's view being a pyramid, so there are an infinite number of world vectors that could be represented at a screen point. My goal here is to draw a mesh to the player's screen, but the issue is that dynamic meshes can only be drawn with world coords, so I'm not sure if I should just choose an arbitrary distance away from the player's view in 3 space or I should angle it in some sort of perspective. Any suggestions?[/QUOTE] What exactly are you trying to draw? Depending on what exactly you need, you can use the mesh library in a 2D rendering context. Valve does it for the default damage indicators (the red bars). The X/Y values seem to change to screenspace. [code] local whiteAdditive = Material( "vgui/white_additive"); local verts = { { pos = Vector( ScrW() / 2, ScrH() / 2, 0 ), u = 0, v = 0, col = Color(20, 200, 20, 100) }, { pos = Vector( ScrW() / 2 + 100, ScrH() / 2 + 100, 0), u = 1, v = 0, col = Color(20, 20, 200, 255) }, { pos = Vector( ScrW() / 2 - 100, ScrH() / 2 + 100, 0 ), u = 1, v = 1, col = Color(200, 20, 20, 255) }, } hook.Add("HUDPaint", "test", function() render.SetMaterial(whiteAdditive); mesh.Begin( MATERIAL_TRIANGLES, 1 ) for i = 1, #verts do mesh.Color(verts[i].col.r, verts[i].col.g, verts[i].col.b, verts[i].col.a); mesh.Position( verts[i].pos ) mesh.TexCoord( 0, verts[i].u, verts[i].v ) mesh.AdvanceVertex() end mesh.End() end) [/code] Draws: [img]https://i.gyazo.com/ad56485475693521ee40d498117a1cca.png[/img]
[QUOTE=Brassx;51997613]What exactly are you trying to draw? Depending on what exactly you need, you can use the mesh library in a 2D rendering context. Valve does it for the default damage indicators (the red bars). The X/Y values seem to change to screenspace.[/QUOTE] I'm drawing a fade texture effect that moves into an stored RT overlay that's diced over itself to give it a sharp-looking effect. I tried using the dynamic mesh library in a 2D rendering hook, but it seems to always want to draw in 3D.
[QUOTE=code_gs;51997641]I'm drawing a fade texture effect that moves into an stored RT overlay that's diced over itself to give it a sharp-looking effect. I tried using the dynamic mesh library in a 2D rendering hook, but it seems to always want to draw in 3D.[/QUOTE] Hmm. That's pretty odd. You have the Z position set to 0? It seems that must be set to 0 for it to align with the screen the way you'd think. The Z position seems to be the 'forward' axis in screen coordinates. As you see in the example I left in the post above, it seems to render things just fine. It should work with the actual IMesh object too. Really hard to say without a snippet of code to help possibly debug.
[QUOTE=Brassx;51997716]Hmm. That's pretty odd. You have the Z position set to 0? It seems that must be set to 0 for it to align with the screen the way you'd think. The Z position seems to be the 'forward' axis in screen coordinates. As you see in the example I left in the post above, it seems to render things just fine. It should work with the actual IMesh object too. Really hard to say without a snippet of code to help possibly debug.[/QUOTE] [del]Well, it worked in HUDPaint but not PostDrawEffects even though they're both 2D rendering hooks. Nearly caused me to pull my hair out. Any idea why?[/del] Oh, the IgnoreZ flag isn't correctly being set on my material. [code] local PrevIgnoreZ = pMaterial:GetInt("$ignorez") pMaterial:SetInt("$ignorez", 1) print(type(pMaterial:GetInt("$ignorez"))) pMaterial:Recompute()[/code] Prints no value; is there a way to set ignorez on a material that doesn't have it defined?
[QUOTE=NeatNit;51997384]What's the default farz? [img]http://i.imgur.com/8qRHmPl.png[/img] .[/QUOTE] Of the entity, -1. As for the real value, [url]https://github.com/ValveSoftware/source-sdk-2013/blob/master/sp/src/game/client/view.cpp#L615[/url]
[QUOTE=code_gs;51997737][del]Well, it worked in HUDPaint but not PostDrawEffects even though they're both 2D rendering hooks. Nearly caused me to pull my hair out. Any idea why?[/del] Oh, the IgnoreZ flag isn't correctly being set on my material. [code] local PrevIgnoreZ = pMaterial:GetInt("$ignorez") pMaterial:SetInt("$ignorez", 1) print(type(pMaterial:GetInt("$ignorez"))) pMaterial:Recompute()[/code] Prints no value; is there a way to set ignorez on a material that doesn't have it defined?[/QUOTE] Why not re-create the material via LUA? I had the same problem with $selfillum. The only way I found to resolve was to do this method. [code] local pars = { ["$basetexture"] ="yourbasetexture", ["$ignorez"]=1, ["$vertexcolor"]=1, ["$vertexalpha"]=1 } local newmat = CreateMaterial("yourMaterial", "UnlitGeneric", pars); [/code] Just copy the VMT parameters as needed, and add what you wish.
[QUOTE=Brassx;51997926]Why not re-create the material via LUA? I had the same problem with $selfillum. The only way I found to resolve was to do this method. [code] local pars = { ["$basetexture"] ="yourbasetexture", ["$ignorez"]=1, ["$vertexcolor"]=1, ["$vertexalpha"]=1 } local newmat = CreateMaterial("yourMaterial", "UnlitGeneric", pars); [/code] Just copy the VMT parameters as needed, and add what you wish.[/QUOTE] That did it, thank you!
[QUOTE=Robotboy655;51997843]Of the entity, -1. As for the real value, [url]https://github.com/ValveSoftware/source-sdk-2013/blob/master/sp/src/game/client/view.cpp#L615[/url][/QUOTE] [del]This just extends the treasure hunt further. How can I get the map parameters in Lua like the line you linked to?[/del] oh, it's a convar. but is it available serverside? I guess I'll look around. Thanks. If anyone cares, the answer is as Robotboy pretty much linked to, 16384 * srqt(3) = about 28378
[QUOTE=code_gs;51998247]That did it, thank you![/QUOTE] Nice! On a side note, I thought maybe this little function would be useful to some people. (Prolly belongs more-so in the 'Useful code Snippets' thread) Little utility function I wrote to draw a 'dynamic' gradient; Allowing you to control the colors of all four corners. [code] local pars = { ["$ignorez"]=1, ["$vertexcolor"]=1, ["$vertexalpha"]=1 } local gradmat = CreateMaterial("gradientMat2", "UnlitGeneric", pars); // util.DrawGradient // Arguments: // x, y = top left position // w, h =width and height // col1 = topleft color, col2 = topright color, col3 = bottom left color, col4 = bottom right color // Written by Brassx STEAM_0:1:40846692 function util.DrawGradient(x, y, w, h, col1, col2, col3, col4) render.SetMaterial(gradmat); mesh.Begin( MATERIAL_QUADS, 1 ); mesh.Color(col1.r, col1.g, col1.b, col1.a); mesh.TexCoord( 0,0,0 ); mesh.Position( Vector(x, y, 0) ); mesh.AdvanceVertex(); mesh.Color(col2.r, col2.g, col2.b, col1.a); mesh.TexCoord( 0,1,0 ); mesh.Position( Vector(x + w, y, 0) ); mesh.AdvanceVertex(); mesh.Color(col4.r, col4.g, col4.b, col4.a); mesh.TexCoord( 0,1,1 ); mesh.Position( Vector(x + w, y + h, 0) ); mesh.AdvanceVertex(); mesh.Color(col3.r, col3.g, col3.b, col3.a); mesh.TexCoord( 0,0,1 ); mesh.Position( Vector(x, y + h, 0) ); mesh.AdvanceVertex(); mesh.End(); end [/code] Example: [code] hook.Add("HUDPaint", "testGradients", function() util.DrawGradient(100, 100, 256, 256, Color(200, 0, 0, 255), Color(0, 200, 0, 255), Color(0, 0, 200, 255), Color(200, 200, 0, 255)); end) [/code] [img]https://i.gyazo.com/2c3c533abbe2a50d1d33a989306a0c9a.png[/img]
Anyone know how to get the average delay of a burst fire weapon? I'm struggling with how I could calculate it. I can retrieve the delay in seconds between each volley in a burst fire. I can retrieve the delay in seconds between each individual bullet in a burst fire. I can retrieve the amount of bullets in each volley shot. [editline]3[/editline] SOLVED
Is there a way to make sure your addon loads after another one? So you can make a patch which replaces some files.
[QUOTE=MaxShadow;52005819]Is there a way to make sure your addon loads after another one? So you can make a patch which replaces some files.[/QUOTE] One way you can help to ensure your addon loads last is by running your [img]http://wiki.garrysmod.com/favicon.ico[/img][url=http://wiki.garrysmod.com/page/Global/include]include[/url] functions inside a [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/timer/Simple]timer.Simple[/url] or in the [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/Initialize]GM:Initialize[/url] hook. You'd have to make sure most of your addon isn't in autorun. Just have an initialize file in your autorun that has [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Global/AddCSLuaFile]AddCSLuaFile[/url] in it for your clientside/shared files. Then only use include with the methods above.
[QUOTE=Brassx;52005879]One way you can help to ensure your addon loads last is by running your [img]http://wiki.garrysmod.com/favicon.ico[/img][url=http://wiki.garrysmod.com/page/Global/include]include[/url] functions inside a [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/timer/Simple]timer.Simple[/url] or in the [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/Initialize]GM:Initialize[/url] hook. You'd have to make sure most of your addon isn't in autorun. Just have an initialize file in your autorun that has [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Global/AddCSLuaFile]AddCSLuaFile[/url] in it for your clientside/shared files. Then only use include with the methods above.[/QUOTE] I guess that would work if I want to use other scripts for my own addon, but what I'm trying to do is replace a file from a broken addon, to fix it without having to reupload it entirely. I suppose GMod overrides any lua file if it loads another file with the same path and name, so I wanted to know if there's a way to control which file is loaded first.
is it possible move ragdolls with code and how can i? Like i have a ragdoll entity and want it to move as if it was held by physgun
[QUOTE=Hobo_Gus;52007972]is it possible move ragdolls with code and how can i? Like i have a ragdoll entity and want it to move as if it was held by physgun[/QUOTE] [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/PhysObj/ComputeShadowControl]PhysObj:ComputeShadowControl[/url]
[QUOTE=MaxShadow;52007782]I guess that would work if I want to use other scripts for my own addon, but what I'm trying to do is replace a file from a broken addon, to fix it without having to reupload it entirely. I suppose GMod overrides any lua file if it loads another file with the same path and name, so I wanted to know if there's a way to control which file is loaded first.[/QUOTE] Why don't you just extract the addon with gmad.exe and then make the changes to the files then put it in your addons folder?
[QUOTE=Nick78111;52008408]Why don't you just extract the addon with gmad.exe and then make the changes to the files then put it in your addons folder?[/QUOTE] That's what I do, if I want to keep it for myself. But if I want to upload the patch to the workshop, I would need to reupload the entire mod. So there isn't a way to change the mod load order?
Is there an easier way to detect if an entity is visible to the player? ( I really am unfamiliar with EyeAngles and such ) Vector:ToScreen works quite well, but it doesn't ignore walls/obstructions.
[QUOTE=kpjVideo;52008873]Is there an easier way to detect if an entity is visible to the player? ( I really am unfamiliar with EyeAngles and such ) Vector:ToScreen works quite well, but it doesn't ignore walls/obstructions.[/QUOTE] Entity:Visible (Entity)
[QUOTE=code_gs;52008967]Entity:Visible (Entity)[/QUOTE] darn, is there a clientside alternative? It does state it's similar to a trace, but I'm not so sure of the values I could replicate with. Thanks regardless
[QUOTE=kpjVideo;52008990]darn, is there a clientside alternative? It does state it's similar to a trace, but I'm not so sure of the values I could replicate with. Thanks regardless[/QUOTE] [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/IsLineOfSightClear]Entity:IsLineOfSightClear[/url]
[QUOTE=MPan1;52008166][img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/PhysObj/ComputeShadowControl]PhysObj:ComputeShadowControl[/url][/QUOTE] thanks!
Ugh, why does util.Stack exist? [url]https://github.com/garrynewman/garrysmod/blob/master/garrysmod/lua/includes/extensions/util.lua#L301[/url] It's just a shitty implementation of what could already be achieved with a simple table.insert and table.remove. Pop doesn't return a value (?!), it uses a sub-table instead of the main table, it keeps track of the top element in a custom way instead of just tab[#tab] and calls it Top() instead of the more common Peek(). Just why? In other news, this section needs a chat thread
[QUOTE=NeatNit;52013547]In other news, this section needs a chat thread[/QUOTE] Just use the glua discord
[QUOTE=code_gs;52013685]Just use the glua discord[/QUOTE] Got a link? Only discord I have is the one for the gamemode competition late last year.
[QUOTE=NeatNit;52014207]Got a link? Only discord I have is the one for the gamemode competition late last year.[/QUOTE] [url]https://glua.team/[/url]
Sorry, you need to Log In to post a reply to this thread.