• Trace code doesn't work the way I need it to
    2 replies, posted
cl_ragdollsearching.lua: [code]--cl_ragdollsearching.lua(this is included in cl_init, it prints success but doesn't show the derma menu ) --trace info function GM:PlayerBindPress( ply, bind, pressed ) if string.find( bind, "use" ) then local tracedata = {} tracedata.start = ply:EyePos() tracedata.endpos = ply:EyePos() + ply:GetAimVector() * 75 tracedata.filter = ply tracedata.mins = Vector( -8 , -8 , -8 ) tracedata.maxs = Vector( 8 , 8 , 8 ) ply:LagCompensation( true ) local tr = util.TraceHull( tracedata ) ply:LagCompensation( false ) if tr.Hit then print("Success!") if tr.Entity == "hl2mp_ragdoll" then df:Show() end end end end [/code] cl_init.lua: [code]include("cl_ragdollsearching.lua") local df = vgui.Create( "DFrame" ) df:Center() df:SetTitle( "Body Search" ) df:SetSize( 300, 200 ) df:Hide() local dl = vgui.Create( "DLabel", df ) dl:SetFont( "DermaLarge" ) dl:Dock( TOP ) dl:SetText( "BODY SEARCH RESULTS:" ) [/code] Why isn't it showing the derma menu when I spawn a ragdoll via the console like so(yes, I am going within the trace's distance and pressing E): [code]lua_run local rag = ents.Create( "hl2mp_ragdoll" ) rag:SetPos( Vector(0,0,0) ) rag:SetModel( "models/player/combine_soldier.mdl" ) rag:Spawn() [/code] ?
At first glance I'd say you are tying to compare an entity to a string, which won't work. You'll have to use tr.Entity:GetClass() == "hl2mp_ragdoll" instead of tr.Entity. [editline]7th June 2015[/editline] Also, make sure you check if the entity is valid (IsValid(tr.Entity)) in the same statement.
[QUOTE=_nonSENSE;47898961]At first glance I'd say you are tying to compare an entity to a string, which won't work. You'll have to use tr.Entity:GetClass() == "hl2mp_ragdoll" instead of tr.Entity. [editline]7th June 2015[/editline] Also, make sure you check if the entity is valid (IsValid(tr.Entity)) in the same statement.[/QUOTE] Okay, so I figured out that util.TraceHull doesn't work the way it should clientside, so I decided to use util.TraceLine. Here's the updated code(which still doesn't work): [code]--trace info function GM:PlayerBindPress( ply, bind, pressed ) if string.find( bind, "use" ) then local tracedata = {} tracedata.start = ply:EyePos() tracedata.endpos = ply:EyePos() + ply:GetAimVector() * 75 tracedata.filter = ply tracedata.mins = Vector( -8 , -8 , -8 ) tracedata.maxs = Vector( 8 , 8 , 8 ) ply:LagCompensation( true ) local tr = util.TraceLine( tracedata ) ply:LagCompensation( false ) if tr.Hit then print("Success!") if not IsValid(tr.Entity) then print("Didn't succeed...") return end if tr.Entity:GetClass() == "hl2mp_ragdoll" then df:Show() end end end end [/code] And even if I look at the entity within the trace's distance, it prints( "Didn't succeed")...
Sorry, you need to Log In to post a reply to this thread.