• Can I use the reload key for ironsights?
    4 replies, posted
I'm working on a hand-to-hand combat SWEP, and both mouse buttons are used for attacks. I was trying to add a blocking mechanic by using ironsights to move the fists up, and also reduce the damage the player takes. I saw this in another SWEP I was using as a reference (minus the SWEP:Reload part), but when I added it to mine, nothing happened when I pressed reload. [lua]function SWEP:Reload() if ( self.Weapon:GetNetworkedBool( "Ironsights" ) == b ) then return end self.Weapon:SetNetworkedBool( "Ironsights", b ) end[/lua] Is this possible, and if so what do I have to do to make it work?
Anybody want to explain why this was rated dumb? I thought this section was "A place for you to ask all your questions."
There's some little kid in serious need of puberty running around rating everything dumb. Just ignore him. As for your problem, I'm not too familiar with the code, myself, but try this: [lua] function SWEP:Reload() if ( !self.IronSightsPos ) then return end if ( self.NextSecondaryAttack > CurTime() ) then return end bIronsights = !self.Weapon:GetNetworkedBool( "Ironsights", false ) self:SetIronsights( bIronsights ) self.NextSecondaryAttack = CurTime() + 0.3 end [/lua] This should let Reload toggle Ironsights for you. I'm afraid I can't explain what exactly is going on in there, so good luck making it work how you want it to.
That didn't work. Now when I press reload, I get an error at the top right saying "weapons/h2hhand/shared.lua:275: attempt to compare number with nil." I don't know much about lua, but I'm assuming it means there's an error on line 275, which would be "if ( self.NextSecondaryAttack > CurTime() ) then return end."
Well, the only possible thing that could be wrong with that line is if self.NextSecondaryAttack didn't equal anything (equaling nothing, not even zero, is called "nil"). That means that all you need to do to fix that is to make it equal something. Try putting this line in your SWEP:Initialize() SWEP.NextSecondaryAttack = 0
Sorry, you need to Log In to post a reply to this thread.