• How can i test if a player is crouching
    6 replies, posted
Basically what i want to do is make a SWEP Knife that works like the css knife but when you crouch your material is set to the predator one and the player is set to 50% alpha i can do the colour and material i just dont know how to make the weapon know if your croutching Can this be done?
[lua]function SWEP:Think() if self.Owner:Crouching() == true then self.Owner:SetColor(255,255,255,255/2) self.Owner:SetMaterial("predatormaterial.vtf") end end[/lua] Something like that.
exactly that thanks! i just found [url]http://wiki.garrysmod.com/?title=Player.Crouching[/url] not sure if this is the same but thanks!
[QUOTE=Virus78;16582133]exactly that thanks! i just found [url]http://wiki.garrysmod.com/?title=Player.Crouching[/url] not sure if this is the same but thanks![/QUOTE] It is the same.
Ok thanks i finished the SWEP but framerates drop to about 15-20 fps when you croutch any idea why this is happening? EDIT:- Ok i fixed the framerates it turned out i put the path in wrong ok now the problem is that when you die or if your not croutching / have the wepon equipped you stay stuck with the material and colour how can i reset the defualt material if the croutching return false [lua] function SWEP:Think() if self.Owner:Crouching() == false then self.Owner:SetColor(255,255,255,255) --What do i do to this? self.Owner:SetMaterial("models/shadertest/predator") end end [/lua] EDIT:- Worked it out i just leave it as "" now the only problem is if your coutching but not holding the knife this is my code at the moment [lua] function SWEP:Think() if self.Owner:Crouching() == true then self.Owner:SetColor(255,255,255,255/2) self.Owner:SetMaterial("models/shadertest/predator") else self.Owner:SetColor(255,255,255,255) self.Owner:SetMaterial("") end end [/lua]
Umm, try this: [lua]function SWEP:Think() if self.Owner:GetActiveWeapon():GetClass() == "weapon_predknife" then if self.Owner:Crouching() == true then self.Owner:SetColor(255,255,255,255/2) self.Owner:SetMaterial("models/shadertest/predator") else self.Owner:SetColor(255,255,255,255) self.Owner:SetMaterial("") end end end[/lua] Just substitute "weapon_predknife" with the classname.
yea that worked thanks is there a way i can make you jump higher aswell if your holding it? but not using gravity because i would want it to jump just as fast and fall just as fast maybe like 4 times the regular jump height EDIT:- Found SetJumpPower my swep is now finished :D EDIT2:- Would this work [lua] function SWEP:Think() if self.Owner:GetActiveWeapon():GetClass() == "weapon_asblade" then if self.Owner:KeyDown( IN_SPEED ) then self.Owner:SetJumpPower( 560 ) else self.Owner:SetJumpPower( 160 ) end end end [/lua]
Sorry, you need to Log In to post a reply to this thread.