• Select entities by color and do something to them?
    4 replies, posted
Im trying to do that if an entity is transparent (like alpha 190 or less), a halo is drawn around it. (This is being run clientside btw) and i've tried many ways to do it, by using the GetAll() and then v:GetColor() but for some reason it doesn't work. I tried printing the v:GetColor() and it printed me, instead of a color table, something like. [CODE]table: 0x546e9e48 table: 0x4392df30 table: 0x55b3f1a0 table: 0x54c0a6c8 table: 0x55af5a18 table: 0x5588c300 table: 0x473b7c68 [/CODE] which I supose is something like a "table ID"? I also thought about using traces but the trace result table doesn't return anything like the color. Something I thought about is doing a code in all entities that is like: if self.GetColor() == Color(0,0,0,190) then [draw the halo] But I don't know how to do that, and i didn't find any answers online or in the wiki, on how to run code in all the entities (which is something I'm sure it's not that hard to do because It's pretty useful) Here is the code of the getall and getcolor. [CODE]hook.Add("Think", "colorGet", function() for k,v in pairs(ents.GetAll()) do if v:GetColor() == Color(0,0,0,190) then print("testwork") halo.Add(ents.GetAll(), Color(255,0,0,255), 5, 5,30, true, true ) end end end)[/CODE] This is for my server because it's annoying when someone gets the color tool and uses it to make something invisible,to help with the administration of my server, and I also had the chance to try to code, but I got stuck with this. EDIT: Solved it, just did some messing around with tables, here's the code: [CODE]wantHolo = {} transparencia = 180 hook.Add("Think", "colorGet", function() enties = ents.FindByClass("prop_physics") for k,v in pairs(enties) do if v:GetColor().a <= transparencia then table.insert(wantHolo,v) end if v:GetColor().a > transparencia then table.remove(wantHolo,k) end end end) hook.Add("Think","drawear",function() halo.Add(wantHolo, Color(255,0,0,255), 5, 5,30, true, true ) end)[/CODE]
You could try [lua] if v:GetColor().a <= 190 then [/lua]
[QUOTE=James xX;52508098]You could try [lua] if v:GetColor().a <= 190 then [/lua][/QUOTE] For some reason, even if there aren't any entities with that color the halo is drawn everywhere (even though this is because in the halo I target all entities)
[QUOTE=h3xu.hg;52508110]For some reason, even if there aren't any entities with that color the halo is drawn everywhere (even though this is because in the halo I target all entities)[/QUOTE] That would be because you are adding a halo to all entities. [lua] halo.Add(ents.GetAll(), [/lua] This code means add a halo to every entity.
Please don't add Halos on the Think hook, add them on this hook: [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/PreDrawHalos]GM:PreDrawHalos[/url]
Sorry, you need to Log In to post a reply to this thread.