• Problems That Don't Need Their Own Thread v5
    4,111 replies, posted
[QUOTE=Mista_Epic;51829108]So I should use a combination of the two then? Use the Regex to see if the SteamID is correctly formatted, then convert it to a 64, and then fetchm if so[/quote] That would work [quote]Regex stuff[/quote] Lua doesn't have regex, it only has Lua patterns. Looking at the [URL="https://developer.valvesoftware.com/wiki/SteamID"]Valve wiki page for the SteamID[/URL], the first part is going to be 0 through 5, second part either 0 or 1, and third part being the account number. So a valid Lua pattern would be [code] "^STEAM_[0-5]:[0-1]:%d+$" [/code] If you really wanted to make sure they only entered a number up to 10 digits, you could use [code] "^STEAM_[0-5]:[0-1]:%d%d?%d?%d?%d?%d?%d?%d?%d?%d?$" [/code]
So using the Roblox lua wiki I discovered how to make a trace reflect from a surface like a beam using an equation. Problem is, I don't know how to get the angle of the beam relative to the shot position and the surface normal. On a 2D surface it's easy. I mean I actually forgot basic trigonometry but I don't think it would help me here anyway since this is a 3D space and I struggle with getting a 2D object out of a 3D space.
[QUOTE=ROFLBURGER;51835404]So using the Roblox lua wiki I discovered how to make a trace reflect from a surface like a beam using an equation. Problem is, I don't know how to get the angle of the beam relative to the shot position and the surface normal. On a 2D surface it's easy. I mean I actually forgot basic trigonometry but I don't think it would help me here anyway since this is a 3D space and I struggle with getting a 2D object out of a 3D space.[/QUOTE] Your question doesn't have enough information based upon what I see. Please, rephrase it. Whats your angle, direction, or relative angle to surface normal? etc.
[QUOTE=Jack Parsons;51835460]Your question doesn't have enough information based upon what I see. Please, rephrase it. Whats your angle, direction, or relative angle to surface normal? etc.[/QUOTE] I'm trying to find out what the equation is, not the answer to a specific question. [t]http://i.imgur.com/008mzRz.png[/t] [t]http://i.imgur.com/j4Lp6sH.png[/t] Think of it as trying to find the circumference of a circle. I'm not looking for the answer to a circumference of a circle, I'm trying to get the equation.
Using trig angle identities, we know that sin(theta) = opposite/hypotenuse, cos(theta) = adjacent/hypotenuse, and tan(theta) = opposite/adjacent. In this case, your theta is angle a where the opposite side is the x-difference between the eyepos and hitpos, and the adjacent is y-difference. Thus, your formula will look like this: [code]tan(a) = abs((xf - xo)/(yf - yo))[/code] If the arctangent is taken of both sides, the right side will yield your angle. In Lua, it will look like this: [code]local angle = math.atan(math.abs((tr.HitPos.x - vEye.x)/(tr.HitPos.y - vEye.y)))[/code] Note that the angle returned will be in radians. That was in reference to your second image. In the first, the fraction's x and y components would be flipped due to the perspective of the triangle. this will require you to check the z-distance between the eyes and hitpos to find the correct orientation.
use this ? [url]https://wiki.garrysmod.com/page/Structures/TraceResult[/url] HitNormal
[QUOTE=pierre0158;51835516]use this ? [url]https://wiki.garrysmod.com/page/Structures/TraceResult[/url] HitNormal[/QUOTE] That is just a normal vector going in the direction of the trace. Doesn't provide angular information.
Well if he want to calculate the A angle, he's going to need the hit angle, which he can get with the view angle and the hit angle.
[QUOTE=pierre0158;51835537]Well if he want to calculate the A angle, he's going to need the hit angle, which he can get with the view angle and the hit angle.[/QUOTE] It looks like from the images, the trace is always going in the direction of his eyes, in which case using the normal with a vector-angle calculation is a bit overkill. Also, that returns a euler angle while his pictures only depict a two-dimensional depth.
[QUOTE=code_gs;51835513]Using trig angle identities, we know that sin(theta) = opposite/hypotenuse, cos(theta) = adjacent/hypotenuse, and tan(theta) = opposite/adjacent. In this case, your theta is angle a where the opposite side is the x-difference between the eyepos and hitpos, and the adjacent is y-difference. Thus, your formula will look like this: [code]tan(a) = abs((xf - xo)/(yf - yo))[/code] If the arctangent is taken of both sides, the right side will yield your angle. In Lua, it will look like this: [code]local angle = math.atan(math.abs((tr.HitPos.x - vEye.x)/(tr.HitPos.y - vEye.y)))[/code] Note that the angle returned will be in radians. That was in reference to your second image. In the first, the fraction's x and y components would be flipped due to the perspective of the triangle. this will require you to check the z-distance between the eyes and hitpos to find the correct orientation.[/QUOTE] This helped me a lot. I tried your original formal, it didn't work probably because I entered the new values, but after a lot of testing I found something that worked. [lua] local DirectionTest = -2 * tr.Normal:Dot(tr.HitNormal) * tr.HitNormal + tr.Normal DirectionTest:Normalize() local LocalVec, LocalAng = WorldToLocal( Vector(0,0,0), tr.Normal:Angle(), Vector(0,0,0), DirectionTest:Angle() ) --DirectionTest is the direction where the bullet goes after bounce local Result = math.deg( math.acos(DirectionTest:Dot( tr.Normal ) )) print( Result / 2 )[/lua]
[del]You want to find the position Y, right? If so then all you really need is to use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/util/IntersectRayWithPlane]util.IntersectRayWithPlane[/url]. Your ray is the eye position with the eye direction, and your plane is your wall or the floor.[/del] Edit: Totally misunderstood the question, ignore this.
How can I make an entity do increasingly damage the closer a client moves towards the ent? I am trying to make a radioactive propent/
[QUOTE=MGFear;51836183]How can I make an entity do increasingly damage the closer a client moves towards the ent? I am trying to make a radioactive propent/[/QUOTE] Something like this: [lua]local maxDist = 2000 local damageMultiplier = 20 local dist = ply:GetPos():Distance(ent:GetPos()) if dist <= maxDist then local dmgRatio = maxDist/dist local dmg = dmgRatio * damageMultiplier ply:SetHealth(ply:Health() - dmg) end[/lua] Untested and could be more optimized by using DistToSqr but its good enough.
Anybody have an idea as to why Sandbox doesn't like referencing SWEP values? (such as self.Primary.ClipSize)
[QUOTE=Rocket;51836870]What do you mean?[/QUOTE] For instance, trying to grab a weapon's Primary.ClipSize will throw an error that: field 'primary' is a nil value when it's not.
[QUOTE=Aeternal;51836887]For instance, trying to grab a weapon's Primary.ClipSize will throw an error that: field 'primary' is a nil value when it's not.[/QUOTE] That also depends if the weapon base chooses to store clip size in SWEP.Prinary.ClipSize. ply:GetActiveWeapon().Primary.ClipSize should work fine afaik with TTT base weapons and I think Sandbox too.
[QUOTE=Rocket;51836892]Where are you using Primary.ClipSize?[/QUOTE] lua/autorun/client Displaying ammo if it's over a certain number as a gradient bar instead of individual number icons. I need the clips primary size to correctly calculate the size of the bar. [QUOTE]That also depends if the weapon base chooses to store clip size in SWEP.Prinary.ClipSize. ply:GetActiveWeapon().Primary.ClipSize should work fine afaik with TTT base weapons and I think Sandbox too.[/QUOTE] I'm very aware that it works with TTT and that it should work with Sandbox. However, Sandbox will always error out this line whereas TTT works just fine. I'm having a hard time understanding why since this is already defined in weapon_base.
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Weapon/GetMaxClip1]Weapon:GetMaxClip1[/url]?
[QUOTE=NeatNit;51836919][img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Weapon/GetMaxClip1]Weapon:GetMaxClip1[/url]?[/QUOTE] While that would work, it wouldn't give me the correct calculation for the ammo bar. I don't need the current ammo, I need the max amount of ammo that clip can hold.
[QUOTE=Aeternal;51836913]lua/autorun/client Displaying ammo if it's over a certain number as a gradient bar instead of individual number icons. I need the clips primary size to correctly calculate the size of the bar. I'm very aware that it works with TTT and that it should work with Sandbox. However, Sandbox will always error out this line whereas TTT works just fine. I'm having a hard time understanding why since this is already defined in weapon_base.[/QUOTE] Which weapons are you trying this with? Most of the HL2 weapons are made in C++ so they are a little wonky. Try PrintTable(myWep:GetTable()) and see what you have to mess with.
[QUOTE=YourStalker;51836929]Which weapons are you trying this with? Most of the HL2 weapons are made in C++ so they are a little wonky. Try PrintTable(myWep:GetTable()) and see what you have to mess with.[/QUOTE] I'm using the default HL2 weapons as of now. This method does work with other weapons AFAIK. Edit: I'll just use a workaround for now but I'd still like to know why that doesn't work.
[QUOTE=Aeternal;51836952]I'm using the default HL2 weapons as of now. This method does work with other weapons AFAIK. Edit: I'll just use a workaround for now but I'd still like to know why that doesn't work.[/QUOTE] The Primary table only exists on Lua weapons. Engine weapons are not SWEPs. That's why the GetMaxClip/GetDefaultClip/GetClip accessors exist -- they work across all weapon entities.
Where are SWEP holdtype animations dictated? I wanted to make some new ones and I have some new aim layers but I'm not sure how to to make the holdtype work properly
[QUOTE=solid_jake;51838016]Where are SWEP holdtype animations dictated? I wanted to make some new ones and I have some new aim layers but I'm not sure how to to make the holdtype work properly[/QUOTE] [url]https://github.com/garrynewman/garrysmod/blob/master/garrysmod/gamemodes/base/entities/weapons/weapon_base/sh_anim.lua[/url] [url]https://github.com/garrynewman/garrysmod/blob/master/garrysmod/gamemodes/base/entities/weapons/weapon_base/ai_translations.lua[/url]
I've finished creating an Alpha copy of a new gamemode, but I have a problem understanding custom files. I have a custom weapon script, model, texture, and sound files for the gamemode. Since these are in the gamemode\<mymode>\ folder, will they automatically be added and downloaded for connecting clients, or do I have to use [b]resource.AddFile[/b] for every single file?
Yes, however, AddFile has some shortcuts. If you add a .mdl file, it will automatically also add all related model components to that mdl. If you add a .vmt, it will automatically include its vtf.
[QUOTE=code_gs;51839599]Yes, however, AddFile has some shortcuts. If you add a .mdl file, it will automatically also add all related model components to that mdl. If you add a .vmt, it will automatically include its vtf.[/QUOTE] Okay. To make it easier, I'm just going to make it a separate workshop pack, and add "resource.AddWorkshop" to the gamemode\init.lua... I ran into another issue, where the content I added to the gamemode is not working at all, unless I add it as an addon pack. I'm falling asleep so I'm going to deal with this in the morning.
[QUOTE=Rory;51839620]Okay. To make it easier, I'm just going to make it a separate workshop pack, and add "resource.AddWorkshop" to the gamemode\init.lua... I ran into another issue, where the content I added to the gamemode is not working at all, unless I add it as an addon pack. I'm falling asleep so I'm going to deal with this in the morning.[/QUOTE] If you don't want to go through and make an addon pack, I wrote this script ages ago that may help; It will automatically include all 'needed' files listed in the directory you input. It doesn't include sub directories, but it has saved me a lot of time: [code] --Example Usage: --util.AddAllResources("models/mycustommodels/"); --util.AddAllResources("materials/models/mycustommodelsmats/"); --Arguments: --dir = directory --It is advised using something like- util.AddAllResources("models/") try and be more specific with your folders! function util.AddAllResources(dir) local e = {"*.vtf", "*.vmt", "*.mdl", "*.wav", "*.mp3", "*.png"}; for _ , ext in pairs(e) do local f = file.Find(dir .. ext, "GAME"); for k, nm in pairs(f) do resource.AddFile(dir .. nm); end end end [/code] It wouldn't be too hard to adapt it to include sub directories. Feel free to use it or modify it if you want!
-snip- fixed.
I'm kinda confused as to how variables work, I have a think hook to set the pos of a DynamicLight that I've attached to a vehicle but I obviously don't want to be getting the vehicle entity every tick in case the player gets out, so I have: [CODE] partybus_vehicle = LocalPlayer():GetVehicle() hook.Add("Think", "partybus_think", function() if partybus_on then partybus_dlight = DynamicLight(partybus_vehicle:EntIndex()) partybus_pos = partybus_vehicle:GetPos() partybus_dlight.pos = Vector(partybus_pos.x, partybus_pos.y, partybus_pos.z) print("set pos!") partybus_dlight.brightness = 200 partybus_dlight.decay = 100 partybus_dlight.size = 512 partybus_dlight.DieTime = CurTime() + 1 end if IsValid(partybus_audiochannel) then partybus_audiochannel:SetPos(partybus_vehicle:GetPos()) partybus_audiochannel:Set3DFadeDistance(1000, 5000) end end) [/CODE] but this results in an error saying partybus_vehicle is null, I thought it should be accessible within other functions because it's not local? Can anyone think of a better way to do this? All of this is in a net.Receive() called when the player gets in the party bus. [editline]18th February 2017[/editline] [QUOTE=Brassx;51839807]If you don't want to go through and make an addon pack, I wrote this script ages ago that may help; It will automatically include all 'needed' files listed in the directory you input. It doesn't include sub directories, but it has saved me a lot of time: [code] --Example Usage: --util.AddAllResources("models/mycustommodels/"); --util.AddAllResources("materials/models/mycustommodelsmats/"); --Arguments: --dir = directory --It is advised using something like- util.AddAllResources("models/") try and be more specific with your folders! function util.AddAllResources(dir) local e = {"*.vtf", "*.vmt", "*.mdl", "*.wav", "*.mp3", "*.png"}; for _ , ext in pairs(e) do local f = file.Find(dir .. ext, "GAME"); for k, nm in pairs(f) do resource.AddFile(dir .. nm); end end end [/code] It wouldn't be too hard to adapt it to include sub directories. Feel free to use it or modify it if you want![/QUOTE] I made a cool little bash script for FastDLing things too: [CODE] #!/bin/bash sudo rm -r /home/steam/server_main/fastdl/uncompressed/* sudo rm -r /home/steam/server_main/fastdl/compressed/* sudo rm -r /home/var-link/www/fastdl/* # Download directory (your URL) for d in /home/steam/server_main/fastdl_addons/*/ ; do for i in "${d}"{sound,materials,models,resource,fonts}; do rsync -a --delete "${i}" /home/steam/server_main/fastdl/uncompressed/; rsync -a --delete "${i}" /home/steam/server_main/fastdl/compressed/; done done find /home/steam/server_main/fastdl/compressed/. -type f -exec bzip2 {} + rm /home/steam/server_main/garrysmod/lua/autorun/server/resource.lua touch /home/steam/server_main/garrysmod/lua/autorun/server/resource.lua find /home/steam/server_main/fastdl/uncompressed/ -type f -printf 'resource.AddSingleFile("%P")\n' >> /home/steam/server_main/garrysmod/lua/autorun/server/resource.lua sudo rsync -a --delete /home/steam/server_main/fastdl/compressed/ /home/var-link/www/fastdl/ [/CODE]
Sorry, you need to Log In to post a reply to this thread.