• Problems That Don't Need Their Own Thread v5
    4,111 replies, posted
[QUOTE=gonzalolog;52711693]It's a good practice, but let's be honest, api won't ever change, some of us just memorized MOUSE_LEFT as 107, as some other memorized TEXT_ALIGN_CENTER with 1 (I didn't sadly)[/QUOTE] The API has changed before, specifically with TEXT_ALIGN and ACT. Many addons broke because people didn't use enums.
[QUOTE=Moat;52711702]If it's a png, it needs to be a size that's a power of 2.[/QUOTE] Yeah. I fixed the issue, it was a 1920 png but when I scaled it down to 1200 it fucked up somehow, had to remake it for 1200 res.
[QUOTE=code_gs;52711778]The API has changed before, specifically with TEXT_ALIGN and ACT. Many addons broke because people didn't use enums.[/QUOTE] I've seen people who wrote entire animation tables with literals instead of ACT enums. Outdated literals, of course. I wanted to punch them in the mouth so goddamn much. And gonzo, remember that not everyone who looks at your code will be you. I certainly didn't memorize MOUSE_LEFT, and it's really annoying to have to look up the hook on the wiki, find out what enum it uses, go to the enum page, find the value in the table...
[QUOTE=Invule;52711428]I've made a material for my vgui but for some reason the pixels aren't where they're suppose to be? This is how they're [url="https://i.imgur.com/tWMwjp6.png"]suppose[/url] to be And this is [url="https://i.imgur.com/N1dNleM.png"]how they are[/url] in garry's mod Anyone has any idea what could be causing this? I haven't set any of the material parameters, however I have tried with no luck.[/QUOTE] The material parameter you want is probably [url=https://developer.valvesoftware.com/wiki/$alphatest]$alphatest[/url], but it would probably be more convenient for you to just use a PNG instead of VTF. One less headache. [editline]24th September 2017[/editline] I completely misread the question... What size is your image (in pixels)? It should be a square with each side being a power of 2, e.g. 64x64.
[highlight]<DELETED>[/highlight] I was giving myself the wrong SWEP in-game... whoops :boxhide:
So I have to dynamic props and I'm trying to affect one of them individually. How would I go about that? [CODE] local defaultTorso = ents.Create("prop_dynamic") defaultTorso:SetModel(selfcharacter:getData("Torso")) --This is a nutscript thing don't worry about it defaultTorso:SetParent(selfchar) --This is called someplace else on the code don't worry about it defaultTorso:SetPos(self:GetPos()) defaultTorso:Fire("setparentattachment", selfchar:GetAttachments()[1].name) defaultTorso:AddEffects(EF_BONEMERGE) defaultTorso:Spawn() local defaultHands = ents.Create("prop_dynamic") defaultHands:SetModel(selfcharacter:getData("Hands")) --This is a nutscript thing don't worry about it defaultHands:SetParent(selfchar) --This is called someplace else on the code don't worry about it defaultHands:SetPos(self:GetPos()) defaultHands:Fire("setparentattachment", selfchar:GetAttachments()[1].name) defaultHands:AddEffects(EF_BONEMERGE) defaultHands:Spawn() if selfcharacter:getData("Torso") != "models/torso.mdl" then --models/torso.mdl is set for the data someplace else don't worry about it for _, v in pairs( ents.FindByClassAndParent( "prop_dynamic", selfchar ) ) do v:Remove() end end [/CODE] I'm trying to call the specific defaultTorso but as you can see there are two different prop_dynamic entities. How would I go about calling defaultTorso specifically in the if then statement?
Could you be more specific about what you're trying to do? Maybe pseudo-code?
[QUOTE=code_gs;52714564]Could you be more specific about what you're trying to do? Maybe pseudo-code?[/QUOTE] I have two prop_dynamic entities: [CODE] local Entity1 = ents.Create("prop_dynamic") Entity1:SetModel("models/torso.mdl") Entity1:SetPos(Vector(0,0,0)) Entity1:Spawn() local Entity2 = ents.Create("prop_dynamic") Entity2:SetModel("models/hands.mdl") Entity2:SetPos(Vector(50,50,50)) Entity2:Spawn() [/CODE] I want to change the model in Entity2, but not Entity1 and I can't do because it just calls Entity1 as a nil value: [CODE] Entity1:SetModel("models/police.mdl") --Random different model [/CODE] So what I gathered is that you have to do something like: [CODE] for _, v in pairs(ents.FindByClass("prop_dynamic")) do v:Remove() end [/CODE] But I only want to do it for Entity2. Not both entities. How would I go about doing that?
You should store the entity's as variables on the entity you're parenting it to so that you can access it later. Ex. [code]local Entity1 = ents.Create("prop_dynamic") -- Other code here -- Entity1:SetParent(ParentEnt) ParentEnt.mytorso = Entity1[/code] That was, you can access Entity1 later.
[QUOTE=code_gs;52714604]You should store the entity's as variables on the entity you're parenting it to so that you can access it later. Ex. [code]local Entity1 = ents.Create("prop_dynamic") -- Other code here -- Entity1:SetParent(ParentEnt) ParentEnt.mytorso = Entity1[/code] That was, you can access Entity1 later.[/QUOTE] So when I access it later I would do? [CODE] ParentEnt.mytorso:SetModel("models/police.mdl") [/CODE] Also does the parent entity need to be something specific? Or just some other entity to parent it onto?
Yes, but you should verify ParentEnt.mytorso is valid before running methods on it. The parent entity doesn't need anything else specific.
[QUOTE=code_gs;52714632]Yes, but you should verify ParentEnt.mytorso is valid before running methods on it. The parent entity doesn't need anything else specific.[/QUOTE] Hmm, when I do this the parent entity comes back as a nil value. [CODE] attempt to index global 'selfchar' (a nil value) [/CODE] Is there a fuller example on how this would look like? This is what I have: [CODE] local selfchar = client:getChar() --This basically calls the player as an entity in Nutscript local Entity1 = ents.Create("prop_dynamic") Entity1:SetModel("models/torso.mdl") Entity1:SetParent(selfchar) Entity1:SetPos(Vector(0,0,0)) selfchar.torso = Entity1 Entity1:Spawn() local Entity2 = ents.Create("prop_dynamic") Entity2:SetModel(selfcharacter:getData("Hands")) Entity2:SetParent(selfchar) Entity2:SetPos(Vector(50,50,50)) selfchar.hands = Entity2 Entity2:Spawn() --Something happens to make this below happen-- if IsValid(selfchar.torso) then selfchar.torso:SetModel("models/police.mdl") end [/CODE] EDIT: Yeah I even tried making a whole new entity cause maybe selfchar wasn't working and it still came back as nil.
You can't use locals from other functions -- you need to call getChar every time you want to use that entity.
Anyone know what causes this physics glitch? Players can occasionally run into a prop_vehicle_jeep and move it, sometimes pushing it into the ground which in return kills the player.
[QUOTE=Gfoose;52714921]Anyone know what causes this physics glitch? Players can occasionally run into a prop_vehicle_jeep and move it, sometimes pushing it into the ground which in return kills the player.[/QUOTE] That's just vphysics for you
Not really a problem but not worth creating a thread for. Is there a way to make a drop-shadow affect with the Paint function?
[QUOTE=Unknown Gamer;52715883]Not really a problem but not worth creating a thread for. Is there a way to make a drop-shadow affect with the Paint function?[/QUOTE] If you don't want a blurred shadow, then just use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Global/DisableClipping]DisableClipping[/url], then [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/surface/DrawRect]surface.DrawRect[/url] to draw a transparent black rectangle behind the panel. If you want blur, then you could use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/surface/DrawTexturedRect]surface.DrawTexturedRect[/url] to draw a gradient on each side, but this isn't a good method
[QUOTE=MPan1;52715913]If you don't want a blurred shadow, then just use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Global/DisableClipping]DisableClipping[/url], then [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/surface/DrawRect]surface.DrawRect[/url] to draw a transparent black rectangle behind the panel. If you want blur, then you could use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/surface/DrawTexturedRect]surface.DrawTexturedRect[/url] to draw a gradient on each side, but this isn't a good method[/QUOTE] Would I use the gradient-d or whatever for the shadow?
[QUOTE=Unknown Gamer;52716124]Would I use the gradient-d or whatever for the shadow?[/QUOTE] Yes, but this wouldn't be a good method because you'd have to do some weird kind of thing for the corners of the panel. There are some tilted gradients, but it wouldn't look very smooth.
I am having issues with an AR2 replication I have been making. With the secondary attack (which is a dark energy ball launcher like in HL2), I need the user to have no secondary ammo on spawn. The code does work, however, when I switch back to the weapon, it will set my ammo to 1. Can't seem to find anything in the code. I'll post the weapon base here too (Please excuse the numerous copy and pastes of functions from TTT and possibly other places) AR2 - [url]https://pastebin.com/Si0C1rJU[/url] Weapon Base - [url]https://pastebin.com/7YSQA7L3[/url]
--snip im stupid--
[QUOTE=MelonShooter;52721330]This is why. [code] if self:Clip2() == 0 and self:Ammo2() > 0 then self:SetClip2(1) self.Owner:SetAmmo(self:Ammo2()-1,"AR2AltFire") end[/code][/QUOTE] This is in the SecondaryAttack function and shouldnt be called when I deploy the weapon? And it shouldnt be called anyways because Ammo2 is 0. Regardless, I'll try removing it EDIT Definitely not that block of code; I put a print function in so if it did run I would know, and it wasn't running. What's also bizarre is that it doesn't happen if i quickswitch. It only happens if I switch using the keyboard numbers.
[QUOTE=Sm63;52721341]This is in the SecondaryAttack function and shouldnt be called when I deploy the weapon? And it shouldnt be called anyways because Ammo2 is 0. Regardless, I'll try removing it[/QUOTE] Don't, I realized that as soon as I posted and snipped. [editline]26th September 2017[/editline] Mind if I ask, what is quickswitch and what do you mean by siwtching using keyboard nums. Pressing a number a certain number of times and clicking? Oh alright, lastinv
[QUOTE=MelonShooter;52721344]Mind if I ask, what is quickswitch and what do you mean by siwtching using keyboard nums. Pressing a number a certain number of times and clicking?[/QUOTE] Quickswitch is just a command in Source that switches to your previous held weapon. And by switching using keyboard numbers, I mean normal weapon switching in the game (keys 1-6)
How do you use string.gsub with a table? It seems this doesn't work: [CODE] local name = string.gsub(string.lower(client:getChar():getData("DefaultModel")), "^.-/.-/.-/", "") --This returns male_african.mdl (nothing wrong here) local races = "_caucasian" or "_african" or "_hispanic" or "_asian" local modelName = string.gsub(name, races, "") model = "models/humans/"..modelName print(model) [/CODE] This piece of code prints "models/humans/male_african.mdl" when it should be printing "models/humans/male.mdl" I think I read [URL="https://wiki.garrysmod.com/page/string/gsub"]here[/URL] that with string.gsub you need to use a table when it comes to things like: [CODE] local races = "_caucasian" or "_african" or "_hispanic" or "_asian" [/CODE] Although it doesn't seem to realize that "_african" is in the string and when I tried making it into a table like: [CODE] local races = {"_caucasian", "_african", "_hispanic", "_asian"} [/CODE] I only got: [CODE] bad argument #2 to 'gsub' (string expected, got table) [/CODE] Any ideas?
what exactly do you expect "local races = "_caucasian" or "_african" or "_hispanic" or "_asian"" to do? doing an or operation like that will just set "modelName" to the first thing in the or operation, in this case "_caucasian". What you should do is replace anything after the "_" and of course replace the _ [lua] name = string.gsub(name, "_.*", "")[/lua]
I'm trying to modify the TTT DNA Scanner to make a custom Traitor weapon that changes a body's role. I've got it working but it currently only works [I]]after[/I] you've searched the body, revealing the body's role. I want to change it so that you can set the body's role without having to search it, but I can't find anything in the code to do with that. Can someone tell me what it is that imposes this restriction and how I can get rid of it?
[QUOTE=Iceotty;52722127]I'm trying to modify the TTT DNA Scanner to make a custom Traitor weapon that changes a body's role. I've got it working but it currently only works [I]]after[/I] you've searched the body, revealing the body's role. I want to change it so that you can set the body's role without having to search it, but I can't find anything in the code to do with that. Can someone tell me what it is that imposes this restriction and how I can get rid of it?[/QUOTE] At line 112 in the DNA scanners lua file is [code] if CORPSE.GetFound(ent, false) then self:GatherRagdollSample(ent) else self:Report("dna_identify") end [/code] CORPSE.GetFound is the function that checks if the corpse has been identified [url]https://github.com/Facepunch/garrysmod/blob/bece6cc34eec88f058de722ebf3008521a4bc62e/garrysmod/gamemodes/terrortown/entities/weapons/weapon_ttt_wtester.lua#L112[/url]
[QUOTE=Iceotty;52722127]I'm trying to modify the TTT DNA Scanner to make a custom Traitor weapon that changes a body's role. I've got it working but it currently only works [I]]after[/I] you've searched the body, revealing the body's role. I want to change it so that you can set the body's role without having to search it, but I can't find anything in the code to do with that. Can someone tell me what it is that imposes this restriction and how I can get rid of it?[/QUOTE] [url]https://github.com/Facepunch/garrysmod/blob/bece6cc34eec88f058de722ebf3008521a4bc62e/garrysmod/gamemodes/terrortown/gamemode/corpse.lua#L11[/url]
How do I have quotes inside of a string? [code] print("[\"Name\"]") -- Not working -- I want it to print this: ["Name"] [/code]
Sorry, you need to Log In to post a reply to this thread.