• Problems That Don't Need Their Own Thread v1
    4,785 replies, posted
[QUOTE=NisshokuZK;44671370]In my recent experience a comma at the end will generate an error when initializing tables without field names, i.e. [CODE] -- will error so use commas with care local names = { "Adam", "Ben", }[/CODE][/QUOTE] [img]http://i.imgur.com/F19ecMe.png[/img]
I have a question about lua... It's probably kind of dumb so I'm sorry. I understand the way it works but how do you KNOW what can and actually can be used, as in what actually exists as something you can use in your code? Like for example in the creation of an swep, one thing is "SWEP.Primary.ClipSize = -1" How would you otherwise know that "SWEP.Primary.ClipSize" is even something that exists and is what you would type in to have it do whatever function it is that it does as opposed to say, typing in something like "GunMagCount = 3" blindly, which probably doesnt do anything because it probably doesn't exist. [editline]28th April 2014[/editline] Or like "Ply" How would I know without reading it somewhere that "Ply" is something that exists and that it means "Player", and then how would I know how/where to use it?
[QUOTE=GoldenTWM;44672222]I have a question about lua... It's probably kind of dumb so I'm sorry. I understand the way it works but how do you KNOW what can and actually can be used, as in what actually exists as something you can use in your code? Like for example in the creation of an swep, one thing is "SWEP.Primary.ClipSize = -1" How would you otherwise know that "SWEP.Primary.ClipSize" is even something that exists and is what you would type in to have it do whatever function it is that it does as opposed to say, typing in something like "GunMagCount = 3" blindly, which probably doesnt do anything because it probably doesn't exist. [editline]28th April 2014[/editline] Or like "Ply" How would I know without reading it somewhere that "Ply" is something that exists and that it means "Player", and then how would I know how/where to use it?[/QUOTE] "ply" is usually used to represent the player entity, but anything can really be used in that case. As for SWEP.Primary.ClipSize, well... you could do guess work, or you can [URL="http://wiki.garrysmod.com/page/Structures/SWEP"]read[/URL]. [u][b]I need an entity to be: Usable ( +use default E ), Touchable, and Shoot-able, all without interfering with the player's movement.[/b][/u]
[QUOTE=WalkingZombie;44672370]"ply" is usually used to represent the player entity, but anything can really be used in that case. As for SWEP.Primary.ClipSize, well... you could do guess work, or you can [URL="http://wiki.garrysmod.com/page/Structures/SWEP"]read[/URL]. [u][b]I need an entity to be: Usable ( +use default E ), Touchable, and Shoot-able, all without interfering with the player's movement.[/b][/u][/QUOTE] You didn't even read the question, did you?...
I did... and uh, what I got was you didn't understand how you should know certain variable names without looking them up, that's at least what I caught [editline]28th April 2014[/editline] Oh, and the bold underline at the bottom was and is my own problem. [U][B]I need an entity to be: Usable ( +use default E ), Touchable, and Shoot-able, all without interfering with the player's movement. (basically, it runs a function when it's used, when it would be touched, and when it gets shot, but it doesn't really collide with anything) Imagine an Antlion Grub that you could use like a button[/B][/U]
[QUOTE=WalkingZombie;44672604]I did... and uh, what I got was you didn't understand how you should know certain variable names without looking them up, that's at least what I caught [editline]28th April 2014[/editline] Oh, and the bold underline at the bottom was and is my own problem. [U][B]I need an entity to be: Usable ( +use default E ), Touchable, and Shoot-able, all without interfering with the player's movement.[/B][/U][/QUOTE] Here is what you said: ""ply" is usually used to represent the player entity, but anything can really be used in that case. As for SWEP.Primary.ClipSize, well... you could do guess work, or you can read." I never asked for someone to tell me what 'ply' represents or what SWEP.Primary.ClipSize means. In fact I even show that I already know what it means in my original post. I asked how I should know of the existence of these sorts of things, as in what would do what, and what WOULDN'T do that. So to explain it again in a new fashion, for example let's say I were making a weapon and wanted it to play a sound. You'd use something like self:EmitSound( ShootSound ) ((I know what that is and I know what it does, so you don't make this mistake again, I'm not asking what self:EmitSound does...)) But how would I know that self:EmitSound is actually the thing I should type in to make it do that? Otherwise I'd be blindly typing something in like Playsound:Gun or something like that which isn't a real thing. Albeit in english saying to do the same thing, is not what would be used to make it happen in code. How would I know that self:EmitSound exists and that it is what I'd use for this
[QUOTE=GoldenTWM;44672222]Or like "Ply" How would I know without reading it somewhere that "Ply" is something that exists and that it means "Player", and then how would I know how/where to use it?[/QUOTE] You go to the wiki, look for what order the parameters are in, and put your arguments in that order. Let's use an example here. [img]http://i.imgur.com/C23xP4R.png[/img] It takes a string and it takes a function. There are other things but those are optional. One step at a time. First parameter is a string. Easy enough. [img]http://i.imgur.com/YPXFaK0.png[/img] The second parameter is a function, and I know you'll be wondering what is supposed to go there. [img]http://i.imgur.com/0oau0Z8.png[/img] If we look further down the page we see that the function should have these parameters (you don't HAVE to use any of the parameters, though). [img]http://i.imgur.com/gVG3wAv.png[/img] Parameter names can be arbitrary, but it's a good idea to name the parameters after what they represent. No one wants to look at your code and see a parameter named [B]shit[/B] because it doesn't really make sense. Name your parameters after what should go in as the argument. The first parameter is a player so we named it player. [img]http://i.imgur.com/KikUIhw.png[/img] [img]http://i.imgur.com/dxl7Geg.png[/img] Those functions both do the same thing. The only thing that actually matters is the order that they are in. Since the first parameter was named [B]player[/B], we know that it is now a valid variable to use in the function.
no, for as far as I'm aware ply is nothing but a personally chosen variable. so... basically the answer is, don't be stupid. If you didn't know what you needed to do you could look it up, but if you understand the way code works you'd eventually guess it. In the case that you're really having trouble figuring anything out for real, I recommend getting syntax highlighting installed into your text editor if it's actually difficult for you. Here I only know of one major problem, the official garry's mod wiki has a god awful search function. I hate the way it's lain out. Because of this I use [url]http://maurits.tv/data/garrysmod/wiki/[/url] since when you search it's more likely to find the right answer to your request. [editline]28th April 2014[/editline] I knew as soon as I saw brandonj4's name at the bottom of the page that I was going to get AT LEAST ONE dumb rating. [editline]28th April 2014[/editline] just a general tip to you GoldenTWM, if you really need to do a search to find what you need, and [url]http://wiki.garrysmod.com/[/url] is being a stuck-up bitch about it, then use the link above in this post.
[QUOTE=WalkingZombie;44672839]no, for as far as I'm aware ply is nothing but a personally chosen variable. so... basically the answer is, don't be stupid. If you didn't know what you needed to do you could look it up, but if you understand the way code works you'd eventually guess it. In the case that you're really having trouble figuring anything out for real, I recommend getting syntax highlighting installed into your text editor if it's actually difficult for you. Here I only know of one major problem, the official garry's mod wiki has a god awful search function. I hate the way it's lain out. Because of this I use [url]http://maurits.tv/data/garrysmod/wiki/[/url] since when you search it's more likely to find the right answer to your request. [editline]28th April 2014[/editline] I knew as soon as I saw brandonj4's name at the bottom of the page that I was going to get AT LEAST ONE dumb rating. [editline]28th April 2014[/editline] just a general tip to you GoldenTWM, if you really need to do a search to find what you need, and [url]http://wiki.garrysmod.com/[/url] is being a stuck-up bitch about it, then use the link above in this post.[/QUOTE] You failed to even be RELEVANT to a simple question 3 times in a row, but thanks anyway man. I'll just go back to the programming section, this is why nobody ever wants to come to the gmod section. And to BayLife, thanks that helped a bit but it wasn't exactly what I meant. I wasn't talking about specifics such as ply, thats just an example. very detailed and well explained post though, I appreciate it
[QUOTE=GoldenTWM;44672897]You failed to even be RELEVANT to a simple question 3 times in a row, but thanks anyway man. I'll just go back to the programming section, this is why nobody ever wants to come to the gmod section. And to BayLife, thanks that helped a bit but it wasn't exactly what I meant. I wasn't talking about specifics such as ply, thats just an example. very detailed and well explained post though, I appreciate it[/QUOTE] oh come on man, then your question is hardly obvious. I'm not even the only person to fail at understanding it apparently.
I just asked my friend so nevermind it's all good now
I'm confused...
[QUOTE=GoldenTWM;44672222]I have a question about lua... It's probably kind of dumb so I'm sorry. I understand the way it works but how do you KNOW what can and actually can be used, as in what actually exists as something you can use in your code? Like for example in the creation of an swep, one thing is "SWEP.Primary.ClipSize = -1" How would you otherwise know that "SWEP.Primary.ClipSize" is even something that exists and is what you would type in to have it do whatever function it is that it does as opposed to say, typing in something like "GunMagCount = 3" blindly, which probably doesnt do anything because it probably doesn't exist. [editline]28th April 2014[/editline] Or like "Ply" How would I know without reading it somewhere that "Ply" is something that exists and that it means "Player", and then how would I know how/where to use it?[/QUOTE] Alright, so objects / meta-tables, or classes such as SWEPs are initialized in the back-end. Anything that is in the file as SWEP. is imported into the Weapons table, kind of like you defining local PANEL = { }; and building a vgui element, then registering it. Instead of manually registering a SWEP ( even though it can be done if you don't want to use the swep dir ), anything with the SWEP prefix will be available in SWEP functions. You can also define alternative local files, and they'll follow scope of the file. So, if you define local GunMagCount = 3; at the top of a swep file, say CanPrimaryAttack, and inside SWEP:CanPrimaryAttack you check GunMagCount; you can read it. Now, there is something important to know, you can define SWEP functions, and any other meta-table or GM, or whatever functions two ways and they'll be absolutely identical. [lua]function SWEP.CanPrimaryAttack( self ) // This is the same as return self:Clip1( ) > 0; // This, and this is the same as --return self.Clip1( self ) > 0; end // Just like this is the same as the function above function SWEP:CanPrimaryAttack( ) // This is the same as return self:Clip1( ) > 0; // This, and this is the same as --return self.Clip1( self ) > 0; end[/lua] I commented one return because you can only have one or you'll get an error. So, scope, what is it and how does it work? Scope can be described as what a segment of code being executed has access to. This example will print nil, because the local variable is defined within the scope of the if; it's not seen by the print even though it's defined before it. [lua]if ( true ) then local _ammo = 30; end print( _ammo );[/lua] The same is for this, but we defined _ammo before-hand you say? Yes, but we also defined a difference instance of _ammo within the if. [lua]local _ammo; if ( true ) then local _ammo = 30; end print( _ammo );[/lua] Now it will print 30, the reason being is the scope is on the same level as the print. If we tried printing _ammo in a different file, it'd fail because they can't see locals from other files. [lua]local _ammo; if ( true ) then _ammo = 30; end print( _ammo );[/lua] I hope this helps. Quick addition: To simulate different Lua files within one file we can use a do. Load order will always be linear, so one after the other. File 1 will print properly, file 2 will not because its outside the scope of the file. [lua]// File 1 do local _ammo; if ( true ) then _ammo = 30; end print( _ammo ); end // File 2 do print( _ammo ); end [/lua] Hopefully that puts things into better perspective in terms of separate files.
I am having a really hard time getting the position of an attachment on a view model in sp. I am trying to grab it clientside because I am mocking shell ejection with clientside models. When I attempt to get the position of the attachment it sometimes returns the pos of the attachment but most of the time it returns something like 32,32,32. Any idea why it does this? I can't figure out why and its driving me insane.
How does one attach lua particles to an entity? So that they are not affected by entity moving at high speeds?
Is there a way to detect mouse wheel movement up and down? As well, how would I replace the $basetexture of a weapon's scope lens?
[url]http://wiki.garrysmod.com/page/Enums/MOUSE[/url] MOUSE_WHEEL_UP MOUSE_WHEEL_DOWN [url]http://wiki.garrysmod.com/page/input/IsMouseDown[/url]
[QUOTE=Pandaman09;44679856][url]http://wiki.garrysmod.com/page/Enums/MOUSE[/url] MOUSE_WHEEL_UP MOUSE_WHEEL_DOWN [url]http://wiki.garrysmod.com/page/input/IsMouseDown[/url][/QUOTE] Thank you. Does anyone know of an answer to my second question?
How can I extract values from the entity returned by game:GetWorld()? More specifically, the bool for "World is Cold" (coldworld)
[QUOTE=Robotboy655;44677669]How does one attach lua particles to an entity? So that they are not affected by entity moving at high speeds?[/QUOTE] Typically it's supposed to be done in a PostDrawMethod; but because particles have a life-time, gravity, and other effects they're spawned in the world and don't keep the relation unless you manually create the effect and update the position based on the deltas and the current location; it ceases to being an "effect". Now, you could use the effect Lua files, and keep track of each particle you make, instead of relying on the built-in functions to update you could do it in the effect think foreach particle created... [QUOTE=HumbleTH;44678375]Is there a way to detect mouse wheel movement up and down? As well, how would I replace the $basetexture of a weapon's scope lens?[/QUOTE] Use CreateMove; it is more reliable than input.IsMouseDown. [lua]hook.Add( "CreateMove", "CreateMove:MouseWheelCheck", function( _cmd ) local _wheel = _cmd:GetMouseWheel( ); if ( _wheel != 0 ) then print( _wheel ); end end );[/lua] To replace the texture, you'd need to find the exact texture. Use +mat_texture_list to show the list of textures; then work through getting the texture, saving a reference if you want to switch back, and overwriting $basetexture on the old with the new. [QUOTE=Nova Prospekt;44680249]How can I extract values from the entity returned by game:GetWorld()? More specifically, the bool for "World is Cold" (coldworld)[/QUOTE] On either Client or Server it'll return NULL, or empty entity if I recall correctly. I personally store worldspawn values in a list at index 0, actually I store all entity values in a list using the EntIndex as the key.
How would I go about making a derma skin for GMod? There is a lack of documentation for how to do it on the wikis.
[QUOTE=The Android1;44681854]How would I go about making a derma skin for GMod? There is a lack of documentation for how to do it on the wikis.[/QUOTE] Take a look at garrysmod/lua/skins/default.lua That contains ALL options for a skin. You can make your own and use any number of those to create the effect you want. There are minimalistic skins which only change buttons to rounded, scrollbar colors, etc. It really isn't documented that well and to find out what part of a skin you need to change usually involves digging in the vgui code, unfortunately.
[QUOTE=Acecool;44681812] On either Client or Server it'll return NULL, or empty entity if I recall correctly. I personally store worldspawn values in a list at index 0, actually I store all entity values in a list using the EntIndex as the key.[/QUOTE] Alrighty so, how do I/You go about [i]obtaining[/i] the values (and KeyValues?) for [url=https://developer.valvesoftware.com/wiki/Worldspawn]Worldspawn[/url]? That's what I'm really after D:
Hi, I try to improve a script I did.. Previously I used the HUDPaint hook to draw the names of players. Now I try to switch to PostPlayerDraw, since it could theorically make my script much simpler. But it doesn't work as expected. This is what I used before (simplified a lot) [code] hook.Add( "HUDPaint", "paint", function() for _, ply in ipairs(player.GetAll()) do ply.ToScreenData = ply:GetPos():ToScreen() draw.SimpleText(ply:Name(), fontName, ply.ToScreenData.x, ply.ToScreenData.y, Color(255,255,255, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP ) end end ) [/code] And this is what I try to do now: [code] hook.Add( "PostPlayerDraw", "paint", function( ply ) ply.ToScreenData = ply:GetPos():ToScreen() draw.SimpleText(ply:Name(), fontName, ply.ToScreenData.x, ply.ToScreenData.y, Color(255,255,255, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP ) end ) [/code] But with this, the text doesn't show at the player's pos on my screen. It seem to show at map origin + what seem to be the coordinates of where it should display on my screen, and also the angle is wrong, always pointing north. What am I missing? I know I could use cam.start3d2d, but I don't want that. I just want to understand why it's working in one hook and not working correctly in another.
[QUOTE=DEFCON1;44682888]What am I missing? I know I could use cam.start3d2d, but I don't want that. I just want to understand why it's working in one hook and not working correctly in another.[/QUOTE] HUDPaint is a 2d rendering context, so drawing to your screen works fine. IIRC PostPlayerDraw is a 3d rendering context, so you need to wrap your code inside cam.Start2D()/End2D() for it to behave the same way. You could use Start2D for having everything aligned to your screen, or Start3D2D to have them aligned to the entity (or whatever angle you choose).
[QUOTE=wh1t3rabbit;44683196]HUDPaint is a 2d rendering context, so drawing to your screen works fine. IIRC PostPlayerDraw is a 3d rendering context, so you need to wrap your code inside cam.Start2D()/End2D() for it to behave the same way. You could use Start2D for having everything aligned to your screen, or Start3D2D to have them aligned to the entity (or whatever angle you choose).[/QUOTE] Thanks a lot I totally forgot about this function Start2D ;) Edit: it's much, much slower than with my HUDPaint hook. The only advantage of PostPlayerDraw is that it can draw things behind the weapon. Well, at least I tried :) Edit again: is there a better "2D" hook than HUDPaint, in which I could draw behind the weapon ? Edit: I solved my problem by doing something like this: [code] local shouldDraw = false hook.Add("HUDPaint", "test", function() shouldDraw = true end ) hook.Add( "PreDrawViewModel", "test", function() if shouldDraw == true then -- My old code that was inside the HUDPaint hook, but now inside a cam.Start2D() shouldDraw = false end end ) [/code] This way, it is drawn only when needed, and behind the weapon :) . I lose only few FPS. I will do some more experiments, I'm sure there is still a better way. Feel free to reply if you have another solution!
[QUOTE=Robotboy655;44677669]How does one attach lua particles to an entity? So that they are not affected by entity moving at high speeds?[/QUOTE] Set the particles velocity to effectdata:GetEntity():GetVelocity() + YourNewVelocity or use this: [code] ParticleEffectAttach( "particle_name", PATTACH_ABSORIGIN_FOLLOW, entity, 0 ) [/code] But this makes the particle effect spawn the particles at the entity but there's nothing that tells them to maintain the velocity of the parent object. Not sure if you can specify that as a flag or keyvalue in the Particle Editor.
trying to make players spawn as spectators on inital spawn... dosen't work. players just spawn as normal.. does anyone know how to do this? i do DeriveGamemode( "base" ) in my shared.lua not sure if this has something to say but anyway.. [lua] function GM:PlayerInitialSpawn(ply) ply:SetTeam(TEAM_SPECTATOR) ply:Spectate( OBS_MODE_ROAMING ) end [/lua]
[QUOTE=DEFCON1;44683378]Thanks a lot I totally forgot about this function Start2D ;) Edit: it's much, much slower than with my HUDPaint hook. The only advantage of PostPlayerDraw is that it can draw things behind the weapon. Well, at least I tried :) Edit again: is there a better "2D" hook than HUDPaint, in which I could draw behind the weapon ? Edit: I solved my problem by doing something like this: [code] local shouldDraw = false hook.Add("HUDPaint", "test", function() shouldDraw = true end ) hook.Add( "PreDrawViewModel", "test", function() if shouldDraw == true then -- My old code that was inside the HUDPaint hook, but now inside a cam.Start2D() shouldDraw = false end end ) [/code] This way, it is drawn only when needed, and behind the weapon :) . I lose only few FPS. I will do some more experiments, I'm sure there is still a better way. Feel free to reply if you have another solution![/QUOTE] I'm not sure if this would be any better than your solution but I draw 'behind' the weapon in HUDPaint by using [URL="www.facepunch.com/threads/878986-Stencil-tutorial"]stencils[/URL]. Draw the viewmodel onto the stencil, and then it set it to only draw anything outside of that area. Anything you draw will be cut by the viewmodel and seem to be going behind it.
[QUOTE=wh1t3rabbit;44683196]HUDPaint is a 2d rendering context, so drawing to your screen works fine. IIRC PostPlayerDraw is a 3d rendering context, so you need to wrap your code inside cam.Start2D()/End2D() for it to behave the same way. You could use Start2D for having everything aligned to your screen, or Start3D2D to have them aligned to the entity (or whatever angle you choose).[/QUOTE] Make sure what is returned isn't NULL; if it is look at Entity( 0 ) which may also return NULL, etc -- you may also be able to do a search ents.FindByClass( "worldspawn" )[ 1 ];.. That is if you're trying to target it directly to retrieve data that you didn't set. If you want to set / track data, I'd still recommend making your own table and managing it that way without attaching it directly to the entity.
Sorry, you need to Log In to post a reply to this thread.