Menu
Login
Language
DE EN FR ES IT CZ
Back

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

  • #10, by afrlme Sunday, 23. September 2018, 15:01 7 years ago Quote
    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

    7290 Posts

  • #11, by nerd Sunday, 23. September 2018, 15:36 7 years ago Quote
    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 afrlme Sunday, 23. September 2018, 15:46 7 years ago Quote
    No worries. wink

    Imperator

    7290 Posts