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" )  
end 
addEventHandler("onClientResourceStart", resourceRoot, function() addEventHandler("onClientRender", root, showImage) end) 
  

Edited by Guest
Link to comment

nil is always nil, all variables that doesn't point on anything will return nil when trying to access them, to make a long story short, Yes.

Depending on what you're trying to do it may be simpler using constant values rather than inserting lot's of pointers to nil and then trying to figure out what's wrong.

What values are you using?

Link to comment

i use that both codes here:

server side:

function setDataOnLogin() 
    if not isGuestAccount(getPlayerAccount(source)) and isObjectInACLGroup("user."..getAccountName(source), aclGetGroup("Everyone")) then 
        setElementData(source, "showimg", true) 
    end 
end 
addEventHandler("onPlayerLogin", root, setDataOnLogin) 
  
function setDataOnResourceStart() 
    for i, v in ipairs(getElementsByType("player")) do 
        if not isGuestAccount(getPlayerAccount(v)) and isObjectInACLGroup("user."..getAccountName(v), aclGetGroup("Everyone")) then 
            setElementData(v, "showimg", true) 
        end 
    end 
end 

client side:

nameWidth = 1 
teamWidth = 1 
sx = 1 
scale = 1 
imageSize = 2 
function showImage() 
dxDrawImage( sx + math.max(nameWidth/2, teamWidth/2) + 0*scale, sy - imageSize, imageSize, imageSize, "classicon_player.png" ) 
end 
addEventHandler("onClientResourceStart", resourceRoot, function() addEventHandler("onClientRender", root, showImage) end) 
  

Link to comment

Your image is showing but it's only 2 pixels in size so you can't see it, don't make it more complicated than it has to be:

local sx,sy = guiGetScreenSize() 
function showImage() 
    dxDrawImage((sx-800)/2, (sy-600)/2, 800, 600, "player.png" )  
end 
addEventHandler("onClientRender", root, showImage) 

Edited by Guest
Link to comment
local sx,sy = guiGetScreenSize() 
function showImage() 
    if getElementData(localPlayer, "showimg") then 
        dxDrawImage((sx-800)/2, (sy-600)/2, 800, 600, "player.png" )  
    end 
end 
addEventHandler("onClientRender", root, showImage) 

Now which one is it? Just modify the if statement to toggle admin or non admin.

Link to comment

like that or ??

local sx,sy = guiGetScreenSize() 
function showImage() 
    if  isObjectInACLGroup("user."..getAccountName(source), aclGetGroup("Admin"))(localPlayer, "showimg") then 
        dxDrawImage((sx-800)/2, (sy-600)/2, 800, 600, "player.png" ) 
    end 
end 
addEventHandler("onClientRender", root, showImage) 

And second how can i make it shown at the right sy sx for different resolutions??

Link to comment
local sx,sy = guiGetScreenSize() 
function showImage() 
    if getElementData(localPlayer, "showimg") then 
        dxDrawImage((sx-800), (sy-600), 800, 600, "player.png" )  
    end 
end 
addEventHandler("onClientRender", root, showImage) 

That's all you need, do not use server functions client side and vice versa, you had the server side part which set's the element data making it accessible to the clients. The if statement holds this: "getElementData(localPlayer, "showimg")" which will be true or false depending on if you're staff or not.

Link to comment
like that or ??
local sx,sy = guiGetScreenSize() 
function showImage() 
    if  isObjectInACLGroup("user."..getAccountName(source), aclGetGroup("Admin"))(localPlayer, "showimg") then 
        dxDrawImage((sx-800)/2, (sy-600)/2, 800, 600, "player.png" ) 
    end 
end 
addEventHandler("onClientRender", root, showImage) 

And second how can i make it shown at the right sy sx for different resolutions??

You need to get the player's account on the server side

To answer your other question:

local sx,sy = guiGetScreenSize() 
local px,py = 1600,900 
local x,y =  (sx/px), (sy/py) 
dxDrawImage(x*800, y*600, x*800,y*600, "player.png" )  

Link to comment

Try this:

Server side

local account = getPlayerAccount(thePlayer) 
local accountName = getAccountName(account) 
  
function setDataOnLogin(thePlayer) 
        if ( isObjectInACLGroup ( "user.".. accountName, aclGetGroup ( "Admin" ) ) ) then 
            setElementData(thePlayer,"showimg",true) 
        end 
end 
addEventHandler ( "onPlayerLogin", root, setDataOnLogin ) 

Client side

local sx,sy = guiGetScreenSize() 
local px,py = 1600,900 
local x,y =  (sx/px), (sy/py) 
  
function showImage() 
    if getElementData(localPlayer, "showimg") then 
        dxDrawImage(x*800, y*600, x*800, y*600, "player.png" ) 
    end 
end 
addEventHandler("onClientRender", root, showImage) 

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