GMod Lua-problems with userdata and string values

I need some help getting part of a script to work. My issue is that I need a value to be a string rather than userdata in a string.find, but I’ve heard it’s pretty much impossible to convert, so I’m hoping it’s possible to just use the context of what I’m trying to do to properly get the var I would like. Take a look at the example below to know what I mean.



--An example, trying to find whether a prop (in this case, a barrel) exists in an environment or not.
for k, v in pairs( ents.GetAll() ) do
	for i=0,v:GetPhysicsObjectCount() do
	local bone=v:GetPhysicsObjectNum(i)
	if IsValid(bone) then --I NEED to validate it as I need to use it later (you'd know why if this was the original script, but it shouldn't be important).
	  if not string.find( bone, "models/props_c17/oildrum001.mdl" ) then --'string' expected, got userdata
		print("Barrel not found!")
		else
		print("Barrel found!")
				end
			end
		end
	end
end


In case you missed it,



if IsValid(bone) then


returns a userdata value rather than a string, making the string.find impossible. Please help.

Also, in case it helps, there is an entity using this script, and I would like the script to exclude the entity (assuming it has a barrel as it’s model, as in this example). Maybe I can just use the context of what I want to do?

-snip-

Forgot that PhysicsObjects don’t have GetModel.

This might be a dumb suggestion, but have you tried bone:GetEntity():GetModel()? This would get the model of the parent entity, since PhysOBJs don’t often exist without them (usually as worldprop or prop_physics for oildrumbs)

Try this- it says ‘GetEntity’ is nil~



for k, v in pairs( ents.GetAll() ) do
	for i=0,v:GetPhysicsObjectCount() do
	local bone=v:GetPhysicsObjectNum(i)
	if IsValid(bone) then
          local str = bone:GetEntity():GetModel()
	  if not string.find( str, "models/props_c17/oildrum001.mdl" ) then
		print("Barrel not found!")
		else
		print("Barrel found!")
				end
			end
		end
	end
end


[editline]5th March 2015[/editline]

If it helps, this script gets run WITHIN an entity (and within a function), so perhaps ‘self’ can be used somehow, assuming that this entity has the oildrum model?

Nevermind, V:GetModel() works (I didn’t say it had to be the bone)