• How to stop ents.CreateClientProp() from rendering model in firstperson?
    18 replies, posted
As the title says, ents.CreateClientProp() does what its supposed to do, but I'm wondering if theres a way to make it stop rendering in first person (Running this off of a concommand for the time being.). Code: concommand.Add( "helmettest", function( ply, cmd, args ) local HelmetVisor = ents.CreateClientProp() HelmetVisor:SetModel( "models/props_silo/welding_helmet.mdl" ) HelmetVisor:SetParent(ply, 7) HelmetVisor:Spawn() end) https://i.imgur.com/egNP6ft.png https://i.imgur.com/JgypZ8s.png
Use a GM/PostPlayerDraw hook to draw the entity with ENTITY/Draw.
Entity/SetNoDraw
Thank you! Those will work.
Got another question now. The model works perfectly fine except it won't stay on the players head as intended? Know a good fix for this? concommand.Add( "helmettest", function( ply, cmd, args ) local HelmetVisor = ClientsideModel( "models/props_silo/welding_helmet.mdl", RENDERGROUP_STATIC ) HelmetVisor:SetNoDraw( true ) hook.Add( "PostPlayerDraw" , "DrawHelmetVisor" , function( ply ) if not IsValid( ply ) or not ply:Alive() then return end local attach_id = ply:LookupAttachment( 'eyes' ) local attach = ply:GetAttachment( attach_id ) local pos = attach.Pos local x = pos.x local y = pos.y local z = pos.z local ang = attach.Ang HelmetVisor:SetPos( Vector(x - 5, y, z) ) HelmetVisor:SetParent( ply, 7 ) HelmetVisor:DrawModel() end ) end)
So what you can do is attach it to a bone instead using Entity/FollowBone, also that's a terrible way of implementing the PostPlayerDraw hook.
I figured. Used SetParent instead and it WORKS but now I have another issue. If I'm in thirdperson and use the command, the helmet angles itself perfectly. But if I use the command in firstperson, the helmet angles itself like shit. Not sure why its happening. net.Receive( "HelmetRunCL", function( ply ) local HelmetVisor = ClientsideModel( "models/props_silo/welding_helmet.mdl", RENDERGROUP_STATIC ) HelmetVisor:SetNoDraw( true ) //DrawMaterialOverlay( "blacksnow/helmetoverlay", 0.06 ) hook.Add( "PostPlayerDraw" , "DrawHelmetVisor" , function( ply ) if not IsValid( ply ) or not ply:Alive() then return end //local attach_id = ply:LookupAttachment( 'eyes' ) //local attach = ply:GetAttachment( attach_id ) //local pos = attach.Pos //local x = pos.x //local y = pos.y //local z = pos.z //local ang = attach.Ang HelmetVisor:SetPos( Vector(ply:GetBonePosition(6)) ) //HelmetVisor:FollowBone(ply, 6) //HelmetVisor:SetAngles(Angle(90, 0, 0)) HelmetVisor:SetParent( ply, 7 ) //if SERVER then //HelmetVisor:Fire("SetParentAttachment", "eyes") //end HelmetVisor:DrawModel() end ) end) Tried a few ways, but it didn't work. Any idea whats the cause? https://files.facepunch.com/forum/upload/111222/e35915a0-a113-48b9-80ec-60aea83ac791/hl2_jZvv4wu1vk.png
Maybe using Fire on server side to attach it to a bone would do the trick for both views?
Remove it when in FirstPerson.
I want it to work in both views.
That doesn't make sense, you've asked us how to stop it from rendering in first person - Also you do realize, that you're doing it all clientside? The visor won't be visible to any other player, but you.
Oh sorry for the confusion. The visor will be an overlay that I already did and it works. The issue im having is when I use the command in firstperson the helmet changes it angle depending on where im looking at, but in thirdperson the helmet angles itself perfectly.
Might be because the player model might not exist when you're in the first person, so the bone/attachment angles are invalid - You could just set a bool on the player, that once he leaves first person gets checked, and only then the prop is created. Also, it might be better to opt-in to use a serverside implementation instead of clientside model, clientside models tend to unparent themselves during a big stutter freeze - and well, you gotta do all that networking fiasco to make sure every player sees it - serverside prop would have disabled collisions, and generally wouldn't do much to the performance, also there's a chance that you won't run into those positioning issues serverside.
That is true. Was thinking about having collisions with the model as well for that extra realism, but thats besides the point. I'll try redoing the code to work on server side and I'll keep you updated once I'm home.
Aaaand my issues continue. This time, the model doesnt do a switcheroo on angles during perspective changes, however now I can't rotate the model at all: net.Receive( "HelmetRunCL", function( ply ) local HelmetVisor = ClientsideModel( "models/props_silo/welding_helmet.mdl", RENDERGROUP_STATIC ) HelmetVisor:SetNoDraw( true ) hook.Add( "PostPlayerDraw" , "DrawHelmetVisor" , function( ply ) if not IsValid( ply ) or not ply:Alive() then return end HelmetVisor:SetPos( Vector(ply:GetBonePosition(6)) ) //HelmetVisor:FollowBone(ply, 6) HelmetVisor:SetParent( ply ) local helmetAngles = HelmetVisor:GetAngles() HelmetVisor:SetAngles(Angle(LocalPlayer():EyeAngles())) --- Fuck you if SERVER then HelmetVisor:Fire("SetParentAttachment", "eyes") end HelmetVisor:DrawModel() end ) end) Still using networking cause this seems a lot better in some cases, but anyways. The issue i'm getting now is if I change the angle it fixes itself into position and won't rotate with the player at all. It only does that with EeyeAngles() now. Any fixes?
Try to set the parent after setting the Angle
Nope, still the same.
You should not really be using new hook.Add and hook.Remove everytime to draw the helmet. You should make it once, so it runs constantly, but only draw the model when it is needed. For reference, you can try looking here gasmask/g4p_gasmask_cl.lua at master · Gmod4phun/gasmask · GitHu.. , maybe it will help you figure out something.
Dont check for IsValid in PostPlayerDraw. Don't parent it. Create the clientside model in the hook, if it doesn't exist, otherwise update position and angles, every time the hook is called and then draw the model. There's not a better way I could imagine. For reference: Clientside models tend to randomly be removed and wrong positioned, therefore update the pos frequently.
Sorry, you need to Log In to post a reply to this thread.