• KeyPressed and KeyReleased
    2 replies, posted
I have an entity that has 3d2d text, what I'm trying to do is when you release your use key from it the text disappears. I used networkedvar btw. It works when you first press E on it but after releasing the key, the text doesnt disappear. [CODE]function ENT:Initialize() --INIT-- self:SetModel("models/props/de_nuke/crate_extrasmall.mdl") self:PhysicsInit(SOLID_VPHYSICS) self:SetMoveType(MOVETYPE_VPHYSICS) self:SetSolid(SOLID_VPHYSICS) self:SetPressing(false) self:SetUseType(CONTINUOUS_USE) local phys = self:GetPhysicsObject() if phys:IsValid() then phys:Wake() end end function ENT:Use(activator,caller) if caller:KeyPressed(IN_USE) then self:SetPressing(true) elseif caller:KeyReleased(IN_USE) then self:SetPressing(false) end end [/CODE] [CODE] --CLIENT THIS IS BEING USED IN ENT:DRAW-- cam.Start3D2D(poss+offsets,angss,0.15) if self:GetPressing() == true then width = Lerp(FrameTime()*1,width,100) surface.SetDrawColor(0,0,0,mainss) surface.DrawOutlinedRect(-51,-451,102,32) draw.RoundedBox(0,-50,-450,width,30,Color(230,10,30,mainss)) elseif self:GetPressing() == false then draw.SimpleTextOutlined("FALSE","NewFontsz",0,-500,Color(255,255,255,mainss), TEXT_ALIGN_CENTER,0,2,Color(0,0,0,mainss)) end cam.End3D2D()[/CODE]
Well if you don't really need any of the serversided, why not just do it all clientside? Wrap that whole cam.Start3D2D statement in [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/input/IsKeyDown]input.IsKeyDown[/url] (Probably a trace check too) To answer your question, what you're doing won't work because :Use doesn't get called UNTIL the key is pressed down. (not when the key is released)
[QUOTE=kpjVideo;52629541] what you're doing won't work because :Use doesn't get called UNTIL the key is pressed down. (not when the key is released)[/QUOTE] yeah oops, didn't think of that. Ill try doing it all clientside then [editline]30th August 2017[/editline] [CODE] if tr.Entity.PrintName == "Crate" and input.IsKeyDown(IN_USE) then print("yes") width = Lerp(FrameTime()*1,width,100) surface.SetDrawColor(0,0,0,mainss) surface.DrawOutlinedRect(-51,-451,102,32) draw.RoundedBox(0,-50,-450,width,30,Color(230,10,30,mainss)) else draw.SimpleTextOutlined("NOT PRESSING","NewFontsz",0,-450,Color(255,255,255,mainss), TEXT_ALIGN_CENTER,0,2,Color(0,0,0,mainss)) end[/CODE] Currently that only shows the not pressing text, it never prints yes or does the other 3d2d. Anything I missed? Oops it should be KEY_E not IN_USE my bad. Thanks a lot buddy!
Sorry, you need to Log In to post a reply to this thread.