• Altering Viewmodels
    18 replies, posted
Is there a way to parent a clientside prop to a viewmodel and have it render over said viewmodel? [lua] function SWEP:AttachProp() self.Weapon:RemoveProp() local vm = self.Owner:GetViewModel() if IsValid( vm ) then self.Prop = ents.CreateClientProp( "models/dav0r/hoverball.mdl" ) self.Prop:SetModelScale( 1.4, 0 ) self.Prop:SetPos( self.Owner:GetShootPos() + self.Owner:GetAimVector() * 10 ) self.Prop:SetParent( vm ) end end function SWEP:RemoveProp() if IsValid( self.Prop ) then self.Prop:Remove() self.Prop = nil end end function SWEP:ViewModelDrawn( vm, ply, wep ) local bone = vm:LookupBone( "ValveBiped.Bip01_R_Hand" ) local mat = vm:GetBoneMatrix( bone ) local ang = Angle(0,0,0) local pos = Vector(0,0,0) if mat then pos = mat:GetTranslation() ang = mat:GetAngles() end self.Prop:SetPos( pos ) //self.Prop:DrawModel() end[/lua] This doesn't fully work. [img]http://i.imgur.com/rKcwFqR.jpg[/img] When i call self.Prop:DrawModel(), it draws instead of the viewmodel.
put self.Prop:SetNoDraw( true ) to the AttachProp function, and draw the model manually: self.Prop:SetPos( pos ) cam.IgnoreZ( true ) self.Prop:DrawModel() cam.IgnoreZ( false )
I must be using the wrong hook or something because no matter what, when i call self.Prop:DrawModel() it draws the prop as if it is the viewmodel (ie. in the same position as the viewmodel). Also with ignoreZ, my viewmodel acts really weird and draws inside of walls and stuff.
[QUOTE=twoski;43882813]I must be using the wrong hook or something because no matter what, when i call self.Prop:DrawModel() it draws the prop as if it is the viewmodel (ie. in the same position as the viewmodel). Also with ignoreZ, my viewmodel acts really weird and draws inside of walls and stuff.[/QUOTE] Hm, then you should try using PostDrawViewModel hook. It's not WEAPON hook, it's GAMEMODE one.
[QUOTE=ks_uw-the_cat;43883938]Hm, then you should try using PostDrawViewModel hook. It's not WEAPON hook, it's GAMEMODE one.[/QUOTE] [URL="https://github.com/garrynewman/garrysmod/blob/master/garrysmod/gamemodes/base/gamemode/cl_init.lua#L592"]It is actually a SWEP hook too.[/URL]
[QUOTE=Robotboy655;43884015][URL="https://github.com/garrynewman/garrysmod/blob/master/garrysmod/gamemodes/base/gamemode/cl_init.lua#L592"]It is actually a SWEP hook too.[/URL][/QUOTE] Well, these functions are called by GAMEMODE, so they aren't really WEAPON hooks :/
Well the gamemode calls that hook on all weapons i am pretty sure since i have been doing it through weapons. It seems that halos also fuck up the model, whenever i am drawing a halo the model becomes completely black. [IMG]http://i.imgur.com/7ZudDH0.jpg[/IMG] [IMG]http://i.imgur.com/ng34mrh.jpg[/IMG] It covers up the bugbait model but just barely, is there a way to make the bugbait invisible?
Have you taken a look at SWEP construction kit? You could probably fix whatever issue you're having by perusing the base code.
[QUOTE=twoski;43884491]Well the gamemode calls that hook on all weapons i am pretty sure since i have been doing it through weapons. It seems that halos also fuck up the model, whenever i am drawing a halo the model becomes completely black. [IMG]http://i.imgur.com/7ZudDH0.jpg[/IMG] [IMG]http://i.imgur.com/ng34mrh.jpg[/IMG] It covers up the bugbait model but just barely, is there a way to make the bugbait invisible?[/QUOTE] post code of it or they cant help lol
[QUOTE=twoski;43884491]Well the gamemode calls that hook on all weapons i am pretty sure since i have been doing it through weapons. It seems that halos also fuck up the model, whenever i am drawing a halo the model becomes completely black. [IMG]http://i.imgur.com/7ZudDH0.jpg[/IMG] [IMG]http://i.imgur.com/ng34mrh.jpg[/IMG] It covers up the bugbait model but just barely, is there a way to make the bugbait invisible?[/QUOTE] Well, you could try using position bone/attachment to set position of your ball to. Making bugbait invisible could be done changing its material and adding nodraw flag. Material( '< bugbait mat >' ): <magik i'm not sure about> probably: :SetInt( '$nodraw', 1 )
To answer your question, I see no need to further modify the viewmodel, but if it's really an issue you can try 1. Bonescaling on the bait 2. Setting the viewmodel alpha to 0, or setting the material to debug/hsv. This works because you are using cmodel hands, and any color/material changes will not affect the hands.
[QUOTE=BFG9000;43884742]To answer your question, I see no need to further modify the viewmodel, but if it's really an issue you can try 1. Bonescaling on the bait 2. Setting the viewmodel alpha to 0, or setting the material to debug/hsv. This works because you are using cmodel hands, and any color/material changes will not affect the hands.[/QUOTE] If he's parenting the object to his Viewmodel what ever settings it has is applied to child entities.
This is my code [lua] function SWEP:PostDrawViewModel( vm, ply, wep ) local bone = vm:LookupBone( "ValveBiped.Bip01_R_Hand" ) local mat = vm:GetBoneMatrix( bone ) mat:Scale(Vector(5,5,5)) vm:SetBoneMatrix( bone, mat ) local ang = Angle(0,0,0) local pos = Vector(0,0,0) if mat then pos = mat:GetTranslation() ang = mat:GetAngles() end self.Prop:SetPos( pos + ang:Forward() * 10 + ang:Up() * -2 ) cam.IgnoreZ( true ) self.Prop:DrawModel() cam.IgnoreZ( false ) end[/lua] I don't know if there is a bone name for the bugbait, i didn't see anything like that in the model viewer but it's been acting up for me so who knows. Mainly the issue i want to fix right now is the clientside model turning black whenever i am drawing halos. I tried doing a bunch of different render library calls to make sure engine lighting isn't suppressed etc. but no dice. Maybe if i could see garry's halo draw code i'd be able to fix it.
You don't need to use cam.* library or draw a client prop, however, wiki is complete shit and the clientsideprop function seems to bug a little. Try basing this as your spawn func: [lua] function SWEP:PostDrawViewModel( vm, ply, weapon ) ply = self.Owner; if !self.Object then self.Object = ents.CreateClientProp("models/dav0r/hoverball.mdl"); self.Object:SetModel("models/dav0r/hoverball.mdl"); self.Object:SetParent(vm); self.Object:SetPos(ply:GetShootPos()); self.Object:Spawn(); end end [/lua] [editline]12th February 2014[/editline] Update the position in SWEP:ViewModelDrawn( vm ) or a Think, give me a little I'm trying to see if I can think of a way to NoDraw the viewmodel.
Get bone name with Swep Construct Kit and manipulate bone scale will do the job.
[QUOTE=Commander11;43885256]You don't need to use cam.* library or draw a client prop, however, wiki is complete shit and the clientsideprop function seems to bug a little. Try basing this as your spawn func: [lua] function SWEP:PostDrawViewModel( vm, ply, weapon ) ply = self.Owner; if !self.Object then self.Object = ents.CreateClientProp("models/dav0r/hoverball.mdl"); self.Object:SetModel("models/dav0r/hoverball.mdl"); self.Object:SetParent(vm); self.Object:SetPos(ply:GetShootPos()); self.Object:Spawn(); end end [/lua] [editline]12th February 2014[/editline] Update the position in SWEP:ViewModelDrawn( vm ) or a Think, give me a little I'm trying to see if I can think of a way to NoDraw the viewmodel.[/QUOTE] what you have there would just put the prop in my face, with the code i have it would at least be properly placed on top of the bugbait... i'm doing things more or less like you are except i'm manually drawing the prop in the draw hook in order to get the z-level right. And it looks funny to me, the ball draws over top of the hand. I was hoping to get the fingers over top of it to make it look more real but that might not be possible.
[QUOTE=twoski;43885659]what you have there would just put the prop in my face, with the code i have it would at least be properly placed on top of the bugbait... i'm doing things more or less like you are except i'm manually drawing the prop in the draw hook in order to get the z-level right. And it looks funny to me, the ball draws over top of the hand. I was hoping to get the fingers over top of it to make it look more real but that might not be possible.[/QUOTE] I seriously second BFG9000's comment, check out the code generated by SWEP Construction kit, I've made a 'plasma grenade' swep done exactly as you are trying to do (have a hoverball gripped 'inside' the hand) and had no issues with halos/going black.
Ok so i used the same method as the construction kit to create the client prop. Apparently you have to make it use the same render group as viewmodels, so that fixed the halo shit. I can't scale down the bugbait though, and i'm doing what his code does... There must be something i am missing. [lua] local ms = Vector(1, 1, 1) local scale = Vector(0.001, 0.001, 0.001) local bone = vm:LookupBone( "ValveBiped.Bip01_Spine4" ) local cur = vm:GetBoneParent(bone) while( cur >= 0 ) do local pscale = loopthrough[vm:GetBoneName(cur)].scale ms = ms * pscale cur = vm:GetBoneParent(cur) end scale = scale * ms vm:ManipulateBoneScale( bone, scale )[/lua]
His code doesn't make any sense to me, he has a workaround for bone scaling where he literally just loops through the parents of every bone and applies the scaling of the parent bones to their children So when i use his code it applies the same scaling to the entire viewmodel which isn't what i want at all [lua] local allbones = {} for i=0, vm:GetBoneCount() do local bonename = vm:GetBoneName( i ) if ( bonename == "ValveBiped.Bip01_Spine4" ) then allbones[bonename] = Vector(0.01, 0.09, 0.01) else allbones[bonename] = Vector(1,1,1) end end for k,v in pairs( allbones ) do local bone = vm:LookupBone( k ) if not bone then continue end local cur = vm:GetBoneParent( bone ) local ms = Vector(1, 1, 1) local scale = Vector(v.x, v.y, v.z) while( cur >= 0 ) do local pscale = allbones[ vm:GetBoneName( cur ) ] ms = ms * pscale cur = vm:GetBoneParent( cur ) end scale = scale * ms if vm:GetManipulateBoneScale(bone) != scale then vm:ManipulateBoneScale( bone, scale ) end end[/lua] Spine4 is the parent of every bone in the entire viewmodel so its scaling is applied to every other bone by his method, what i want is to scale only Spine4
Sorry, you need to Log In to post a reply to this thread.