Get the looking at entity index?

Hey!

I had the lua_run(_cl) command before that did something like this:

It gets your player, then it gets what entity you’re looking on.
And returns the EntIndex() of the entity in console.

I of course forgot how I made that one.
Could someone recreate it please?

Thanks

[editline]06:15PM[/editline]

Not sure if it was EntIndex() now.
But it prints out all info about that entity.

Like material path, and so on

lua_run_cl print(LocalPlayer():GetEyeTrace().Entity)

Ent index and class will be printed

Thanks!

But I would need to get the material of the entity.

**[Entity.GetMaterial

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=Entity.GetMaterial)**

I used this one, and made:

[lua]
lua_run_cl print(LocalPlayer():GetEyeTrace().Entity:GetMaterial())
[/lua]

But it only prints a empty line. Like a "
"

You can only get the material if it’s an override material (like when you use the material stool) the models default texture is inaccessible.

Ah shoot…

I know its somehow possible. But I don’t remember how :confused:

It was some kind of function that printed a whole list with info of the entity, including texture and so on. (It even worked when I looked at a brush, and I could get a texture out of it)

You can with the modelinfo module.

And how does that work?

The thread about it is here. I used the following code with it:

[lua]function GetModelMaterial(ply, cmd, args)
if !args[1] then print(“Error”) return end
local nIndex = modelinfo.GetIndex( Model( args[1] ) );
print( modelinfo.GetMaterials( nIndex ) );
end

concommand.Add(“GetModelMaterial”, GetModelMaterial)[/lua] Its serverside. Put it in autorun/server and just type GetModelMaterial “modelnamehere” in the console.

hmm…

Okey… Well I installed it… in lua/includes/modules

But I get this though:



] GetModelMaterial "models/gantry_crane/crane_trolley.mdl"
[lua\autorun\print_errors.lua:22] attempt to index global 'modelinfo' (a nil value)


[editline]08:11PM[/editline]

Line 22: local nIndex = modelinfo.GetIndex( Model( args[1] ) );

you need to require it.

Please explain what you mean?

Add require( “modelinfo” ) at the top of your lua file

Okey! Now I got rid of that problem. But next problem:




] GetModelMaterial "models/gantry_crane/crane_trolley.mdl"
[lua\autorun\print_errors.lua:24] attempt to call field 'GetIndex' (a nil value)



[editline]08:36PM[/editline]

Okey, never mind. I finally got what I wanted. By some help from someone else:

lua_run PrintTable(Entity(1):GetEyeTrace())