• Getting materials from Muscles, Elastics, Rope, etc.?
    3 replies, posted
Hey, a friend recently asked me on how to print the material from specific "toolgun outputs", like rope, elastics and stuff, into the console or a file. The way on how to this has recently bothered me alot. This is how far I've gotten. I tried to do this: [CODE] for k, v in pairs(ents.GetAll()) do if ( v:GetClass() == "class_C Rope") then MsgN(v:GetMaterial()) end end[/CODE] (also tried class c_RopeKeyFrame) things print blank into the console. Nothing else, really. Tried GetTable and GetSaveTable, but it just returns the classes. Tried to do [CODE]hook.Add('OnEntityCreated','fdf', function(ent) PrintTable(ent:GetKeyValues()) end) [/CODE] and it returns this: [url]http://pastebin.com/esiKLabA[/url] Nothing useful for what I can see. If the Rope Tool's code is interesting to anyone, here it is: [url]http://pastebin.com/7cJCfJCf[/url] I don't think it's impossible to get the material of a spawned rope, does anyone have a clue?
This can be done in several ways, such as using [i]IsConstraint[/i]. If I recall though, elastic, muscle and other springs aren't classed as constraints with this method. If you're looking for those, you'll need to search for the appropriate class. Something like this: [lua]for _,v in pairs(ents.GetAll()) do if v:GetClass() == "classname" then MsgN(v.material) end end[/lua] The classes I know of are as follows: [code]phys_spring - elastic, hydraulic, winch, muscle phys_lengthconstraint - rope phys_slideconstraint - slider phys_pulleyconstraint - pulley[/code] As far as I know, all constraints have [i]Type[/i] and [i]material[/i] variables in their table. [i]Type[/i] will be the listed name (case-sensitive) i.e. Elastic, Rope, Muscle. You could therefore search using something like this: [lua]for _,v in pairs(ents.GetAll()) do local class, ctype = v:GetClass(), v.Type if class == "required_class" && ctype == "Type" then MsgN(v.material) end end[/lua] Beware however, world-to-world (brush-to-brush) constraints aren't registered as constraint-entities, and won't be found.
[QUOTE=thefreeman193;39093772] Beware however, world-to-world (brush-to-brush) constraints aren't registered as constraint-entities, and won't be found.[/QUOTE] Yeah I guess that's the problem I had. Thanks for helping anyways. Also that code is server-side right?
Yep, the code will only work serverside. After a little more testing, I discovered that brush-brush ropes are of the class [i]keyframe_rope[/i]. Although unlike [i]real[/i] constraints, they still have a [i]Type[/i] member, as well as [i]material[/i], in their table. So, rather than searching for specific classes, you could search through all entities for the existence of these members, and sort your results using the value contained within [i]Type[/i].
Sorry, you need to Log In to post a reply to this thread.