Jump to content

destroyElement [LAG]


Gallagher

Recommended Posts

because DestroyElement cause lag?

Is there any way to replace DestroyElement by alpha?

---- 
    dxDrawImage(screenWidth * 0.94, screenHeight * 0.7, screenHeight * 0.065, screenHeight * 0.065, "images/dayzicons/temperature.png", 0, 0, 0, tocolor(0, 255, 0)) 
    if getElementData(getLocalPlayer(), "temperature") > 36.8 then 
    destroyElement(elementtemp4) 
    destroyElement(elementtemp3) 
    destroyElement(elementtemp1) 
    destroyElement(elementtemp2) 
    destroyElement(elementtemp5) 
    destroyElement(elementtemp) 
    elementtemp1 = dxDrawImage(screenWidth * 0.94, screenHeight * 0.7, screenHeight * 0.065, screenHeight * 0.065, "images/hud/temp/37.png", 0, 0, 0, tocolor(0, 255, 0)) 
    end 
    if getElementData(getLocalPlayer(), "temperature") > 36 then 
    destroyElement(elementtemp4) 
    destroyElement(elementtemp3) 
    destroyElement(elementtemp1) 
    destroyElement(elementtemp2) 
    destroyElement(elementtemp5) 
    destroyElement(elementtemp) 
    elementtemp2 = dxDrawImage(screenWidth * 0.94, screenHeight * 0.7, screenHeight * 0.065, screenHeight * 0.065, "images/hud/temp/36.png", 0, 0, 0, tocolor(0, 255, 0)) 
    end 
    if getElementData(getLocalPlayer(), "temperature") > 34 then 
    destroyElement(elementtemp4) 
    destroyElement(elementtemp3) 
    destroyElement(elementtemp1) 
    destroyElement(elementtemp2) 
    destroyElement(elementtemp5) 
    destroyElement(elementtemp) 
    elementtemp4 = dxDrawImage(screenWidth * 0.94, screenHeight * 0.7, screenHeight * 0.065, screenHeight * 0.065, "images/hud/temp/34.png", 0, 0, 0, tocolor(0, 255, 0)) 
    end 
    if getElementData(getLocalPlayer(), "temperature") > 32 then 
    destroyElement(elementtemp4) 
    destroyElement(elementtemp3) 
    destroyElement(elementtemp1) 
    destroyElement(elementtemp2) 
    destroyElement(elementtemp5) 
    destroyElement(elementtemp) 
    elementtemp5 = dxDrawImage(screenWidth * 0.94, screenHeight * 0.7, screenHeight * 0.065, screenHeight * 0.065, "images/hud/temp/32.png", 0, 0, 0, tocolor(0, 255, 0)) 
    end 
    if getElementData(getLocalPlayer(), "temperature") > 30 then 
    destroyElement(elementtemp4) 
    destroyElement(elementtemp3) 
    destroyElement(elementtemp1) 
    destroyElement(elementtemp2) 
    destroyElement(elementtemp5) 
    destroyElement(elementtemp) 
    elementtemp = dxDrawImage(screenWidth * 0.94, screenHeight * 0.7, screenHeight * 0.065, screenHeight * 0.065, "images/hud/temp/30.png", 0, 0, 0, tocolor(0, 255, 0)) 
    end 
    ------------------------------- 

Link to comment

DX is not element

    x, y, w, h = screenWidth * 0.94, screenHeight * 0.7, screenHeight * 0.065, screenHeight * 0.065 
    dxDrawImage(x, y, w, h, "images/dayzicons/temperature.png", 0, 0, 0, tocolor(0, 255, 0)) 
    if getElementData(getLocalPlayer(), "temperature") > 36.8 then 
        image =  "images/hud/temp/37.png" 
    elseif getElementData(getLocalPlayer(), "temperature") > 36 then 
        image =  "images/hud/temp/36.png" 
    elseif getElementData(getLocalPlayer(), "temperature") > 34 then 
        image =  "images/hud/temp/34.png" 
    elseif getElementData(getLocalPlayer(), "temperature") > 32 then 
        image =  "images/hud/temp/32.png" 
    elseif getElementData(getLocalPlayer(), "temperature") > 30 then 
        image =  "images/hud/temp/30.png" 
    end 
    if image then dxDrawImage(x, y, w, h, image, 0, 0, 0, tocolor(0, 255, 0)) end 

