proper use for .HitTexture?

The title, what is the proper use of .HitTexture I couldn’t find any examples.

What do you mean by proper use?

As in what’s defined

[lua]local pl = player.GetByID(1)
local traceRes = pl:GetEyeTrace()
if traceRes.HitWorld then
Msg("Hit world!
Msg("Didn’t hit world!

like in that example will player.GetByID( 1 ) or would i need to loop through all the players and change it to v

Could be used for playing different sounds based on the texture a bullet hits.


It returns a string containing the texture of the surface the trace hit.

It contains the texture of the world surface your trace hits, but you can’t use it to to find what textures a model uses, it works only when you hit world surfaces.

If you don’t know what something does, lua_run and lua_run_cl are your best friends.

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

Entity(1) is the first player, that means you, if you’re playing singleplayer. Look at various stuff, execute this, see what happens. You don’t need examples.

[editline]6th January 2011[/editline]

fuck :ninja:

So then could I do this:

[lua]concommand.Add(“gettexture”, function()
local pl = LocalPlayer().GetByID( 1 ) --this is where I am stuck, the GetByID( 1 ) is pointless if I am using LocalPlayer() right?
local traceRes = pl:GetEyeTrace()
filex.Append(“textures.txt”, traceRes.HitTexture

what the fuck is this shit

[lua]concommand.Add(“gettexture”, function(pl)
local traceRes = pl:GetEyeTrace()
filex.Append(“textures.txt”, traceRes.HitTexture)

Although you’ll probably need to do filex.Append(“textures.txt”, traceRes.HitTexture…"
") just so your text file is actually readable.

Corrected code:

if ( CLIENT ) then
concommand.Add(“gettexture”, function()
local traceRes = LocalPlayer():GetEyeTrace()
ErrorNoHalt( “The texture you are looking at:”…tostring( traceRes.HitTexture )…"
" )

Yeah that’s what I thought

I know it’s not very relevant in that precise situation because your concommand is clientside, but for your information, the first argument of the function you pass to concommand.Add is the player who ran the concommand.


Wait. So you want something like a missing texture report command for your server or what?

I just want it so that when I run the command. it saves the texture (with it’s file path, I assumed HitTexture included it) to a file.

Why do you want to save it to a file? Printing it to the console is much simpler.

So that I have them all saved, I will need them all later. I would rather not copy paste 50 textures when I could have them all saved automatically.

Wait, do you want to save the whole texture, or simply its name?
Would be a lot simpler if you simply told us what you are trying to do exactly. Maybe you’re not looking at the right solution.

[editline]6th January 2011[/editline]

oh okay

looks at wall runs command saves the texture with its filepath to file for changing later

[editline]6th January 2011[/editline]

thanks fp