Getting materials from Muscles, Elastics, Rope, etc.?


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:

for k, v in pairs(ents.GetAll()) do
if ( v:GetClass() == "class_C Rope") then

(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

hook.Add('OnEntityCreated','fdf', function(ent) PrintTable(ent:GetKeyValues()) end)

and it returns this:

Nothing useful for what I can see.

If the Rope Tool’s code is interesting to anyone, here it is:

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 IsConstraint. 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

The classes I know of are as follows:

phys_spring - elastic, hydraulic, winch, muscle
phys_lengthconstraint - rope
phys_slideconstraint - slider
phys_pulleyconstraint - pulley

As far as I know, all constraints have Type and material variables in their table. Type 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

Beware however, world-to-world (brush-to-brush) constraints aren’t registered as constraint-entities, and won’t be found.

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 keyframe_rope. Although unlike real constraints, they still have a Type member, as well as material, 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 Type.