yoya99 Posted October 13, 2014 Posted October 13, 2014 (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 October 13, 2014 by Guest
Mr_Moose Posted October 13, 2014 Posted October 13, 2014 nameWidth is not defined, you need to assign a value to it otherwise it's nil.
yoya99 Posted October 13, 2014 Author Posted October 13, 2014 (edited) how can i define it? To draw it i have added it in the nametags.lua too..how to solve this problem? Edited October 13, 2014 by Guest
Mr_Moose Posted October 13, 2014 Posted October 13, 2014 Before it's being used, above line 2 for example.
yoya99 Posted October 13, 2014 Author Posted October 13, 2014 the same error message with 'sx' now...do i add it too?
yoya99 Posted October 13, 2014 Author Posted October 13, 2014 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
Mr_Moose Posted October 13, 2014 Posted October 13, 2014 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?
yoya99 Posted October 13, 2014 Author Posted October 13, 2014 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)
Mr_Moose Posted October 13, 2014 Posted October 13, 2014 (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 October 13, 2014 by Guest
Anubhav Posted October 13, 2014 Posted October 13, 2014 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)
yoya99 Posted October 13, 2014 Author Posted October 13, 2014 another problem...i am not admin but it draws the image for Admin help pls
Mr_Moose Posted October 13, 2014 Posted October 13, 2014 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.
yoya99 Posted October 13, 2014 Author Posted October 13, 2014 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??
Mr_Moose Posted October 13, 2014 Posted October 13, 2014 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.
yoya99 Posted October 13, 2014 Author Posted October 13, 2014 so what i have to add that it only shows the image admins?
Banex Posted October 13, 2014 Posted October 13, 2014 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" )
yoya99 Posted October 13, 2014 Author Posted October 13, 2014 so what i have to add that it only shows the image admins?
Banex Posted October 13, 2014 Posted October 13, 2014 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
yoya99 Posted October 13, 2014 Author Posted October 13, 2014 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
Banex Posted October 13, 2014 Posted October 13, 2014 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)
yoya99 Posted October 13, 2014 Author Posted October 13, 2014 thx guys its fixed.... pls see my other question here : viewtopic.php?f=91&t=81481 itswith dxdraw
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now