Jump to content

dxdraw problem


yoya99

Recommended Posts

hello there i have this codto draw an image near the head of a player wich is ina dmin acl but i get an error....

The Error is:Error:class/client.lua:2 : attempt to perform arithmetic on global "nameWidth" (a nil value)

Can someone help me pls?? here is the client.lua:

function showImage() 
dxDrawImage( sx + math.max(nameWidth/2, teamWidth/2) + 0*scale, sy - imageSize, imageSize, imageSize, "player.png" ) -- Here will go the rest of your code. 
end 
addEventHandler("onClientResourceStart", resourceRoot, function() addEventHandler("onClientRender", root, showImage) end) 
  

Link to comment

HOW CAN I MAKE IT SHON THE IMAGES FROM OTHER PLAYERS TOOß NOT ONLY MINE::::

local sx,sy = guiGetScreenSize() 
function showImage() 
if getElementData(getLocalPlayer(), "showImage") then 
dxDrawImage((sx-190)/2, (sy-200)/2, 25, 25, "classicon_player.png" ) 
else 
dxDrawImage((sx-190)/2, (sy-200)/2, 25, 25, "classicon_vip.png" ) 
end 
end 
addEventHandler("onClientRender", root, showImage) 

function setDataOnLogin() 
     if isObjectInACLGroup ("user."..getAccountName (getPlayerAccount( source )),aclGetGroup ( "Admin" )) then 
        setElementData(source, "showImage", true) 
    end 
end 
addEventHandler("onPlayerLogin", root, setDataOnLogin) 
  
function setDataOnResourceStart() 
    for i, v in ipairs(getElementsByType("player")) do 
     if isObjectInACLGroup ("user."..getAccountName (getPlayerAccount ( v )), aclGetGroup ( "Admin" )) then 
            setElementData(v, "showImage", true) 
        end 
    end 
end 
addEventHandler("onResourceStart", resourceRoot, setDataOnResourceStart) 
  
function removeDataOnLogout() 
        setElementData(source, "showImage", false) 
end 
addEventHandler("onPlayerLogout", root, removeDataOnLogout) 

Link to comment

Well not by being pissed of and write everything in caps, you need some math skills, some understanding in how the server communicate with all the clients and some patience. Here's a modified version of the nametag script from the standard race game mode, which should be relatively easy to modify in the way you want it to work:

local x, y = guiGetScreenSize() 
function PlayerNameTags() 
    local players = getElementsByType("player") 
    for k,v in ipairs(players) do 
        if v ~= localPlayer and getPlayerTeam(v) then 
            local r,g,b = getTeamColor(getPlayerTeam(v)) 
            local x1,y1,z1 = getElementPosition(localPlayer) 
            local x2,y2,z2 = getElementPosition(v) 
            local visibleto = getDistanceBetweenPoints3D(x1,y1,z1,x2,y2,z2) 
            if visibleto < 14 then 
                local sx,sy = getScreenFromWorldPosition ( x2,y2,z2+0.3 ) 
                if sx and sy and not getElementData( v, "anon" ) and getElementInterior(v) == getElementInterior(localPlayer) and  
                    getElementDimension(v) == getElementDimension(localPlayer) then 
                    local nWidth = string.len(getPlayerName(v)) or 20 
                    dxDrawRectangle( sx-((nWidth*14)/2),sy-7,(nWidth*14),30, tocolor(0,0,0,100)) 
                    dxDrawText( string.gsub( getPlayerName(v), "#%x%x%x%x%x%x", "" ).."", sx,sy,sx,sy,  
                        tocolor(r,g,b,255), 0.5, "bankgothic", "center","top",false,false,false ) 
                end 
            end 
        end 
    end 
end 
addEventHandler("onClientRender",getRootElement(),PlayerNameTags) 

Try it out and see for yourself how it works, all you need to do is to show the image instead of the text and increase the height from world position a little bit maybe. element data in the if statement named "anon" is perfect to replace with yours which you used to check if someone are in the staff team (according to your other topic). Good luck.

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