How do I make my player re-appear if he changes weapon?
8 replies, posted
Hello, I am creating an invisiblity Cloak SWEP. So far all it does is sets the player invisible and secondary makes it re-appear. But I would like to make it so if the player changes weapon it would make the player re-appear to stop any exploits.
SWEP.PrintName = "Invisibility Cloak SWEP"
SWEP.Author = "Ryanm2711"
SWEP.Instructions = "Press Left Click to go invisible. Right click to get out."
SWEP.Spawnable = true
SWEP.AdminOnly = true
SWEP.Category = "HogwartsRP"
SWEP.Primary.ClipSize = -1
SWEP.Primary.DefaultClip = -1
SWEP.Primary.Automatic = false
SWEP.Primary.Ammo = "none"
SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = false
SWEP.Secondary.Ammo = "none"
SWEP.Weight = 0
SWEP.AutoSwitchTo = true
SWEP.AutoSwitchFrom = false
SWEP.Slot = 1
SWEP.SlotPos = 2
SWEP.DrawAmmo = false
SWEP.DrawCrosshair = false
function SWEP:Deploy()
self.Owner:DrawViewModel(false);
end
function SWEP:DrawWorldModel() return false; end
function SWEP:PrimaryAttack()
self:SetNextPrimaryFire( CurTime() + 5 )
self.Owner:SetRenderMode(RENDERMODE_TRANSALPHA)
self.Owner:SetColor( Color(0, 0, 0, 0 ) )
end
function SWEP:SecondaryAttack()
self.Owner:SetRenderMode( RENDERMODE_TRANSALPHA )
self.Owner:SetColor(Color(255,255,255,255))
end
probably something like this
function SWEP:Holster( wep )
self.Owner:SetRenderMode(RENDERMODE_TRANSALPHA)
self.Owner:SetColor( Color(0, 0, 0, 0 ) )
end
But this is just going from the wiki entry. But take a good look at the wiki entry, since you're probably more familiar with lua than I.
would probably just be a quick edit
self.Owner:SetColor( Color(255, 255, 255, 255 ) )
since the secondary is what makes them re-appear
ah fudge, i knew i copied the wrong section of code 😋
Thanks, it worked.
The first snippet with SWEP:Holster was actually good, except it didn't return true. If you don't return true, it won't allow the weapon to be changed.
function SWEP:Holster( wep )
self.Owner:SetRenderMode(RENDERMODE_TRANSALPHA)
self.Owner:SetColor( Color(255, 255, 255, 255) )
return true -- you need to return true to allow holstering
end
Try this, it should work.
I did try return true. That did not work, so I used the other method that works fine.
That's strange. I copied the exact code submitted, added my snippet and it worked flawlessly.
Oh well, at least I got it working in the end.
Sorry, you need to Log In to post a reply to this thread.