Viewmodel bobbing up and down

Hey. I’m relatively new to Lua. Now, what I want to do is make a weapon’s view model bob up and down when it’s idle. When I asked a good friend of mine, he gave me this code to use as a reference:

ang = cmovedata:GetViewAngles()
ang.p = ang.p - math.cos( CurTime() * 1.25 ) * 0.003


You can obviously tell that this is meant for a CreateMove hook(makes your view bob up and down when used). How would I use a similar method to make a viewmodel bob up and down in a GetViewModelPosition function?