Link to comment
DX is not element
    x, y, w, h = screenWidth * 0.94, screenHeight * 0.7, screenHeight * 0.065, screenHeight * 0.065 
    dxDrawImage(x, y, w, h, "images/dayzicons/temperature.png", 0, 0, 0, tocolor(0, 255, 0)) 
    if getElementData(getLocalPlayer(), "temperature") > 36.8 then 
        image =  "images/hud/temp/37.png" 
    elseif getElementData(getLocalPlayer(), "temperature") > 36 then 
        image =  "images/hud/temp/36.png" 
    elseif getElementData(getLocalPlayer(), "temperature") > 34 then 
        image =  "images/hud/temp/34.png" 
    elseif getElementData(getLocalPlayer(), "temperature") > 32 then 
        image =  "images/hud/temp/32.png" 
    elseif getElementData(getLocalPlayer(), "temperature") > 30 then 
        image =  "images/hud/temp/30.png" 
    end 
    if image then dxDrawImage(x, y, w, h, image, 0, 0, 0, tocolor(0, 255, 0)) end 

then how does it work?

Link to comment
local x, y, w, h, image = 0, 0, 150, 50, "image.png" 
function drawImage() 
     dxDrawImage(x, y, w, h, image) 
end 
  
addEventHandler("onClientRender", root, drawImage) 
  
setTimer(function() 
     removeEventHandler("onClientRender", root, drawImage) 
end, 15000, 1)-- Stops rendering the image after 15000 ms (15 sec)  

Link to comment

this script makes it the green hud the right corner.

https://fbcdn-sphotos-e-a.akamaihd.net/ ... 0772_n.jpg

but it causes fps drop - lag

how to make it not lag?

