Results 1 to 2 of 2
  1. #1
    BigBlackCJ's Avatar
    Join Date
    Feb 2018
    Gender
    male
    Posts
    9
    Reputation
    10
    Thanks
    0

    Post Can someone help me optimize this ESP?

    Hi, I pasted an ESP and edited it a bit. It works fine on singleplayer with a few bots, but when you go to multiplayer it becomes insanely laggy. Any ideas on how to reduce the lag?

    [SPOILER]
    Code:
    --LIFE CHECK [ESP]
    local function MESPCheck(v)
    	if v:Alive() == true && v:Health() ~= 0 && v:Health() >= 0 && v ~= LocalPlayer() && LocalPlayer():Alive() then
    		return true
    	else
    		return false
    	end
    end
    
    
    -- NAME / ARMOUR / HP
    local check_key, do_draw_esp = false
    
    local function check_ins()
         local key_down = input.IsKeyDown( KEY_INSERT )
        if key_down and !check_key then
            check_key = true
            do_draw_esp = !do_draw_esp
        elseif !key_down and check_key then
            check_key = false
        end
    end
    
    local function draw_esp()
        if ( not do_draw_esp )
    	then
        for k, v in pairs( player.GetAll() ) do
            if ( v == LocalPlayer() ) then continue end
            
            local pos = ( v:GetPos() + Vector( 0, 0, 80 ) ):ToScreen()
    
    		draw.SimpleText( v:Health(), "DebugFixedSmall", pos.x, pos.y - 5, Color( 255, 0, 200 ), 1, 1, 2, Color( 0, 0, 0, 255 ) )
            draw.SimpleText( v:Nick(), "DebugFixedSmall", pos.x, pos.y - 20, Color( 255, 0, 200 ), 1, 1, 2, Color( 0, 0, 0, 255 ) )
        end
    	end
    end
    
    local function drawing_hook() 
        check_ins()
        draw_esp()
    end
    
    hook.Add( "HUDPaint", "", drawing_hook )
     
     
     -- CUSTOM CROSSHAIR
    local shouldDraw = true
     
    local hzCross = CreateClientConVar("HZ_Crosshair","0",false)
     
    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)
    end
    
    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
    hook.Add("HUDPaint", "Example", function()
    for k,v in pairs(player.GetAll()) do
            local x1,y1,x2,y2 = coordinates(v)
             print(tostring(team.GetColor(v:Team())))
             surface.SetDrawColor(255, 0, 200)
     
    check_ins()
    draw_esp()
        if ( not do_draw_esp )
    	then
            surface.DrawLine( x1, y1, math.min( x1 + 100, x2 ), y1 )
            surface.DrawLine( x1, y1, x1, math.min( y1 + 200, y2 ) )
     
     
            surface.DrawLine( x2, y1, math.max( x2 - 100, x1 ), y1 )
            surface.DrawLine( x2, y1, x2, math.min( y1 + 200, y2 ) )
     
     
            surface.DrawLine( x1, y2, math.min( x1 + 100, x2 ), y2 )
            surface.DrawLine( x1, y2, x1, math.max( y2 - 200, y1 ) )
     
     
            surface.DrawLine( x2, y2, math.max( x2 - 100, x1 ), y2 )
            surface.DrawLine( x2, y2, x2, math.max( y2 - 200, y1 ) )
    end
    end
    end)
    [/SPOILER]

  2. #2
    guessjoe1's Avatar
    Join Date
    Aug 2014
    Gender
    male
    Posts
    58
    Reputation
    10
    Thanks
    4
    My Mood
    Bored
    Imagine this.
    1 drawing hook while looping ~12 players.

    Now you're adding more of the same hook and looping all the players again.

    5 drawing hooks * 12 players = big cpu power drain...

    TL : DR
    Hook on the drawing hook once and do all the drawing within that one hook.

Similar Threads

  1. [Help] can someone help me combine this box esp inot the glow esp source
    By yiz34382 in forum Counter-Strike 2 Coding & Resources
    Replies: 0
    Last Post: 12-14-2017, 02:12 PM
  2. [Help Request] [AS3] Can someone help me with this please?
    By ChickaBooka in forum Realm of the Mad God Private Servers Help
    Replies: 6
    Last Post: 12-03-2017, 02:06 AM
  3. [Help Request] can someone help me fix this error
    By Killergard in forum Realm of the Mad God Private Servers Help
    Replies: 2
    Last Post: 09-12-2014, 10:19 AM
  4. [Help Request] can someone help me with this error
    By Killergard in forum Realm of the Mad God Private Servers Help
    Replies: 1
    Last Post: 08-30-2014, 12:27 PM
  5. [Help Request] Can someone help me with this code
    By L33tHaxorCod3r in forum Minecraft Help
    Replies: 3
    Last Post: 07-16-2012, 11:48 AM