• Problems That Don't Need Their Own Thread v5
    4,111 replies, posted
[QUOTE=Yashirmare;52364060]Ok, so if any of you are familiar with the SWEP Creation Kit this question is for you: I'm wanting to change the bone of an attached quad or at least be able to work out the weapon parent without having to manually do it for every weapon, is there any way to do this? I've managed to change the bone but nothing changes, I assume its something to do with the render order but I just can't work it out. Here is my code for it thus far: [t]https://i.gyazo.com/baa2268600eec4e4592b37a8ce53857a.png[/t] (Yes I am aware my tabbing is atrocious.)[/QUOTE] Unrelated but there's no point in doing this bit [lua]if children != nil then[/lua] inside the loop because if it were nil, the pairs function would return an error (Table expected, got nil)
[QUOTE=JasonMan34;52364429]Unrelated but there's no point in doing this bit [lua]if children != nil then[/lua] inside the loop because if it were nil, the pairs function would return an error (Table expected, got nil)[/QUOTE] That is a fair point, I do redundant stuff sometimes.
Which capitalization is preferred for naming variables? [CODE] local somevar = "Rate disagree" local someVar = "Rate dumb" local SomeVar = "Rate late" [/CODE]
[QUOTE=MPan1;52370094]Which capitalization is preferred for naming variables? [CODE] local somevar = "Rate disagree" local someVar = "Rate dumb" local SomeVar = "Rate late" [/CODE][/QUOTE] Not sure how relevant, but the [url=http://wiki.garrysmod.com/page/Help:Editing]wiki's style guide [/url] for examples recommends [img]https://facepunch.com/fp/ratings/box.png[/img]lowerCamelCase. Really though, use whatever the fuck you want.
[QUOTE=NeatNit;52370229]Not sure how relevant, but the [url=http://wiki.garrysmod.com/page/Help:Editing]wiki's style guide [/url] for examples recommends [img]https://facepunch.com/fp/ratings/box.png[/img]lowerCamelCase. Really though, use whatever the fuck you want.[/QUOTE] It says lowercase at the start, but nothing about camel case. I'll use that from now on, it looks better anyway
I'm weird and use all lowercase for function variables ( function NFP_Faggot(thisisafunctionvariable) ) and pascalcase for everything else. Might be because of the wiki.
[QUOTE=MPan1;52370267]It says lowercase at the start, but nothing about camel case. I'll use that from now on, it looks better anyway[/QUOTE] Ah, you're right.
[QUOTE=ROFLBURGER;52370319]I'm weird and use all lowercase for function variables ( function NFP_Faggot(thisisafunctionvariable) ) and pascalcase for everything else. Might be because of the wiki.[/QUOTE] Nothing is objectively weird. I use PascalCase for functions, tables, and global variables, camelCase for local variables and function variables, and snake_case for string identifiers. It doesn't really matter what you use, as long as you are consistent with it
I like to prefix the variable with what type it should be. [lua] local iMaxTries = 15 local strMaxTriesMet = "You've exceeded the maximum number of tries" local tblSettings = {}[/lua]
I know hl2 flashlight charce is disabled how it can be ennabled? (If theres way)
[QUOTE=MPan1;52370094]Which capitalization is preferred for naming variables?[/QUOTE] :hammered: [lua] local __string = "my ass is ready" [/lua]
[QUOTE=RasmusG5;52371063]I know hl2 flashlight charce is disabled how it can be ennabled? (If theres way)[/QUOTE] No way, you'll have to recreate it yourself
[QUOTE=thejjokerr;52370749]I reviewed some C# code yesterday where the programmer used some weird variation on hungarian notation. It made me sick in my mouth a bit. It was like this but in C#: [lua]function SomeFunction(a_firstArgument, a_secondArgument) local i_localVariable = "I cried"; LocalPlayer().p_someProperty = i_localVariable; end[/lua][/QUOTE] Oh, it gets worse. I once saw someone do that but with regular Hungarian notation too: [lua]function SomeFunction(a_intFirstArgument, a_boolSecondArgument) local l_strLocalVariable = "I cried"; LocalPlayer().m_strSomeProperty = l_strLocalVariable; end[/lua]
[QUOTE=Luni;52372961]Oh, it gets worse. I once saw someone do that but with regular Hungarian notation too: [lua]function SomeFunction(a_intFirstArgument, a_boolSecondArgument) local l_strLocalVariable = "I cried"; LocalPlayer().m_strSomeProperty = l_strLocalVariable; end[/lua][/QUOTE] I still do m_ for member variables. The l_ is a bit redundant since the majority of vars are local, though.
Anyone have any idea why my tables (self.BeamStorageTable) are inheriting values from other tables from the same entity? [lua]function ENT:DrawTrails() --Forward, Right, Up local BaseOffset01 = Vector(0,30,0) local BaseOffset02 = Vector(0,-50,0) local TrailLimit = 10 local DieTime = 1 local TrailWidth = 25 + self:GetEngineStress()*2 local TrailLength = 30 if self.NextTrail <= CurTime() then table.insert(self.BeamStorageTable,1,{vector = self:GetPos(),dietime = CurTime() + DieTime}) self.NextTrail = CurTime() + DieTime/TrailLimit end local StoredVectors = {} render.SetMaterial(GhostTrail) for num,data in pairs(self.BeamStorageTable) do v = data.vector t = data.dietime local PreviousVectors = StoredVectors[num - 1] local Distance = 10 --Forward, Right, Up local Vec01 = v + self:LocalToWorld( Vector(0,-TrailWidth,0) ) - self:GetPos() -- Left Forward local Vec02 = v + self:LocalToWorld( Vector(0,TrailWidth,0) ) - self:GetPos() -- Right Forward local Vec03 = v + self:LocalToWorld( Vector(-TrailLength,TrailWidth,0) ) - self:GetPos() -- Right Back local Vec04 = v + self:LocalToWorld( Vector(-TrailLength,-TrailWidth,0) ) - self:GetPos() -- Left Back if PreviousVectors then Vec01 = PreviousVectors[4] Vec02 = PreviousVectors[3] else Vec01 = self:LocalToWorld( Vector(0,-TrailWidth,0) ) Vec02 = self:LocalToWorld( Vector(0,TrailWidth,0) ) end StoredVectors[num] = {Vec01,Vec02,Vec03,Vec04} local WingOffsetLeft = self:GetRight()*-35 + self:GetUp()*20 + self:GetForward()*20 local WingOffsetRight = self:GetRight()*30 + self:GetUp()*20 + self:GetForward()*20 local ColorMod = Color(self.EffectsColor.r,self.EffectsColor.g,self.EffectsColor.b,self.EffectsColor.a * math.Clamp( (t - CurTime())/DieTime,0,255) ) if IsValid(self:GetNetDriver()) then --print(num,Vec01 - self:GetPos(),Vec02 - self:GetPos(),Vec03 - self:GetPos(),Vec04 - self:GetPos()) end render.DrawQuad(Vec01 + WingOffsetRight,Vec02 + WingOffsetRight,Vec03 + WingOffsetRight,Vec04 + WingOffsetRight,ColorMod) render.DrawQuad(Vec04 + WingOffsetRight,Vec03 + WingOffsetRight,Vec02 + WingOffsetRight,Vec01 + WingOffsetRight,ColorMod) render.DrawQuad(Vec01 + WingOffsetLeft,Vec02 + WingOffsetLeft,Vec03 + WingOffsetLeft,Vec04 + WingOffsetLeft,ColorMod) render.DrawQuad(Vec04 + WingOffsetLeft,Vec03 + WingOffsetLeft,Vec02 + WingOffsetLeft,Vec01 + WingOffsetLeft,ColorMod) if t <= CurTime() then table.remove(self.BeamStorageTable,num) end end end[/lua] It causes [URL="http://i.imgur.com/HIGyNdd.png"]this[/URL] sort of thing to happen and it's driving me nuts. [editline]53[/editline] Solved it by creating my own custom table insertion that returns the table once the value has been inserted. [lua]function ENT:CustomInsert(tabletomod,position,data) local ReturnTable = {} if #tabletomod == 0 then ReturnTable[position] = data else for k,v in pairs(tabletomod) do local LengthMod = #ReturnTable + 1 if LengthMod == position then ReturnTable[LengthMod] = data LengthMod = LengthMod + 1 end ReturnTable[LengthMod] = v end end return ReturnTable end[/lua]
Hey guys, do you know a way to get the gender of a player? I explain it better: I would like to emit a sound when a player get damaged, I done it but I would like to emit a male moan when the player have a male playermodel and a female moan when the player have a female playermodel. I know that it is possibile because there are many mods that does this. Thank you! (Excuse me for any grammatical errors)
Most citizen models have male_ or female_ at the start of them (I think), so you could use that: [CODE] if string.find( LocalPlayer():GetModel(), "female" ) then -- play female sound else -- most playermodels are male anyway -- play male sound end [/CODE]
Regex doesn't seem to work in string.find, any idea why? [t]http://i.imgur.com/riEQZWW.png[/t]
Lua doesn't have regex, [URL="https://wiki.garrysmod.com/page/Patterns"]it has patterns[/URL]. It's probably still possible to do that, but it's a bit more annoying
[QUOTE=polivlas;52373951]Regex doesn't seem to work in string.find, any idea why? [t]http://i.imgur.com/riEQZWW.png[/t][/QUOTE] Special characters There are a bunch of special characters that either escape other characters, or modify the pattern in some way. These characters are: ^ $ ( ) % . [ ] * + - ? They can also be used in the pattern as normal characters by prefixing them with a "%" character, so "%%" becomes "%", "%[" becomes "[", etc. string.find uses Patterns by default. Sources: [URL="http://wiki.garrysmod.com/page/Patterns"]http://wiki.garrysmod.com/page/Patterns[/URL] [URL="http://wiki.garrysmod.com/page/string/find"]http://wiki.garrysmod.com/page/string/find[/URL] [editline]18th June 2017[/editline] [QUOTE=MPan1;52373948]Most citizen models have male_ or female_ at the start of them (I think), so you could use that: [CODE] if string.find( LocalPlayer():GetModel(), "female" ) then -- play female sound else -- most playermodels are male anyway -- play male sound end [/CODE][/QUOTE] Thank you! I'll try this!
Is there a way we can implement regex to gLua? Patterns are so annoying sometimes.
[QUOTE=kantalketche;52373979]Is there a way we can implement regex to gLua? Patterns are so annoying sometimes.[/QUOTE] There's lots of modules and stuff you can find, but it takes such a ridiculous amount of code, it's not worth bothering to be honest. Here's some that I found, no clue if they work, but it just shows the huge amount of code needed: [url]http://luaforge.net/projects/lrexlib/[/url] [url]https://github.com/openresty/lua-nginx-module[/url]
Why does [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/surface/DrawTexturedRect]surface.DrawTexturedRect[/url] darken this .png so much? Material [t]https://i.imgur.com/NIuBgkL.png[/t] Output [t]https://image.prntscr.com/image/9EDyFNpmQ6SZ-5by4_rXiA.png[/t] [editline]fml[/editline] [QUOTE=MPan1;52374126]Did you set the draw color?[/QUOTE] I didn't realize it affects DrawTexturedRect. In hindsight it seems obvious but the wiki didn't say anything, thanks!
Post code. Did you set the draw color?
Hey, I'm trying to make it so the physgun [U]appears[/U] in the crotch area for a t-pose playermodel. Just like the minges from War Of The Servers. Any idea how I can rig it so it so it's there? Thanks!
I'm having a strange problem. I put some function in a file.lua in the client-side, the problem is that when I start these function, these gives me some lua errors, but, if I go inside the file and I simply edit something and save the file, it doesn't give me more errors. It seems like to be not initialized until I edit the file. Some ideas? (Excuse me for any grammatical errors)
[QUOTE=Predda;52374551]I'm having a strange problem. I put some function in a file.lua in the client-side, the problem is that when I start these function, these gives me some lua errors, but, if I go inside the file and I simply edit something and save the file, it doesn't give me more errors. Some ideas? (Excuse me for any grammatical errors)[/QUOTE] Could you post the file?
[QUOTE=AwfulRanger;52374557]Could you post the file?[/QUOTE] Sure, but isn't only one file, I try to explain what I'm trying to do. I created a meta function "IsSick()", it perfectly works in the server-side, I would like to make this function works also in the client-side, so I put this in a file named shared.lua in lua/autorun: [CODE] local meta = FindMetaTable( "Player" ) function meta:IsSick() return self:GetNWBool( "PlayerIsSick" ) end [/CODE] Client-Side: [CODE] AddCSLuaFile( "shared.lua" ) net.Receive( "isSick", function( len, pl ) alert() end) local ply = LocalPlayer() function alert() timer.Create("unique_name", 5, 0, function() if ply:IsSick() then print("You are sick") end end) end [/CODE] If I start the net message "isSick", in the console I can read: [ERROR] addons/sick/lua/autorun/client/alert.lua:8: attempt to call method 'IsSick' (a nil value) 1. unknown - addons/sick/lua/autorun/client/alert.lua:8
[QUOTE=Predda;52374571]Sure, but isn't only one file, I try to explain what I'm trying to do. I created a meta function "IsSick()", it perfectly works in the server-side, I would like to make this function works also in the client-side, so I put this in a file named shared.lua in lua/autorun: [CODE] local meta = FindMetaTable( "Player" ) function meta:IsSick() return self:GetNWBool( "PlayerIsSick" ) end [/CODE] Client-Side: [CODE] net.Receive( "isSick", function( len, pl ) alert() end) local ply = LocalPlayer() function alert() timer.Create("unique_name", 5, 0, function() if ply:IsSick() then print("You are sick") end end) end [/CODE] If I start the net message "isSick", in the console I can read: [ERROR] addons/sick/lua/autorun/client/alert.lua:8: attempt to call method 'IsSick' (a nil value) 1. unknown - addons/sick/lua/autorun/client/alert.lua:8[/QUOTE] The client side file is probably being loaded before the shared file is, meaning IsSick will be nil. If you want to make sure the shared file is loaded when the client file is ran, you could include it in the client file.
That's the problem, I did it. (I just have edited my reply) [editline]18th June 2017[/editline] [QUOTE=AwfulRanger;52374581]The client side file is probably being loaded before the shared file is, meaning IsSick will be nil. If you want to make sure the shared file is loaded when the client file is ran, you could include it in the client file.[/QUOTE] I fixed it putting a simple 10 seconds timer in the client-side file: [CODE] timer.Simple(10, function() AddCSLuaFile( "shared.lua" ) net.Receive( "isSick", function( len, pl ) alert() end) local ply = LocalPlayer() function alert() timer.Create("unique_name", 5, 0, function() if ply:IsSick() then print("You are sick") end end) end end) [/CODE] Thank you for your help!
Sorry, you need to Log In to post a reply to this thread.