function updateIcons() 
  if getElementData(getLocalPlayer(), "logedin") then
    if fading >= 0 and fading2 == "up" then
      fading = fading + 5
    elseif fading <= 255 and fading2 == "down" then
      fading = fading - 5
    end
    if fading == 0 then
      fading2 = "up"
    elseif fading == 255 then
      fading2 = "down"
    end
    dxDrawImage(screenWidth * 0.9325, screenHeight * 0.41, screenHeight * 0.075, screenHeight * 0.075, "images/dayzicons/sound.png", 0, 0, 0, tocolor(0, 255, 0))
    local sound = getElementData(getLocalPlayer(), "volume") / 20
    if sound > 1 then
      dxDrawImage(screenWidth * 0.9075, screenHeight * 0.41, screenHeight * 0.075, screenHeight * 0.075, "images/dayzicons/level_" .. sound .. ".png", 0, 0, 0, tocolor(0, 255, 0))
    end
    dxDrawImage(screenWidth * 0.9325, screenHeight * 0.475, screenHeight * 0.075, screenHeight * 0.075, "images/dayzicons/eye.png", 0, 0, 0, tocolor(0, 255, 0))
    local sound = getElementData(getLocalPlayer(), "visibly") / 20
    if sound > 1 then
      dxDrawImage(screenWidth * 0.9075, screenHeight * 0.475, screenHeight * 0.075, screenHeight * 0.075, "images/dayzicons/level_" .. sound .. ".png", 0, 0, 0, tocolor(0, 255, 0))
    end
    if getElementData(getLocalPlayer(), "") then
      dxDrawImage(screenWidth * 0.9375, screenHbrokenboneeight * 0.55, screenHeight * 0.065, screenHeight * 0.065, "images/dayzicons/brokenbone.png", 0, 0, 0, tocolor(255, 255, 255))
    end
    ------------------------------- HUMANIDADE
   
    if getElementData(getLocalPlayer(), "humanity") <= 5000 then
    destroyElement(maconha2)
    destroyElement(maconha1)
    maconha3 = dxDrawImage(screenWidth * 0.925, screenHeight * 0.6, screenHeight * 0.1, screenHeight * 0.1, "images/dayzicons/5000.png", 0, 0, 0, tocolor(0, 255, 0))
    end
   
    if getElementData(getLocalPlayer(), "humanity") > 500 then
    destroyElement(maconha2)
    destroyElement(maconha3)
    maconha1 = dxDrawImage(screenWidth * 0.925, screenHeight * 0.6, screenHeight * 0.1, screenHeight * 0.1, "images/dayzicons/bandit.png", 0, 0, 0, tocolor(0, 255, 0))
    else
    destroyElement(maconha1)
    destroyElement(maconha3)
    maconha2 = dxDrawImage(screenWidth * 0.925, screenHeight * 0.6, screenHeight * 0.1, screenHeight * 0.1, "images/hud/human/n2500.png", 0, 0, 0, tocolor(0, 255, 0))
    end
   
    ------------------------------- HUMANIDADE
   
    ------------------------------- TEMPERATURA
    dxDrawImage(screenWidth * 0.94, screenHeight * 0.7, screenHeight * 0.065, screenHeight * 0.065, "images/dayzicons/temperature.png", 0, 0, 0, tocolor(0, 255, 0))
    if getElementData(getLocalPlayer(), "temperature") > 37 then
    destroyElement(elementtemp4)
    destroyElement(elementtemp3)
    destroyElement(elementtemp1)
    destroyElement(elementtemp2)
    destroyElement(elementtemp)
    elementtemp1 = dxDrawImage(screenWidth * 0.94, screenHeight * 0.7, screenHeight * 0.065, screenHeight * 0.065, "images/hud/temp/37.png", 0, 0, 0, tocolor(0, 255, 0))
    end
    if getElementData(getLocalPlayer(), "temperature") > 36 then
    destroyElement(elementtemp4)
    destroyElement(elementtemp3)
    destroyElement(elementtemp1)
    destroyElement(elementtemp2)
    destroyElement(elementtemp)
    elementtemp2 = dxDrawImage(screenWidth * 0.94, screenHeight * 0.7, screenHeight * 0.065, screenHeight * 0.065, "images/hud/temp/36.png", 0, 0, 0, tocolor(0, 255, 0))
    end
    if getElementData(getLocalPlayer(), "temperature") > 35 then
    destroyElement(elementtemp4)
    destroyElement(elementtemp3)
    destroyElement(elementtemp1)
    destroyElement(elementtemp2)
    destroyElement(elementtemp)
    elementtemp4 = dxDrawImage(screenWidth * 0.94, screenHeight * 0.7, screenHeight * 0.065, screenHeight * 0.065, "images/hud/temp/35.png", 0, 0, 0, tocolor(0, 255, 0))
    end
    if getElementData(getLocalPlayer(), "temperature") > 34 then
    destroyElement(elementtemp4)
    destroyElement(elementtemp3)
    destroyElement(elementtemp1)
    destroyElement(elementtemp2)
    destroyElement(elementtemp)
    elementtemp = dxDrawImage(screenWidth * 0.94, screenHeight * 0.7, screenHeight * 0.065, screenHeight * 0.065, "images/hud/temp/34.png", 0, 0, 0, tocolor(0, 255, 0))
    end
    ------------------------------- TEMPERATURA
   
    ------------------------------- SEDE
    dxDrawImage(screenWidth * 0.94, screenHeight * 0.775, screenHeight * 0.065, screenHeight * 0.065, "images/dayzicons/thirsty.png", 0, 0, 0, tocolor(0, 255, 0))
    if getElementData(getLocalPlayer(), "thirst") > 80 then
    destroyElement(elementdrink4)
    destroyElement(elementdrink3)
    destroyElement(elementdrink1)
    destroyElement(elementdrink2)
    destroyElement(elementdrink)
    elementdrink1 = dxDrawImage(screenWidth * 0.94, screenHeight * 0.775, screenHeight * 0.065, screenHeight * 0.065, "images/hud/drink/100.png", 0, 0, 0, tocolor(0, 255, 0))
    end
    if getElementData(getLocalPlayer(), "thirst") > 60 then
    destroyElement(elementdrink4)
    destroyElement(elementdrink3)
    destroyElement(elementdrink1)
    destroyElement(elementdrink2)
    destroyElement(elementdrink)
    elementdrink2 = dxDrawImage(screenWidth * 0.94, screenHeight * 0.775, screenHeight * 0.065, screenHeight * 0.065, "images/hud/drink/60.png", 0, 0, 0, tocolor(0, 255, 0))
    end
    if getElementData(getLocalPlayer(), "thirst") > 40 then
    destroyElement(elementdrink4)
    destroyElement(elementdrink3)
    destroyElement(elementdrink1)
    destroyElement(elementdrink2)
    destroyElement(elementdrink)
    elementdrink4 = dxDrawImage(screenWidth * 0.94, screenHeight * 0.775, screenHeight * 0.065, screenHeight * 0.065, "images/hud/drink/40.png", 0, 0, 0, tocolor(0, 255, 0))
    end
    if getElementData(getLocalPlayer(), "thirst") > 15 then
    destroyElement(elementdrink4)
    destroyElement(elementdrink3)
    destroyElement(elementdrink1)
    destroyElement(elementdrink2)
    destroyElement(elementdrink)
    elementdrink = dxDrawImage(screenWidth * 0.94, screenHeight * 0.775, screenHeight * 0.065, screenHeight * 0.065, "images/hud/drink/15.png", 0, 0, 0, tocolor(0, 255, 0))
    end
    ------------------------------- SEDE
   
    ------------------------------- FOME
    dxDrawImage(screenWidth * 0.94, screenHeight * 0.925, screenHeight * 0.065, screenHeight * 0.065, "images/dayzicons/food.png", 0, 0, 0, tocolor(0, 255, 0))
    if getElementData(getLocalPlayer(), "food") > 70 then
    destroyElement(elementfood4)
    destroyElement(elementfood3)
    destroyElement(elementfood1)
    destroyElement(elementfood2)
    destroyElement(elementfood)
    elementfood1 = dxDrawImage(screenWidth * 0.94, screenHeight * 0.925, screenHeight * 0.065, screenHeight * 0.065, "images/hud/food/100.png", 0, 0, 0, tocolor(0, 255, 0))
    end
    if getElementData(getLocalPlayer(), "food") > 50 then
    destroyElement(elementfood4)
    destroyElement(elementfood3)
    destroyElement(elementfood1)
    destroyElement(elementfood2)
    destroyElement(elementfood)
    elementfood2 = dxDrawImage(screenWidth * 0.94, screenHeight * 0.925, screenHeight * 0.065, screenHeight * 0.065, "images/hud/food/50.png", 0, 0, 0, tocolor(0, 255, 0))
    end
    if getElementData(getLocalPlayer(), "food") > 25 then
    destroyElement(elementfood4)
    destroyElement(elementfood3)
    destroyElement(elementfood1)
    destroyElement(elementfood2)
    destroyElement(elementfood)
    elementfood4 = dxDrawImage(screenWidth * 0.94, screenHeight * 0.925, screenHeight * 0.065, screenHeight * 0.065, "images/hud/food/25.png", 0, 0, 0, tocolor(0, 255, 0))
    end
    if getElementData(getLocalPlayer(), "food") > 10 then
    destroyElement(elementfood4)
    destroyElement(elementfood3)
    destroyElement(elementfood1)
    destroyElement(elementfood2)
    destroyElement(elementfood)
    elementfood = dxDrawImage(screenWidth * 0.94, screenHeight * 0.925, screenHeight * 0.065, screenHeight * 0.065, "images/hud/food/10.png", 0, 0, 0, tocolor(0, 255, 0))
    end
    ------------------------------- FOME
   
    ------------------------------- BLOOD
    dxDrawImage(screenWidth * 0.94, screenHeight * 0.85, screenHeight * 0.065, screenHeight * 0.065, "images/dayzicons/blood.png", 0, 0, 0, tocolor(0, 255, 0))
    if getElementData(getLocalPlayer(), "blood") > 8000 then
    destroyElement(elementblood4)
    destroyElement(elementblood3)
    destroyElement(elementblood1)
    destroyElement(elementblood2)
    destroyElement(elementblood)
    elementblood1 = dxDrawImage(screenWidth * 0.94, screenHeight * 0.85, screenHeight * 0.065, screenHeight * 0.065, "images/hud/blood/100.png", 0, 0, 0, tocolor(0, 255, 0))
    end
    if getElementData(getLocalPlayer(), "blood") > 5000 then
    destroyElement(elementblood4)
    destroyElement(elementblood3)
    destroyElement(elementblood1)
    destroyElement(elementblood2)
    destroyElement(elementblood)
    elementblood2 = dxDrawImage(screenWidth * 0.94, screenHeight * 0.85, screenHeight * 0.065, screenHeight * 0.065, "images/hud/blood/80.png", 0, 0, 0, tocolor(0, 255, 0))
    end
    if getElementData(getLocalPlayer(), "blood") > 3000 then
    destroyElement(elementblood4)
    destroyElement(elementblood3)
    destroyElement(elementblood1)
    destroyElement(elementblood2)
    destroyElement(elementblood)
    elementblood3 = dxDrawImage(screenWidth * 0.94, screenHeight * 0.85, screenHeight * 0.065, screenHeight * 0.065, "images/hud/blood/50.png", 0, 0, 0, tocolor(0, 255, 0))
    end
    if getElementData(getLocalPlayer(), "blood") > 2000 then
    destroyElement(elementblood4)
    destroyElement(elementblood3)
    destroyElement(elementblood1)
    destroyElement(elementblood2)
    destroyElement(elementblood)
    elementblood4 = dxDrawImage(screenWidth * 0.94, screenHeight * 0.85, screenHeight * 0.065, screenHeight * 0.065, "images/hud/blood/30.png", 0, 0, 0, tocolor(0, 255, 0))
    end
    if getElementData(getLocalPlayer(), "blood") > 1000 then
    destroyElement(elementblood4)
    destroyElement(elementblood3)
    destroyElement(elementblood1)
    destroyElement(elementblood2)
    destroyElement(elementblood)
    elementblood = dxDrawImage(screenWidth * 0.94, screenHeight * 0.85, screenHeight * 0.065, screenHeight * 0.065, "images/hud/blood/10.png", 0, 0, 0, tocolor(0, 255, 0))
    end
    -------------------------------
   
    local x, y, z = getElementPosition(getLocalPlayer())
    for i, player in ipairs(getElementsByType("player")) do
      setPlayerNametagShowing(player, false)
      if player ~= getLocalPlayer() then
        local vehicle = getPedOccupiedVehicle(player)
        local px, py, pz = getElementPosition(player)
        local pdistance = getDistanceBetweenPoints3D(x, y, z, px, py, pz)
        if pdistance <= 2 then
          local sx, sy = getScreenFromWorldPosition(px, py, pz + 0.95, 0.06)
          if sx and sy then
            if getElementData(player, "bandit") then
              text = string.gsub(getPlayerName(player), "#%x%x%x%x%x%x", "") .. " (Bandit)"
            else
              text = string.gsub(getPlayerName(player), "#%x%x%x%x%x%x", "")
            end
            local w = dxGetTextWidth(text, 1.02, "default-bold")
            dxDrawText(text, sx - w / 2, sy, sx - w / 2, sy, tocolor(100, 255, 100, 200), 1.02, "default-bold")
          end
        end
      end
    end
    local x, y, z = getElementPosition(getLocalPlayer())
    for i, veh in ipairs(getElementsByType("vehicle")) do
      local px, py, pz = getElementPosition(veh)
      local vehID = getElementModel(veh)
      local vehicle = getPedOccupiedVehicle(getLocalPlayer())
      if veh ~= vehicle and vehID ~= 548 then
        local pdistance = getDistanceBetweenPoints3D(x, y, z, px, py, pz)
        if pdistance <= 6 then
          local sx, sy = getScreenFromWorldPosition(px, py, pz + 0.95, 0.06)
          if sx and sy then
            local w = dxGetTextWidth(getVehicleName(veh), 1.02, "default-bold")
            dxDrawText(getVehicleName(veh), sx - w / 2, sy, sx - w / 2, sy, tocolor(100, 255, 100, 200), 1.02, "default-bold")
          end
        end
      end
    end
    local veh = getPedOccupiedVehicle(getLocalPlayer())
    if veh then
      local maxfuel = getElementData(veh, "maxfuel")
      local fuel = getElementData(getElementData(veh, "parent"), "fuel")
      local needengine = getElementData(veh, "needengines")
      local needtires = getElementData(veh, "needtires")
      local engine = getElementData(getElementData(veh, "parent"), "Engine_inVehicle") or 0
      local tires = getElementData(getElementData(veh, "parent"), "Tire_inVehicle") or 0
      local offset = dxGetFontHeight(1.02, "default-bold")
      local w = dxGetTextWidth(engine .. "/" .. needengine .. " Engine(s)", 1.02, "default-bold")
      if engine == needengine then
        r, g, b = 0, 255, 0
      else
        r, g, b = 255, 0, 0
      end
      dxDrawText(engine .. "/" .. needengine .. " Engine(s)", screenWidth * 0.5 - w / 2, screenHeight * 0, screenWidth * 0.5 - w / 2, screenHeight * 0, tocolor(r, g, b, 220), 1.02, "default-bold")
     
Link to comment

We already explained to you, a dxDraw item is not an ELEMENT, so you cannot "destroy" it. You just stop drawing it, you can do this by using variables. If you're unwilling to listen and learn then don't post. I would hate to see what your debug looks like with that script, no wonder it's lagging.

Link to comment

And once again I have to explain this.

@ReX; You need to understand what onClientRender does. This event will trigger the attached function once EVERY FRAME. This means, if your game is running at 60 FPS, you'll be executing ALL of that function, 60 TIMES PER SECOND.

And you're asking us why it's lagging?

You could always make a command to toggle the HUD on and off to allow players to decide whether they want it or not. Something like this might work,

Client-Side;

local showingHUD = true 
  
function exampleCode() 
    if(showingHUD == true) then 
        removeEventHandler("onClientRender", root, drawImage) 
        outputChatBox("You have toggled the HUD off.") 
    else 
        addEventHandler("onClientRender", root, drawImage) 
        outputChatBox("You have toggled the HUD on.") 
    end 
end 
addCommandHandler("hud", exampleCode, false, false) 

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...