• SWEP Ironsights Bug
    8 replies, posted
So, I'm creating a SWEP. I have the following code: [code] .. SWEP.ViewModel = "models/weapons/thanez_ak/v_rif_ak47.mdl" .. SWEP.IronSightsPos = Vector(5, 5, 5) -- just for tests SWEP.IronSightsAng = Angle(5, 5, 5) -- just for tests .. function SWEP:SecondaryAttack() if (CLIENT) then self:CalcViewModelView(self.ViewModel, Vector(0, 0, 0), Angle(0, 0, 0), self.IronSightsPos, self.IronSightsAng) end end .. [/code] The viewmodel doesn't even change. I have no clue what I'm doing wrong, as there are no errors. If you guys can help me, I'd really appreciate it! Thanks :) PS - My base is weapon_base.
You don't call the function, you have to overwrite it. So something like: [code] function SWEP:CalcViewModelView( ... args ... ) if PLAYER_IS_IRONSIGHTING then return ironsightargs else return defaultargs end end [/code] Also remember this function is CLIENTSIDE, so make sure to plop it in the cl_init equivalent or make a condition that it's being created clientside
[QUOTE=solid_jake;52109111]You don't call the function, you have to overwrite it. So something like: [code] function SWEP:CalcViewModelView( ... args ... ) if PLAYER_IS_IRONSIGHTING then return ironsightargs else return defaultargs end end [/code] Also remember this function is CLIENTSIDE, so make sure to plop it in the cl_init equivalent or make a condition that it's being created clientside[/QUOTE] Hmm, I have the following: [code] .. SWEP.ViewModel = "models/weapons/thanez_ak/v_rif_ak47.mdl" .. SWEP.IronSightsPos = Vector(5, 5, 5) -- just for tests SWEP.IronSightsAng = Angle(5, 5, 5) -- just for tests .. local isAiming function SWEP:SecondaryAttack() isAiming = true end if (CLIENT) then function SWEP:CalcViewModelView(vm, oldpos, oldang, pos, ang) if isAiming then pos = self.IronSightsPos ang = self.IronSightsAng else pos = oldpos ang = oldang end vm = self.ViewModel oldpos = Vector(0, 0, 0) oldang = Angle(0, 0, 0) return end end .. [/code] Also tried [code] .. return vm, oldpos, oldang, pos, ang .. [/code] Still no errors
Remember you have to [I]return[/I] something my man [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/WEAPON/CalcViewModelView]SWEP:CalcViewModelView[/url] You'll see what it wants there. You don't need to change the position or anything like that, just return new ones. Also you don't need that vm = self.ViewModel. The arguements of the function already have that figured out That wiki page should answer your questions
[QUOTE=solid_jake;52109253]Remember you have to [I]return[/I] something my man [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/WEAPON/CalcViewModelView]SWEP:CalcViewModelView[/url] You'll see what it wants there. You don't need to change the position or anything like that, just return new ones. Also you don't need that vm = self.ViewModel. The arguements of the function already have that figured out That wiki page should answer your questions[/QUOTE] [code] if (CLIENT) then function SWEP:CalcViewModelView(vm, oldpos, oldang, pos, ang) pos = self.IronSightsPos ang = self.IronSightsAng if isAiming then return pos, ang end return end end [/code] Sorry, man... I'm fairly new to Lua... This still isn't working for some reason. Also - I tried to add "print(isAiming)", and it is returning nil. Even when I do SecondaryAttack(). This is probably a part of the problem
The only rule was you have to return something and I told you not to change positions, only make return new ones. You gotta read the text dude
[QUOTE=solid_jake;52109923]The only rule was you have to return something and I told you not to change positions, only make return new ones. You gotta read the text dude[/QUOTE] I did exactly what you told me to do: [code] local isAiming = false function SWEP:SecondaryAttack() isAiming = true end if (CLIENT) then function SWEP:CalcViewModelView(vm, oldpos, oldang, pos, ang) if isAiming then return self.IronSightsPos, self.IronSightsAng else return oldpos, oldang end end end [/code] Still nothing
Let me see the rest of the code.. and this is going into shared.lua?
[QUOTE=solid_jake;52110063]Let me see the rest of the code.. and this is going into shared.lua?[/QUOTE] Yup, [url]https://pastebin.com/raw/07TQtYXF[/url]
Sorry, you need to Log In to post a reply to this thread.