• How do I make this keypress toggle work?
    5 replies, posted
Ok, I have this code. The idea is when I hit Inset the crosshair toggles on / off. This is all I have so far and I'm a bit stuck, thanks in advance. open = true if input.IsKeyDown(KEY_INSERT) == true then open = false end if open == true then function Crosshair1() surface.SetDrawColor(team.GetColor(LocalPlayer():Team())) surface.DrawLine(ScrW() / 2 - 10, ScrH() / 2, ScrW() / 2 + 11 , ScrH() / 2) surface.DrawLine(ScrW() / 2 - 0, ScrH() / 2 - 10, ScrW() / 2 - 0 , ScrH() / 2 + 11) hook.Add("HUDPaint","CustomCross",Crosshair1) local function coordinates( ent ) local min, max = ent:OBBMins(), ent:OBBMaxs() local corners = {         Vector( min.x, min.y, min.z ),         Vector( min.x, min.y, max.z ),         Vector( min.x, max.y, min.z ),         Vector( min.x, max.y, max.z ),         Vector( max.x, min.y, min.z ),         Vector( max.x, min.y, max.z ),         Vector( max.x, max.y, min.z ),         Vector( max.x, max.y, max.z ) }   local minX, minY, maxX, maxY = ScrW() * 2, ScrH() * 2, 0, 0 for _, corner in pairs( corners ) do         local onScreen = ent:LocalToWorld( corner ):ToScreen()         minX, minY = math.min( minX, onScreen.x ), math.min( minY, onScreen.y )         maxX, maxY = math.max( maxX, onScreen.x ), math.max( maxY, onScreen.y ) end   return minX, minY, maxX, maxY end end end
Off-topic: You should wrap your code in the code tags for readability. On-topic: Move this part of your code to be inside of the Crosshair1 function if input.IsKeyDown(KEY_INSERT) == true then open = false end if open == true then Then move this portion to be outside of the Crosshair1 function hook.Add("HUDPaint","CustomCross",Crosshair1) local function coordinates( ent )         local min, max = ent:OBBMins(), ent:OBBMaxs()         local corners = {                 Vector( min.x, min.y, min.z ),                 Vector( min.x, min.y, max.z ),                 Vector( min.x, max.y, min.z ),                 Vector( min.x, max.y, max.z ),                 Vector( max.x, min.y, min.z ),                 Vector( max.x, min.y, max.z ),                 Vector( max.x, max.y, min.z ),                 Vector( max.x, max.y, max.z )         }                   local minX, minY, maxX, maxY = ScrW() * 2, ScrH() * 2, 0, 0         for _, corner in pairs( corners ) do                 local onScreen = ent:LocalToWorld( corner ):ToScreen()                 minX, minY = math.min( minX, onScreen.x ), math.min( minY, onScreen.y )                 maxX, maxY = math.max( maxX, onScreen.x ), math.max( maxY, onScreen.y )         end                   return minX, minY, maxX, maxY end Otherwise you're adding the HUDPaint hook and redefining that function every HUDPaint tick.
Sorry, I'm new to all of this, but still, could you help answer my question?
local KeyDown = false local function KeyToggle()     if (input.IsButtonDown(KEY_INSERT)) then         if not (KeyDown) then             -- toggled         end         KeyDown = true     else         KeyDown = false     end end Call KeyToggle in a Think hook.
Sorry but how do I format this? The code thing seems to mess it up for me. Also, where do I paste it in? The code box seems to mess it up for me.
I'm not sure how to format that code for the toggle
Sorry, you need to Log In to post a reply to this thread.