Player:GetEyeTrace() doesn't work on a specific model?
7 replies, posted
Hello Facepunch,
Thoughtout the momentos of pulling my hair out I've decided to take my issue here to see if anyone can solve this.
Somehow, the code doesn't run for one of the models, could anyone figure this out?
[CODE]
local PropDamage = {
"models/props_building_details/Storefront_Template001a_bars.mdl",
// The model above doesn't want to work for some reason?
"models/props_c17/door01_left.mdl"
}
function PropsHUD()
local Ent = LocalPlayer():GetEyeTrace().Entity
if IsValid( Ent ) then
draw.SimpleText( "Model: ".. Ent:GetModel(), "DermaDefault", ScrW()/2, ScrH()/2, Color( 255, 255, 255 ) )
end
for k, v in pairs( PropDamage ) do
if Ent:GetModel() == v then
LocalPlayer():ChatPrint( "Found Prop From Table" )
else
LocalPlayer():ChatPrint( "not in tbl" )
end
end
end
hook.Add( "HUDPaint", "PropHUD_HUDPaint", PropsHUD )
[/CODE]
Check if the prop has a collision model, so that the eye trace hits it.
No need, it hits because the text prints on screen the model name, etc.
So what part doesn't work? You said it doesn't work on it and now you say it does work on it?
Sorry, I explained awfully. So when i look at a prop, if it's in the table it'll chat print "Found Prop From Table". That works for one of the props ( stated aboved ) however, the 'simple.text', does print and it does show me the model of both of them.
Try this way, it's much easier and less CPU intensive since it doesn't have to go through all the table:
local table =
{
["models/props_building_details/Storefront_Template001a_bars.mdl"] = true,
["models/props_c17/door01_left.mdl"] = true
}
if(table[Ent:GetModel()] == true) then
--do stuff here
end
We set the name of the model as the INDEX for the value we store (In this case it's "true")
If that doesn't work then try seeing if you misspelled it and compare the string that you copied and pasted to the string it returns you.
Small critique, but I wouldn't call the variable "table" since you're overriding a global otherwise
I just ran out of names to put there.
Sorry, you need to Log In to post a reply to this thread.