Jump to content

dxdraw problem


yoya99

Recommended Posts

Posted (edited)

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
Posted (edited)

how can i define it? To draw it i have added it in the nametags.lua too..how to solve this problem?

Edited by Guest
Posted

ok i fixed the errors now but i dont see any image...i tried to logout so i am in acl group everyone and then i dont see my image :(((( helpppp

Posted

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?

Posted

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) 
  

Posted (edited)

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
Posted

Its guiGetScreenSize not guiGetScreensize

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

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

Posted

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

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

Posted
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" )  

Posted
so what i have to add that it only shows the image admins?

Use the last code of MrBrutus, and the server-side script you posted here before

Posted

now i dont see any image...its like my old problem was .... i guess the last codes were ok but it drawed me an image even if i werent admin

Posted

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) 

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