Jump to content

[HELP] dxDrawText


Backsage

Recommended Posts

This won't remove the text. Why?

  
function hello(score) 
        dxDrawText("Score: " .. score, 118, 358, 291, 380, tocolor(255, 174, 0, 255), 1.30, "default-bold", "left", "top", false, false, false, false, false) 
end 
  
  
score = 0 
  
function wepfire() 
        if getElementHealth(source) == 0 then 
                score = score + 3 
                addEventHandler("onClientRender", root, function() hello(score) end) 
        end 
end 
addEventHandler("onClientPlayerWasted", root, wepfire) 
  
  
addCommandHandler("removedx", 
function () 
        removeEventHandler("onClientRender", root, hello) 
end 
) 
  

Link to comment
This won't remove the text. Why?
  
function hello(score) 
        dxDrawText("Score: " .. score, 118, 358, 291, 380, tocolor(255, 174, 0, 255), 1.30, "default-bold", "left", "top", false, false, false, false, false) 
end 
  
  
score = 0 
  
function wepfire() 
        if getElementHealth(source) == 0 then 
                score = score + 3 
                addEventHandler("onClientRender", root, function() hello(score) end) 
        end 
end 
addEventHandler("onClientPlayerWasted", root, wepfire) 
  
  
addCommandHandler("removedx", 
function () 
        removeEventHandler("onClientRender", root, hello) 
end 
) 
  

addCommandHandler("removedx", 

u did not call any function in this command handler

Link to comment
  • Moderators
local score = 0 
  
function hello() 
        dxDrawText("Score: " .. tostring(score), 118, 358, 291, 380, tocolor(255, 174, 0, 255), 1.30, "default-bold", "left", "top", false, false, false, false, false) 
end 
  
function wepfire() 
        if getElementHealth(source) == 0 then 
                score = score + 3 
                addEventHandler("onClientRender", root, hello) 
        end 
end 
addEventHandler("onClientPlayerWasted", localPlayer, wepfire) 
  
  
addCommandHandler("removedx", 
function () 
        removeEventHandler("onClientRender", root, hello) 
end 
) 

It should work.

Link to comment

Thanks so much man, it works. Hopefully, I can apply this to another script I'm working on :D

Edit: One last thing. How can I get this to work based on dimension? I want to be able to remove the text by the command AND based on dimension. It removes the text when I'm not in dimension 1, but I can't get it to remove it on the command.

Client side:

  
local score = 0 
  
function hello() 
    local dim = getElementDimension(localPlayer) 
    for i, v in ipairs (getElementsByType("player")) do 
        if (dim == 1) then 
            dxDrawText("Score: " .. tostring(score), 118, 358, 291, 380, tocolor(255, 174, 0, 255), 1.30, "default-bold", "left", "top", false, false, false, false, false) 
        end 
    end  
end 
  
function wepfire() 
        if getElementHealth(source) == 0 then 
                score = score + 3 
                --addEventHandler("onClientRender", root, hello) 
        end 
end 
addEventHandler("onClientPlayerWasted", localPlayer, wepfire) 
  
function thisistest(score) 
    addEventHandler("onClientRender", root, function() hello(score) end) 
end 
addEvent("justfortest1", true) 
addEventHandler("justfortest1", root, thisistest) 
  
  
addCommandHandler("removedx", 
function () 
    local dim = getElementDimension(localPlayer) 
    for i, v in ipairs (getElementsByType("player")) do 
        if (dim == 1) then 
            removeEventHandler("onClientRender", localPlayer, hello) 
        end 
    end 
end 
) 
  
addCommandHandler("showdx",  
    function() 
        local dim = getElementDimension(localPlayer) 
        for i, v in ipairs (getElementsByType("player")) do 
            if (dim == 1) then 
                triggerServerEvent("justfortest", getLocalPlayer(), score) 
            end 
        end 
    end 
) 
  

Server side:

  
function scorehandler(score) 
    local dim1players = getElementsInDimension("player", 1) 
    for k, v in ipairs (dim1players) do 
        text1 = "Score " .. score 
        triggerClientEvent(v, "justfortest1", v, text1) 
    end 
end 
addEvent("justfortest", true) 
addEventHandler("justfortest", root, scorehandler) 
  
function getElementsInDimension(theType,dimension) 
    local elementsInDimension = { } 
      for key, value in ipairs(getElementsByType(theType)) do 
        if getElementDimension(value)==dimension then 
        table.insert(elementsInDimension,value) 
        end 
      end 
      return elementsInDimension 
end 
  

Link to comment
function thisistest(score) 
    addEventHandler("onClientRender", root, hello) 
end 
addEvent("justfortest1", true) 
addEventHandler("justfortest1", root, thisistest) 
  
addCommandHandler("removedx", 
function () 
    local dim = getElementDimension(localPlayer) 
    if (dim == 1) then 
        removeEventHandler("onClientRender", root, hello) 
    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...