• UtilX -- Extending GLua -- Need community input
    371 replies, posted
[QUOTE=TomyLobo;17564113]That's the same the difference between our functions is: mine finds, yours checks if an ent is in that cone. (if I didn't misread that) mine was more a reply to Levybreak's unoptimised FindInCone function.[/QUOTE] Mine does have the convenience of only needing the 2 positions and the base radius, whereas yours requires the length to be separated outside of the function and an argument of the angle instead of the radius.
I don't think that's more convenient FindInCone isn't exactly used for cones standing around somewhere. I think it's more likely used for the aforementioned "find everything in view" task position = shootpos direction = aimvector length = whatever range you want angle = math.rad(75) or something. my function searches in a spherical cone btw, not a cone. it's easier to calculate and just as useful. and I think this is what ents.FindInCone originally looked like. then garry wanted to make it a true cone and messed up by reversing the condition. now it's just the spherical cap, i.e. spherical cone minus the cone
Wouldnt it be usefull? [LUA]function file.GetRecursiveFiles(dir,filter) local tbl = {} local files = file.Find(dir.."*") local folders = file.FindDir(dir.."/*") local function DoFilter(filename) if !filter then return true end for k,v in pairs(filter) do local len = string.len(v) local extension = string.Right(filename,len) if v == extension then return true end end return false end local function IsFolder(v) if !folders then return false end if table.HasValue(folders,v) then return true end return false end if files then for k,v in pairs(files) do local str = string.lower(string.Right(v,5)) if str != ".ztmp" and !IsFolder(v) and DoFilter(v) then local path = string.Replace(dir,"../","")..v table.insert(tbl,path) end end end if folders then for k,folddir in pairs(folders) do local filetbl = file.GetRecursiveFiles(dir..folddir.."/",filter) for _,found in pairs(filetbl) do table.insert(tbl,found) end end end return tbl end [/LUA]
[lua] function math.wrap(number,mins,maxs) if number > maxs or number < mins then if number > maxs then return math.wrap(mins+(number-maxs),mins,maxs) elseif number < mins then return math.wrap(maxs+(number-mins),mins,maxs) end else return number end end [/lua] I *think* that's right.
That's pretty damn complex, Levy... I think all you need is this: [lua] function math.wrap(n, ...) return math.max(math.min(n, math.max(...)), math.min(...)) end [/lua]
Isn't that just math.Clamp? Levy's actually wraps the number, ie math.wrap(6,2,5) = 3
[QUOTE=cyber_cam34;17650994]Isn't that just math.Clamp? Levy's actually wraps the number, ie math.wrap(6,2,5) = 3[/QUOTE] Works sort of the same as math.Clamp, but uses all the arguments and doesn't require them to be ordered. I misread his function :P Tis awesome :D
[lua]function math.wrap(number, mins, maxs) return mins+(number-mins)%(maxs-mins) end[/lua] should do the same. if number >= maxs or number < min then wrap
What does it do?
the same :D math.wrap(6,2,5) == 3, like cyber_cam34 said y=math.wrap(x,2,5): x: 0 1 2 3 4 5 6 7 8 9 y: 3 4 2 3 4 2 3 4 2 3
[b]utilx.Decode64 ( base64 string )[/b] - takes a base 64 string and changes it into ASCII. [lua] local function utilx.Decode64( base64 ) local b='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/' data = string.gsub(data, '[^'..b..'=]', '') return (data:gsub('.', function(x) if (x == '=') then return '00' end local r,f='',(b:find(x)-1) for i=6,1,-1 do r=r..(f%2^i-f%2^(i-1)>0 and '1' or '0') end return r; end):gsub('%d%d%d?%d?%d?%d?%d?%d?', function(x) if (#x ~= 8) then return '' end local c=0 for i=1,8 do c=c+(x:sub(i,i)=='1' and 2^(8-i) or 0) end return string.char(c) end)) end [/lua]
how about encoding?
I made a conversion from HSL to RGB. I got the information for converting from [url=http://130.113.54.154/~monger/hsl-rgb.html]this[/url] website. [lua]function HSL(h, s, l, a) local H = h/360 local S = s/100 local L = l/100 local R = 0 local G = 0 local B = 0 a = a or 255 if S == 0 then R = L G = L B = L else local temp1 = 0 local temp2 = 0 local temp3r = 0 local temp3g = 0 local temp3b = 0 if L < 0.5 then temp2 = L*(1+S) else temp2 = L+S-L*S end temp1 = 2*L-temp2 temp3r = H+1/3 temp3g = H temp3b = H-1/3 if temp3r < 0 then temp3r = temp3r+1 elseif temp3r > 1 then temp3r = temp3r-1 end if temp3g < 0 then temp3g = temp3g+1 elseif temp3g > 1 then temp3g = temp3g-1 end if temp3b < 0 then temp3b = temp3b+1 elseif temp3b > 1 then temp3b = temp3b-1 end if 6*temp3r < 1 then R = temp1+(temp2-temp1)*6*temp3r elseif 2*temp3r < 1 then R = temp2 elseif 3*temp3r < 2 then R = temp1+(temp2-temp1)*((2/3)-temp3r)*6 else R = temp1 end if 6*temp3g < 1 then G = temp1+(temp2-temp1)*6*temp3g elseif 2*temp3g < 1 then G = temp2 elseif 3*temp3g < 2 then G = temp1+(temp2-temp1)*((2/3)-temp3g)*6 else G = temp1 end if 6*temp3b < 1 then B = temp1+(temp2-temp1)*6*temp3b elseif 2*temp3b < 1 then B = temp2 elseif 3*temp3b < 2 then B = temp1+(temp2-temp1)*((2/3)-temp3b)*6 else B = temp1 end end return {r = R*255, g = G*255, b = B*255, a = a} end[/lua]
[QUOTE=CowThing;17701402]-[/QUOTE] You need an 'a' field in your colours
Oh yeah, forgot about alpha. I added it. Thanks.
[QUOTE=CowThing;17705558]Oh yeah, forgot about alpha. I added it. Thanks.[/QUOTE] np. What's the point of a colour object in HSL anyway? The only thing it would work with would be the HLSToRGB converter. Why not have the HSL() function accept h,s,l,a then return an r,g,b,a colour object? :>
Yeah that might work better. :P I changed it to just HSL() that returns RGBA.
Remember that tonumber returns nil when it can't make a number. You probably don't need it in the return statement.
Alright, thanks again.
[QUOTE=CowThing;17701402]I made a conversion from HSL to RGB. I got the information for converting from [url=http://130.113.54.154/~monger/hsl-rgb.html]this[/url] website. [lua]code[/lua][/QUOTE] [url=http://wiki.garrysmod.com/?title=G.HSVToColor]Too late :v:[/url]
Oh, never knew about that. Either way, HSL and HSV are 2 different color spaces. Here's an example of red in all 3 types: RGB = 255, 0, 0 HSL = 0, 100, 50 HSV = 0, 100, 100
Shall I port [url=http://82.171.96.250/evaluator/]this[/url] to Lua for utilx? It parses expressions like this and gives the result or a detailed error message: [code](3+6) * 5^( 15 % 2 )[/code]
You mean something like this? [url]http://luabin.foszor.com/1337[/url] I found that the other day.
Yes, but it follows operator order and supports parentheses.
That'd be cool.
I really can't think of a good use for that beside a calculator, though. It's neat, but doesn't have any apparent uses.
[QUOTE=Kogitsune;17727268]I really can't think of a good use for that beside a calculator, though. It's neat, but doesn't have any apparent uses.[/QUOTE] Like a lot of stuff in this thread?
[QUOTE=Lexic;17727290]Like a lot of stuff in this thread?[/QUOTE] I'd love it. It's be useful for a !math chat command or something.
[QUOTE=Levybreak;17727332]I'd love it. It's be useful for a !math chat command or something.[/QUOTE] [img]http://img25.imageshack.us/img25/4521/geniusz.gif[/img]
[QUOTE=Levybreak;17727332]I'd love it. It's be useful for a !math chat command or something.[/QUOTE] I remember giving a math command a try but I failed because of my poor knowledge in math. A function for it would be awesome, though.
Sorry, you need to Log In to post a reply to this thread.