Tosti Posted December 13, 2016 Share Posted December 13, 2016 (edited) Hey guys! I want to create an object counter for Map Editor but when i use #getElementsByType("object") it still show 1 object when there's 0 object on editor's list. with object: Spoiler without object: Spoiler x,y = guiGetScreenSize() addEventHandler("onClientRender", root, function() dxDrawText(string.format("obj: %d", #getElementsByType("object")), x * 0.4470, y * 0.1514, x * 0.5071, y * 0.1800, tocolor(255, 255, 255, 255), 1.00, "bankgothic", "left", "top", false, false, false, false, false) end) Edited December 13, 2016 by Tosti Link to comment
iPrestege Posted December 13, 2016 Share Posted December 13, 2016 With the way you are using any object's in the server will be counted if you want to count the object's in the resource. You have to use resourceRoot . Something like this : #getElementsByType ( 'object',resourceRoot ); @Tosti Link to comment
Tosti Posted December 13, 2016 Author Share Posted December 13, 2016 Nah, u didnt understood me. I'm counting objects on Map Editor, it isn't same resource as mine. I'd created another resource to count objects from Map Editor. Link to comment
Mr.Loki Posted December 13, 2016 Share Posted December 13, 2016 Your code works for me but when deleting an object in editor it just places in a temporary dimension so that the undo and redo functions are simple. You will need to ckeck if the object is in the same dimension as you. x,y = guiGetScreenSize() addEventHandler("onClientRender", root, function() local obj,count = getElementsByType("object"), 0 for i=1,#obj do count = true and inMyDim(obj[i]) and count+1 or count end dxDrawText("obj: ".. count, x * 0.4470, y * 0.1514, x * 0.5071, y * 0.1800, tocolor(255, 255, 255, 255), 1.00, "bankgothic", "left", "top", false, false, false, false, false) end) function inMyDim( elem ) if getElementDimension( elem ) == getElementDimension( localPlayer ) then return true end end Spoiler Link to comment
Tosti Posted December 13, 2016 Author Share Posted December 13, 2016 4 hours ago, loki2143 said: Your code works for me but when deleting an object in editor it just places in a temporary dimension so that the undo and redo functions are simple. You will need to ckeck if the object is in the same dimension as you. x,y = guiGetScreenSize() addEventHandler("onClientRender", root, function() local obj,count = getElementsByType("object"), 0 for i=1,#obj do count = true and inMyDim(obj[i]) and count+1 or count end dxDrawText("obj: ".. count, x * 0.4470, y * 0.1514, x * 0.5071, y * 0.1800, tocolor(255, 255, 255, 255), 1.00, "bankgothic", "left", "top", false, false, false, false, false) end) function inMyDim( elem ) if getElementDimension( elem ) == getElementDimension( localPlayer ) then return true end end Reveal hidden contents Works! Thanks u much! Link to comment
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