• Problems That Don't Need Their Own Thread v2.0
    5,020 replies, posted
Maybe it a bit bigger and cut it ?
Hi, new to Glua, but I have a background in C. When opening a file for reading, is it being read as plaintext or as binary?
Open it and you'll find out. (It's plain text)
[QUOTE=Author.;47250455]Open it and you'll find out. (It's plain text)[/QUOTE] I'm not on a PC where I can do any glua right now. Is there a way to open things as binary?
What's the least cumbersome way to differentiate between false and nil?
[QUOTE=Neat-Nit;47250678]What's the least cumbersome way to differentiate between false and nil?[/QUOTE] Can't you just do if (var==nil) then elseif (var == false) then else end
[QUOTE=Neat-Nit;47250678]What's the least cumbersome way to differentiate between false and nil?[/QUOTE] You should avoid situations where you are having functions able to return both nil or false. Typically you should either return a valid object (ent, angle, vector, etc) or nil, or either true or false. But, checking if x == nil or x == false will give you what you need where the not operator isn't enough.
[QUOTE=GreyGeist;47250687]Can't you just do if (var==nil) then elseif (var == false) then else end[/QUOTE] Well, I'm planning on changing all my scattered CanTool hooked functions into just global functions and call them all, in me preferred order, in one place. Each one can return either false or no-value (= nil), unless I change them. I guess I could do a = SomeFunction() == false That way if it returns false, a would be true ( = should block), and if it returns nil, a would be false ( = nothing returned). But I'm interested to know what other people would do :)
[QUOTE=proboardslol;47250569]I'm not on a PC where I can do any glua right now. Is there a way to open things as binary?[/QUOTE] Yes - use "br" as the file mode in [url]http://wiki.garrysmod.com/page/file/Open[/url] then read data with [url]http://wiki.garrysmod.com/page/File/Read[/url].
[QUOTE=Neat-Nit;47250729]Well, I'm planning on changing all my scattered CanTool hooked functions into just global functions and call them all, in me preferred order, in one place. Each one can return either false or no-value (= nil), unless I change them. I guess I could do a = SomeFunction() == false That way if it returns false, a would be true ( = should block), and if it returns nil, a would be false ( = nothing returned). But I'm interested to know what other people would do :)[/QUOTE] [QUOTE=Revenge282;47250726]You should avoid situations where you are having functions able to return both nil or false. Typically you should either return a valid object (ent, angle, vector, etc) or nil, or either true or false. But, checking if x == nil or x == false will give you what you need where the not operator isn't enough.[/QUOTE] [del]If you are doing a hook to check if a player can use a tool, then your CanTool hook should return true if the player is allowed, and false if not. By nature of even using the word "can", you should only have a binary answer (true/false, yes/no). You should very rarely ever return nil in any hook.[/del] I was horribly, horribly wrong... :suicide:
[QUOTE=Revenge282;47250899]If you are doing a hook to check if a player can use a tool, then your CanTool hook should return true if the player is allowed, and false if not. By nature of even using the word "can", you should only have a binary answer (true/false, yes/no). You should very rarely ever return nil in any hook.[/QUOTE] Are you joking? When you don't return anything in a hook, it runs all other hooks until an answer is returned, if all hooks return no value then it runs the GM: function. By returning a value (true), I would be preventing all other hooks from running, breaking my logic completely. CanTool defaults to true if false wasn't returned. Suppose I have a points system, and I want to disallow use of a certain tool when the player doesn't have enough points. My hook would return false if there aren't enough points, or according to you, true otherwise. Suppose I have another, unrelated place in my code, which prevents players from using tools on props not belonging to them. I would have it return false if the trace hits an enemy prop, and according to you, true otherwise. It's impossible to say in advance which of these will run first, but let's assume it's the points one. Assume I have enough points but tooling en enemy's prop. The hook sees that I have enough points, so it returns true, and then all other cantool hooks are skipped and the tool is immediately allowed. It's obvious that if I'm not making a final decision (e.g. DON'T ALLOW), I shouldn't return a value. As for converting them to just global functions called from a central hook, sure, in that case the logic is sound that I should return a value at all times (true or false), but from your phrasing it doesn't sound like what you were saying.
[QUOTE=Revenge282;47250899]You should very rarely ever return nil in any hook.[/QUOTE] I think there's a special place in hell for your addons.
[QUOTE=Neat-Nit;47251066]Are you joking? When you don't return anything in a hook, it runs all other hooks until an answer is returned, if all hooks return no value then it runs the GM: function. By returning a value (true), I would be preventing all other hooks from running, breaking my logic completely. CanTool defaults to true if false wasn't returned. Suppose I have a points system, and I want to disallow use of a certain tool when the player doesn't have enough points. My hook would return false if there aren't enough points, or according to you, true otherwise. Suppose I have another, unrelated place in my code, which prevents players from using tools on props not belonging to them. I would have it return false if the trace hits an enemy prop, and according to you, true otherwise. It's impossible to say in advance which of these will run first, but let's assume it's the points one. Assume I have enough points but tooling en enemy's prop. The hook sees that I have enough points, so it returns true, and then all other cantool hooks are skipped and the tool is immediately allowed. It's obvious that if I'm not making a final decision (e.g. DON'T ALLOW), I shouldn't return a value. As for converting them to just global functions called from a central hook, sure, in that case the logic is sound that I should return a value at all times (true or false), but from your phrasing it doesn't sound like what you were saying.[/QUOTE] You are correct, I wasn't thinking and trying to occupy myself in class... [QUOTE=Willox;47251195]I think there's a special place in hell for your addons.[/QUOTE] If I made any with what I just stupidly spewed out, then yes, I have a front row seat. But, I was thinking more along the lines of what Neat-Nit mentioned here: [QUOTE=Neat-Nit;47251066]As for converting them to just global functions called from a central hook, sure, in that case the logic is sound that I should return a value at all times (true or false), but from your phrasing it doesn't sound like what you were saying.[/QUOTE] Sorry for throwing mixed up ideas out there.
It certainly would make more sense for hooks to work the way you described. A bit too late for that though.
[QUOTE=Willox;47251453]It certainly would make more sense for hooks to work the way you described.[/QUOTE] Not really. How would that work? Maybe I'm just too used to the current system that I can't think of any other way working.
[QUOTE=Willox;47251195]I think there's a special place in hell for your addons.[/QUOTE] I remember doing this when I was about two weeks into lua, haha. Then later, when I was more experienced, I realised my earlier work was breaking my new stuff. Anyhow, I'm having a new issue. How can I get beams to render correctly? For some reason, when certain parts of a beam go behind the player's camera, the entire thing gets culled. Here is my code: [code] if #self.vparticles>=2 then render.StartBeam(#self.vparticles) local prevpos = nil for k,v in ipairs(self.vparticles) do local alphac = ColorAlpha(smokecol, (1-(CurTime()-v.startlife)/v.lifetime) * 64) render.AddBeam(v.position,v.radius*(1-k/#self.vparticles),(k/#self.vparticles),alphac) end render.EndBeam() end [/code] It works correctly in almost all circumstances, but for some reason doesn't work when the player is moving forwards, presumably due to the problem I mentioned at the start of my post. I'm a noob when it comes to graphics programming, so any assistance would be great.
[QUOTE=Neat-Nit;47251469]Not really. How would that work? Maybe I'm just too used to the current system that I can't think of any other way working.[/QUOTE] It wouldn't work. It'd still be nicer though :v:.
Is it position to have the AddPanel function to insert at a certain position?
[QUOTE=Adzter;47252140]Is it position to have the AddPanel function to insert at a certain position?[/QUOTE] AddPanel docks the input panels. I don't see setting the position as useful. Try changing the margin of the panels you are adding instead.
[QUOTE=Adzter;47252140]Is it position to have the AddPanel function to insert at a certain position?[/QUOTE] [QUOTE=Willox;47252178]AddPanel docks the input panels. I don't see setting the position as useful. Try changing the margin of the panels you are adding instead.[/QUOTE] [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Panel/DockMargin]Panel:DockMargin[/url] [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Panel/DockPadding]Panel:DockPadding[/url]
I have an entity with the model of a prop that I want to be able to be lifted by the gravity gun, But the prop model appears to be too heavy. I have tried changing the physical properties of the entity, but other than some amusing ice sliding it didn't really get me anywhere. Has anyone had this issue before and has a fix I may have overlooked? The prop model is "[I]models/Items/ammocrate_ar2.mdl[/I]" if it makes a difference. Thank you =)
How do you get the angles of a brush door? I'm trying to do 3d2d door names which works fine on model doors but the brush doors always have the angle wrong since all brush doors have 0 0 0 angles.
[QUOTE=G4MB!T;47252983]How do you get the angles of a brush door? I'm trying to do 3d2d door names which works fine on model doors but the brush doors always have the angle wrong since all brush doors have 0 0 0 angles.[/QUOTE] I believe there is something about how opened/closed a door is in the [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/GetSaveTable]Entity:GetSaveTable[/url]. I am 99% sure it works for brush doors.
[QUOTE=Revenge282;47253184]I believe there is something about how opened/closed a door is in the [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/GetSaveTable]Entity:GetSaveTable[/url]. I am 99% sure it works for brush doors.[/QUOTE] What I really need is the angle that the brush is at which is weird to do I know. I need to rotate the door text so that its aligned with the door and not perpendicular. Some brush doors it works fine on because they are coincidentally at the right angle but others its perpendicular. Like I said, all model doors work because they have proper angles.
Discrepancies in the savetables between an open and closed door [code] touchStamp: shut = 60 open = 90 nextthink: shut = -6497 open = -6593 m_toggle_state: shut = 1 open = 0 m_vecFinalAngle: shut = 0.000000 0.000000 0.000000 open = -0.000000 -90.000000 -0.000000 ltime: shut = 1.7999999523163 open = 2.6999998092651 m_angRotation: shut = 0.000000 0.000000 0.000000 open = -0.000000 -90.000000 -0.000000 m_nSimulationTick: shut = -54 open = -50 m_flAnimTime: shut = -196.87879943848 open = -199.78788757324 m_flVPhysicsUpdateLocalTime: shut = 1.7999999523163 open = 2.6999998092651 m_flSimulationTime: shut = -2.1818237304688 open = -1.5454559326172 m_flNavIgnoreUntilTime: shut = -196.87879943848 open = -199.78788757324 m_nLastThinkTick: shut = -6463 open = -6559 m_rgflCoordinateFrame: shut = 1 open = -4.3711388286738e-008 m_flPrevAnimTime: shut = -196.87879943848 open = -199.78788757324 m_angAbsRotation: shut = 0.000000 0.000000 0.000000 open = -0.000000 -90.000000 -0.000000 m_flGroundChangeTime: shut = -196.87879943848 open = -199.78788757324 [/code] m_vecFinalAngle?
The problem is that all brush doors have an angle of (0, 0, 0) when they are closed. I'm not sure if I'm explaining my problem properly.
[QUOTE=Deathbypwnage;47252600]I have an entity with the model of a prop that I want to be able to be lifted by the gravity gun, But the prop model appears to be too heavy. I have tried changing the physical properties of the entity, but other than some amusing ice sliding it didn't really get me anywhere. Has anyone had this issue before and has a fix I may have overlooked? The prop model is "[I]models/Items/ammocrate_ar2.mdl[/I]" if it makes a difference. Thank you =)[/QUOTE] [code]yourentity:GetPhysicsObject():SetMass(250)[/code] The gravity gun can't lift anything with a mass higher than 250, so just set it to that number or less. I checked, though, and the model you're using doesn't actually have a bottom since it was never supposed to move, so if players are going to be picking it up and stuff you might want to use something else.
Hi all. I am trying to draw text over an NPC, but cant seem to find the correct hook. I'm pretty much trying to do the example at [URL="http://wiki.garrysmod.com/page/GM/PostPlayerDraw"]http://wiki.garrysmod.com/page/GM/PostPlayerDraw[/URL], but this hook is only for players. Is there a hook for NPC's?
[QUOTE=101kl;47253729]Hi all. I am trying to draw text over an NPC, but cant seem to find the correct hook. I'm pretty much trying to do the example at [URL="http://wiki.garrysmod.com/page/GM/PostPlayerDraw"]http://wiki.garrysmod.com/page/GM/PostPlayerDraw[/URL], but this hook is only for players. Is there a hook for NPC's?[/QUOTE] Use this hook instead: [url]http://wiki.garrysmod.com/page/GM/PostDrawOpaqueRenderables[/url] With the cam library, more specifically 3d2d. Its a pretty weird system to figure out but you can do a lot of good stuff with it
Is there any way to set a material of a viewmodel without it affecting the hands, even if it is a c_model, unless c_model hands don't get affected? EDIT: Would also like to know how to do this for the worldmodel also as I'm trying to make a skin system.
Sorry, you need to Log In to post a reply to this thread.