• A networked int is somehow being changed. Any ideas?
    2 replies, posted
I'm making a reload function for a SWEP and want to make it so the reload process is stopped if the player switches weapons but for some reason the process continues in the background even if the player is on a different weapon. Here's the needed code. I have put print statements in for testing purposes and I will explain them more below. [lua] function SWEP:Reload() if self.Weapon:GetNetworkedBool( "reloading" ) then return end print("test1"..tostring(self.Weapon:GetNetworkedBool( "reloading" ))) if self.Weapon:Clip1() < self.Primary.ClipSize && self.Owner:GetAmmoCount( self.Primary.Ammo ) > 0 then if self.Weapon:GetNWInt( "zoomed" ) != 0 then self.Owner:SetFOV(0, 0.1) self.Weapon:SetNWInt( "zoomed", 0 ) end self.Weapon:SetNetworkedBool( "reloading", true ) self.Weapon:SendWeaponAnim( ACT_VM_RELOAD ) if true then // True for testing purposes self.Weapon:SetVar( "reloadtimer", CurTime() + 1.8 ) self.Owner:GetViewModel():SetPlaybackRate(2.0) else self.Weapon:SetVar( "reloadtimer", CurTime() + 3.6 ) end end print("test2"..tostring(self.Weapon:GetNetworkedBool( "reloading" ))) end // Checks to see if we are reloading and the reloadtimer is over. If so then it refills the clip and set reload bool to false. function SWEP:Think() print("testthink1"..tostring(self.Weapon:GetNetworkedBool( "reloading" ))) if self.Weapon:GetNetworkedBool( "reloading" ) && self.Weapon:GetVar( "reloadtimer", 0 ) < CurTime() then print("testthink"..tostring(self.Weapon:GetNetworkedBool( "reloading" ))) self.Weapon:SetClip1(self.Primary.ClipSize) self.Weapon:SetNetworkedBool( "reloading", false ) return end end // If weapon is holstered while reloading, stop the reloading process function SWEP:Holster() if self.Weapon:GetNetworkedBool( "reloading" ) then self.Weapon:SetNetworkedBool( "reloading", false ) print("testhol"..tostring(self.Weapon:GetNetworkedBool( "reloading" ))) end return true end function SWEP:Deploy() print("testdep"..tostring(self.Weapon:GetNetworkedBool( "reloading" ))) return true end [/lua] Here's what prints out in console when I switch weapons while reloading. testthink1true testthink1true testholfalse testthink1false testthink1false testdepfalse testdepfalse testdepfalse testdepfalse testdepfalse testthink1true testthinktrue testthink1false testthink1false The first 2 statements are while I'm in the reload process so true is correct, then I switch weapons which can be seen by the testhol(ster)false statement. This false is correct since Im holstering. The false is confirmed as the think statement ticked 2 more times before fully holstering. I then deploy the weapon and confirm the bool is still false. Then all of a sudden it is true and quickly goes back to false. I dont see any reason for it to become true. The only spot where I make the bool true is in the reload function and since the "test1" and "test2" statements weren't displayed I've confirmed that it isn't setting the bool to true.
Unrelated, but your use of self.Weapon irks me. self.Weapon is deprecated, like self.Entity, so just use self. Using self.Weapon just slows down your script a bit, as an extra indexing operation must be performed every time it's used.
Any ideas? I've trued a bunch of things and still no luck.,
Sorry, you need to Log In to post a reply to this thread.