• Question about SWEP: Texture returning to normal after weapon is put away.
    2 replies, posted
I am studying a piece of code from Tenteran. In the code, I want to know if I can reverse the effect of the swep when put away. Somehow I need to set 'self.conceal = false' when weapon is being put away. Anyone know how to do this? By the way to summerize the function of this swep, the rightclick button will enable invisiblity for the player and rightclick again is to set normal. [CODE]if( SERVER ) then AddCSLuaFile( "shared.lua" ); end if( CLIENT ) then SWEP.PrintName = "Predator's Cloak"; SWEP.Slot = 3; SWEP.SlotPos = 0; SWEP.DrawAmmo = false; SWEP.DrawCrosshair = false; end SWEP.Author = "Tenteran" SWEP.Instructions = "Left = Taunt right = Cloak/Uncloak" SWEP.Contact = "" SWEP.Purpose = "Like Predator" SWEP.Category = "Ostrich Industries"; SWEP.ViewModelFOV = 60 SWEP.ViewModelFlip = false SWEP.Spawnable = true SWEP.AdminSpawnable = true SWEP.ViewModel = "models/weapons/v_hands.mdl" SWEP.WorldModel = "" resource.AddFile( "invis/clicking.wav" ) -------------Primary Fire Attributes---------------------------------------- function SWEP:PrimaryAttack() self.Weapon:SetNextSecondaryFire( CurTime() + 1 ) local TauntSound = Sound( "invis/clicking.wav" ) self.Weapon:EmitSound( TauntSound ) // The rest is only done on the server if (!SERVER) then return end self.Weapon:EmitSound( TauntSound ) end -------------Secondary Fire Attributes------------------------------------- SWEP.Secondary.Delay = 0.5 SWEP.Secondary.Recoil = 0 SWEP.Secondary.Damage = 0 SWEP.Secondary.NumShots = 1 SWEP.Secondary.Cone = 0 SWEP.Secondary.ClipSize = -1 SWEP.Secondary.DefaultClip = -1 SWEP.Secondary.Automatic = false SWEP.Secondary.Ammo = "none" function SWEP:SecondaryAttack() // conceal yourself if ( !self.conceal ) then self.Owner:SetMaterial("models/effects/vol_light001") self.Weapon:SetMaterial("models/effects/vol_light001") self.Owner:PrintMessage( HUD_PRINTCENTER, "Cloak On" ) self.conceal = true else self.Owner:SetMaterial("models/glass") self.Weapon:SetMaterial("models/glass") self.Owner:PrintMessage( HUD_PRINTCENTER, "Cloak Off" ) self.conceal = false end end [/CODE]
Try these. [code] function SWEP:Holster() --Disables cloak if the swep is holstered if self.conceal then self.Owner:SetMaterial("models/glass") self.Weapon:SetMaterial("models/glass") self.Owner:PrintMessage( HUD_PRINTCENTER, "Cloak Off" ) self.conceal = false end end function SWEP:OnRemove() --Disables cloak if the swep is removed if self.conceal then self.Owner:SetMaterial("models/glass") self.Weapon:SetMaterial("models/glass") self.Owner:PrintMessage( HUD_PRINTCENTER, "Cloak Off" ) self.conceal = false end end function SWEP:OnDrop() --Disables cloak if the player drops the weapon if self.conceal then self.Owner:SetMaterial("models/glass") self.Weapon:SetMaterial("models/glass") self.Owner:PrintMessage( HUD_PRINTCENTER, "Cloak Off" ) self.conceal = false end end [/code]
Thank you, that's really simple and it does exactly what I wanted. Although I'm not sure why I cannot switch weapons after the swep is equipped. [editline]21st August 2013[/editline] I removed this, and now I can switch weapons. Thanks again, I really appreciate your help. [I]function SWEP:Holster()[/I] --Disables cloak if the swep is holstered
Sorry, you need to Log In to post a reply to this thread.