Jump to content

drawing same image multiple times on different pos


John Smith

Recommended Posts

i would like to do something like a hud with advanced health or whatever bar

so lets say one green little line is in an image of size 16x16 pixels

i got a basic example how i would make this

local sw,sh = guiGetScreenSize() 
function drawPlayerHealth() 
local pHealth = getElementHealth(localPlayer) 
for i = tonumber(pHealth) do 
dxDrawImage(sw/2,sh/2,16,16,"test.png") 
end 
end 
addEventHandler("onClientRender",root,drawPlayerHealth) 

it would probably draw the required number of images for my health depending on my health points in a number

however all of those images would be on same spot

how could i move them depending on how much images are there?

Link to comment

Your code should be:

  
local sw,sh = guiGetScreenSize() 
function drawPlayerHealth() 
    local pHealth = getElementHealth(localPlayer) -- get player health 
    for i=0,tonumber(pHealth/22) do -- Math.. 
        if pHealth > 50 then -- Check the player's health is < 50 to create the green images 
            dxDrawImage(sw/2,(sh/2)+i*10,5,5,"b.png") -- I added i*10 to make space in between the images 
        else -- the player's health is > 50 create the red images 
            dxDrawImage(sw/2,(sh/2)+i*10,5,5,"a.png") -- I added i*10 to make space in between the images 
        end 
    end 
end 
addEventHandler("onClientRender",root,drawPlayerHealth) 
  

I explained using comments, just edit the X,Y for the position you'd like.

PS: I used these two images:

Red: http://i.cubeupload.com/oS8w0m.png

Green: http://i.cubeupload.com/5HJiN9.png

Edited by Guest
Link to comment

aboudmad, nice bicycle...

John Smith, try this, with comments, don't need image for static color, really! Just edit!

  
-- Resolution 
local ScreenX, ScreenY = guiGetScreenSize() 
-- Render coordinats (where we wil render out rectangle) 
local X, Y = ScreenX/2, ScreenY/2 
-- Rectangle width and height for ONE unit, just write, what you want, again... 
local RectangleWidth, RectangleHeight = 5, 5 
-- Color for green HP, you can edit! 
local ColorGreen = tocolor ( 0, 255, 0, 255 ) 
-- Color for yellow HP, you can edit! 
local ColorYellow = tocolor ( 255, 255, 0, 255 ) 
-- Color for red HP, you can edit! 
local ColorRed= tocolor ( 255, 0, 0, 255 ) 
  
function RenderHealth() 
     local Health = getElementHealth ( localPlayer ) 
     -- Total Rectangle width 
     -- I dont change height of recntagle, you can to do it! 
     local TottalWidth = RectangleWidth * Health 
     -- Draw our recntagle 
     if Health > 66 then 
          dxDrawRectangle ( X, Y, TottalWidth, RectangleHeight, ColorGreen ) 
     elseif Health > 33 then 
          dxDrawRectangle ( X, Y, TottalWidth, RectangleHeight, ColorYellow ) 
     else 
          dxDrawRectangle ( X, Y, TottalWidth, RectangleHeight, ColorRed) 
     end 
end 
  

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...