[QUOTE=CptFuzzies;16976076]Deprecated download.
The only reason for downloading the framework (if finished) would be because another addon which required it would be broken (or half available) without it.
Useless.
The GMod Plus project was designed for both ends, player and programmer; to be a majorly popular addon upon release, which would then be motivation for programmers to use the internal frameworks included.
Or is it just me who notices the loads of wiremod, and phx downloads on garrysmod.org?[/QUOTE]
I looked directly in the SVN link you posted, not an out of date download.
GM+ has the same problems that this would have - fixing the problems involves integrating them with the game itself so everybody has them.
If we want to get personal on things being useless or unreliable ( subjective ), I can point out some things in the code but that can be done in private messages.
If you don't intend to contribute, please don't post in the thread.
Should be right. I'm using this to convert item names that have amounts. 115 is s and 121 is y btw.
[lua]function util.AOrAn(name)
local sub1 = string.byte(string.sub(string.lower(name), 1, 1))
if sub1 == 97 or sub1 == 101 or sub1 == 105 or sub1 == 111 or sub1 == 117 then
return "an "..name
else
return "a "..name
end
end
function util.NameByAmount(name, amount)
if amount == 1 then
return util.AOrAn(name)
end
local endchar = string.byte(string.lower(string.sub(name, -1)))
if endchar == 115 then
return amount.." "..name.."es"
elseif endchar == 121 then
return amount.." "..string.sub(name, 1, -2).."ies"
else
return amount.." "..name.."s"
end
end[/lua]
[QUOTE=JetBoom;17056478]-stuff-[/QUOTE]
Is the string.byte really necessary?
Could you just have use 's' and 'y'?
yeah it is.
Here's a number suffix function that does any number above 0:
[lua]
function util.NumberSuffix(n)
local last_char = string.sub(tostring(n), -1)
if string.sub(tostring(n), -2, -2) == "1" then
return "th"
elseif last_char == "1" then
return "st"
elseif last_char == "2" then
return "nd"
elseif last_char == "3" then
return "rd"
else
return "th"
end
end
[/lua]
Here's an A or An function that'll do it properly:
[lua]
function util.AOrAn(s)
return string.match(s, "^h?[AaEeIiOoUu]") and "an" or "a"
end
[/lua]
[QUOTE=Deco Da Man;17062848]Here's an A or An function that'll do it properly:
[lua]
function util.AOrAn(s)
s = string.lower(s)
local first_char = string.sub(tostring(s), 1, 1)
return (
first_char == 'h' and string.match(s, "^.[aeiou]")
or string.match(first_char, "[aeiou]"))
) and "an" or "a"
end
[/lua][/QUOTE]
Let's uhh make our code cryptic... and use some kind of horrible abstract syntax!
[editline]10:41AM[/editline]
Human readable and prettier, atleast I think:
[lua]
Utilx.AOrAnVals = { ["a"] = "", ["e"] = "", ["i"] = "", ["o"] = "", ["u"] = "" }
function util.AOrAn(s)
local s = string.lower(string.sub(tostring(s), 1, 1))
if Utilx.AOrAnVals[s] then return "an" else return "a" end
end
[/lua]
[QUOTE=Jawalt;17063937]Let's uhh make our code cryptic... and use some kind of horrible abstract syntax!
[editline]10:41AM[/editline]
Human readable and prettier, atleast I think:
[lua]
Utilx.AOrAnVals = { ["a"] = "", ["e"] = "", ["i"] = "", ["o"] = "", ["u"] = "" }
function util.AOrAn(s)
local s = string.lower(string.sub(tostring(s), 1, 1))
if Utilx.AOrAnVals[s] then return "an" else return "a" end
end
[/lua][/QUOTE]
What the hell is cryptic about it? Your code is less efficient.
[QUOTE=Jawalt;17063937]-shit-[/QUOTE]
I like the way I code. I can read it, I can understand it and it's usually more efficient than the next person's load of shite. (meaning you)
If you bothered doing some research you'd find that mine takes into account the occurrence of a silent H.
Although checking if a vowel is after the H is not a totally reliable method, it gives the correct result the majority of times.
Example of failure: "I had an hot waterbottle!"
Example of success: "You are an honourable man!"
[QUOTE=Deco Da Man;17064187]I like the way I code. I can read it, I can understand it and it's usually more efficient than the next person's load of shite. (meaning you)
If you bothered doing some research you'd find that mine takes into account the occurrence of a silent H.
Although checking if a vowel is after the H is not a totally reliable method, it gives the correct result the majority of times.
Example of failure: "I had an hot waterbottle!"
Example of success: "You are an honourable man!"[/QUOTE]
You're contributing to something. The code should be orthodox, and readable without the reader having a CPU or intensive knowledge of the inner-workings of Lua's syntax. It's worth sacrificing 1/100th of a frametime so that it's pretty. It's not like you should ever call that function on a think hook anyway.
[editline]11:37AM[/editline]
And honestly on today's CPU's I could loop that code 100 times and then return the 'an' or 'a' and it -wouldn't even matter-. I'm referencing a table and checking if it exists. That's not even close to resource intensive.
[QUOTE=Deco Da Man;17064187]I like the way I code. I can read it, I can understand it and it's usually more efficient than the next person's load of shite. (meaning you)
If you bothered doing some research you'd find that mine takes into account the occurrence of a silent H.
Although checking if a vowel is after the H is not a totally reliable method, it gives the correct result the majority of times.
Example of failure: "I had an hot waterbottle!"
Example of success: "You are an honourable man!"[/QUOTE]
If you already know when an exception happens, throw in a table to check for exceptions, to reduce the rate of failure even more.
[QUOTE=Jawalt;17064487]readable without the reader having a CPU or intensive knowledge of the inner-workings of Lua's syntax.[/QUOTE]
If the reader cannot understand Lua's basic syntax, they really shouldn't be coding Lua.
[QUOTE=Jawalt;17064487]It's not like you should ever call that function on a think hook anyway.[/QUOTE]The only time I can think that I would use a function like that would be in a hudpaint hook and probably quite a few times.
[lua]
utilx.AOrAnVals = { ["a"] = "", ["e"] = "", ["i"] = "", ["o"] = "", ["u"] = "" }
utilx.AOrAnValsH = { ["o"] = "", ["u"] = "" }
utilx.HBlackList = { ["t"] = "", ["g"] = "", ["d"] = ""} -- Not sure what else to put here.
function util.AOrAn(s)
local s = string.lower(string.sub(tostring(s), 1, 1))
local s2 = string.lower(string.sub(tostring(s), 2, 2))
local s3 = string.lower(string.sub(tostring(s), 3, 3))
if s == "h" and utilx.AOrAnVals[s2] and !utix.HBlackList[s3] then return "an" end
if utilx.AOrAnVals[s] then return "an" else return "a" end
end
[/lua]
[editline]11:57AM[/editline]
[QUOTE=Lexic;17064719]If the reader cannot understand Lua's basic syntax, they really shouldn't be coding Lua.
The only time I can think that I would use a function like that would be in a hudpaint hook and probably quite a few times.[/QUOTE]
You should NEVER call that function in a hudpaint hook. That's -horrible- coding. You should just call that function when the value changes not each frame.
[editline]12:00PM[/editline]
The only thing that piece of code wouldn't handle is a word like "hoot" which is still falsely given "an".
[QUOTE=Jawalt;17064487]You're contributing to something. The code should be orthodox, and readable without the reader having a CPU or intensive knowledge of the inner-workings of Lua's syntax. It's worth sacrificing 1/100th of a frametime so that it's pretty. It's not like you should ever call that function on a think hook anyway.
[editline]11:37AM[/editline]
And honestly on today's CPU's I could loop that code 100 times and then return the 'an' or 'a' and it -wouldn't even matter-. I'm referencing a table and checking if it exists. That's not even close to resource intensive.[/QUOTE]
I agree with you on your statements regarding efficiency, in this circumstance at least. I've seen much worse done in HUDPaint with little noticeable lag.
However, that thinking will usually lead to complication later on when applied to other projects (like a remake of the Source engine). [b]Plan ahead.[/b] Plan with efficiency in mind.
Everything I code is readable. The state of readability is one of preference, much as beauty is in the eye of the beholder. A native speaker of Japanese may say English is nigh but disgusting chicken scratchings.
As for 'orthodox'. If you were to read the [url=http://www.lua.org/manual/5.1/manual.html#2.5.3]appropriate documentation[/url], you would see that the methods I use are entirely orthodox. I agree with Lexic.
If you think my coding is shit, go try [url=http://en.wikipedia.org/wiki/Perl]Perl[/url]. You'll love it ;)
[b]Edit:[/b] God damn 12:00AM disconnect.
[QUOTE=Deco Da Man;17059407]Here's a number suffix function that does any number above 0:
[lua]
function util.NumberSuffix(n)
local last_char = string.sub(tostring(n), -1)
if string.sub(tostring(n), -2, -2) == "1" then
return "th"
elseif last_char == "1" then
return "st"
elseif last_char == "2" then
return "nd"
elseif last_char == "3" then
return "rd"
else
return "th"
end
end
[/lua][/QUOTE]
I'm sorry, but that's already included in Gmod.
[url]http://wiki.garrysmod.com/?title=G.STNDRD[/url]
[QUOTE=Dlaor;17064909]I'm sorry, but that's already included in Gmod.
[url]http://wiki.garrysmod.com/?title=G.STNDRD[/url][/QUOTE]
[quote=http://wiki.garrysmod.com/?title=G.STNDRD]
Only works up to 20. Values such as 21, 22, 23 will incorrectly return "th".
[/quote]
[quote=me]
Here's a number suffix function that does any number above 0:
[/quote]
*sigh*
[b]Edit:[/b] [QUOTE=Jawalt;17064792]The only thing that piece of code wouldn't handle is a word like "hoot" which is still falsely given "an".[/QUOTE]
"Hoot" is onomatopoeia.
[QUOTE=Deco Da Man;17064960]*sigh*
[b]Edit:[/b]
"Hoot" is onomatopoeia.[/QUOTE]
It's an example. Anything with two 'o's or 'u's would return 'an' and not 'a' which would be correct.
[QUOTE=Jawalt;17064792][lua]
function util.AOrAn(s)
local s = string.lower(string.sub(tostring(s), 1, 1))
local s2 = string.lower(string.sub(tostring(s), 2, 2))
local s3 = string.lower(string.sub(tostring(s), 3, 3))
if s == "h" and utilx.AOrAnVals[s2] and !utix.HBlackList[s3] then return "an" end
if utilx.AOrAnVals[s] then return "an" else return "a" end
end
[/lua][/QUOTE]
[lua]function util.AOrAn(s)
s = tostring(s):lower()
local s1,s2,s3 = s:sub(1, 1),s:sub(2, 2),s:sub(3,3)
if s1 == "h" and utilx.AOrAnVals[s2] and !utix.HBlackList[s3] then return "an" end
if utilx.AOrAnVals[s1] then return "an" else return "a" end
end[/lua]
[QUOTE=Lexic;17065409][lua]function util.AOrAn(s)
s = tostring(s):lower()
local s1,s2,s3 = s:sub(1, 1),s:sub(2, 2),s:sub(3,3)
if s1 == "h" and utilx.AOrAnVals[s2] and !utix.HBlackList[s3] then return "an" end
if utilx.AOrAnVals[s1] then return "an" else return "a" end
end[/lua][/QUOTE]
That's the same thing except you lower the string all at the same time. and you define your variables differently.
You didn't change the method at all, and you made it all more cramped.
Yeah I'm never submitting anything again you can all lick my ass.
[QUOTE=Jawalt;17065822]That's the same thing except you lower the string all at the same time. and you define your variables differently.
You didn't change the method at all, and you made it all more cramped.[/QUOTE]
I know I didn't. I just took yours and made it less stupid.
[editline]11:42PM[/editline]
Though it is certainly more cramped than yours. My coding style doesn't waste space.
Especially deco da man, god that is terrible coding. Use two regular expressions and then whine about a string.byte.
[QUOTE=JetBoom;17072713]Especially deco da man, god that is terrible coding. Use two regular expressions and then whine about a string.byte.[/QUOTE]
I'm not sure, I wasn't bashing on your code, it's fine. I was just saying the whole syntax Deco Da Man uses is unorthodox. Whether documentation says so or not, what's used by the majority is orthodoxy, and that's not it.
[editline]07:20PM[/editline]
[QUOTE=Lexic;17072631]I know I didn't. I just took yours and made it less stupid.
[editline]11:42PM[/editline]
Though it is certainly more cramped than yours. My coding style doesn't waste space.[/QUOTE]
Whitespace doesn't matter, it's not hindering anyone's ability to read and understand the code.
is gbps still even checking in on this thread?
Yes :)
All you idiots have been arguing about efficiency and prettyness. The reason I reposted the code was [b][u]not[/b][/u] because I thought using string.byte was inefficient or that the code was ugly. I merely wished to contribute a fixed version that would consider the occurence of a silent H.
On behalf of everyone, I thank you JetBoom for your contribution. I'm sure a function serving the same purpose would not have arrisen if not for you. [b](Edit:[/b] And 50 thousand other noobs would be hard coding a collection of else-ifs on what words need 'an'[b])[/b]
I apologise if I appeared hostile. My first question was one of curisoity and my remake of your function was only intended to improve upon the functionality.
Jawalt, will you grow the fuck up and learn that, pretty or not, the code I write is just as good as anyone elses'.
Style is personal preference. Coding style arguements have been around as long as coding has.
Thank you Gbps for starting this awesome project :)
-snip-
[QUOTE=iRzilla;17081134]Snip without edit?
Hmr?[/QUOTE]
If you edit within a minute of posting it doesn't show up as an edit.
[QUOTE=Deco Da Man;17080523]
Jawalt, will you grow the fuck up and learn that, pretty or not, the code I write is just as good as anyone elses'.
Style is personal preference. Coding style arguements have been around as long as coding has.
[/QUOTE]
So have arguments over ridiculously small efficiency crap. You're just as bad with that as I am with style. The efficiency of that code didn't matter in any proper application, you'd might as well make it pretty. I'm not saying your code isn't better than anyone elses it's just ugly.
[editline]02:07PM[/editline]
[lua]function meta:CanSee( ent )
toscr = ent:EyePos():ToScreen()
if toscr.visible then
local trace = { }
trace.start = self:EyePos( );
trace.endpos = ent:EyePos( );
trace.filter = player.GetAll()
local tr = util.TraceLine( trace );
if !tr.Hit then return true end
return false;
end
return false
end
[/lua]
Line of sight code, this will only do a trace only if the player is in the other players field of view. You'd probably want an OPAQUE mask on this.
[lua]
function util.ShuffleTable(t)
local n = #t
while n > 2 do
local k = math.random(n)
t[n], t[k] = t[k], t[n]
n = n - 1
end
return t
end
[/lua]
Shuffles a table. I used this in a lottery thing I made once.
Sorry, you need to Log In to post a reply to this thread.