How to slide an object? Or send it to position?

  • #10, by afrlmeSunday, 23. September 2018, 15:01 6 years ago
    I´m not sure about this but wouldn´t this register the draw function again and again? Since the draw function is called every frame this would get very expensive soon wink
    It doesn't really matter, you are just replacing the draw function inside of the table, but you can create the function that registers the draw function outside of the loop.

    Something along the lines of this...
    local health
    graphics.addDrawFunc("draw()", 0)
    
    function drawHealthBar()
     health = (Values["MC_health"].Int / 100) * 300
     -- + --
     function draw() graphics.drawBox(200, 200, health, 40, 0x0000ff, 1) end
    end
    
    registerEventHandler("mainLoop", "drawHealthBar")


    Imperator

    7278 Posts


  • #11, by nerdSunday, 23. September 2018, 15:36 6 years ago
    I´m not sure about this but wouldn´t this register the draw function again and again? Since the draw function is called every frame this would get very expensive soon wink
    It doesn't really matter, you are just replacing the draw function inside of the table, but you can create the function that registers the draw function outside of the loop.

    Something along the lines of this...
    local health
    graphics.addDrawFunc("draw()", 0)
    
    function drawHealthBar()
     health = (Values["MC_health"].Int / 100) * 300
     -- + --
     function draw() graphics.drawBox(200, 200, health, 40, 0x0000ff, 1) end
    end
    
    registerEventHandler("mainLoop", "drawHealthBar")



    Thank you, it works. I've just added "if mc health < 0 set it to 0" through visual scripting and that's it here it is a wonderfull healthbar!

    Forum Fan

    147 Posts

  • #12, by afrlmeSunday, 23. September 2018, 15:46 6 years ago
    No worries. wink

    Imperator

    7278 Posts