Jump to content

Objects counter for Map Editor


Tosti

Recommended Posts

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

6dIUnHe.png

without object:

Spoiler

vN5qM4B.png

 

	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 by Tosti
Posted

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

Posted

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.

Posted

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

FZhkR95.jpg

 

 

Posted
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

FZhkR95.jpg

 

 

Works! Thanks u much!

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