Jump to content

Dimension Check


ThePCGuy

Recommended Posts

Well i got a function that makes a object at the position of a player, but when changing dimension the object disappears ofcourse. But is there a way to make a automatic system that checks if the player changes from dimension the object does too?

Link to comment

There's 2 ways, 1 is a timer and the other is a render.

If you create a render all you have to do is check if the object is in the same dimension as the player and if it's not then set it's dimension to the player's.

Example 1: Server-sided

setTimer(function() 
    for _,player in ipairs(getElementsByType("player"))do 
        for _,child in ipairs(getElementChildren(player))do 
            if getElementType(child) == "object" then 
                local playerDim = getElementDimension(player) 
                if getElementDimension(child) ~= playerDim then 
                    setElementDimension(child,playerDim) 
                end 
            end 
        end 
    end 
end,3000,0) 

Example 2: Client-side

addEventHandler("onClientPreRender",root,function() 
    for _,player in ipairs(getElementsByType("player"))do 
        for _,child in ipairs(getElementChildren(player))do 
            if getElementType(child) == "object" then 
                local playerDim = getElementDimension(player) 
                if getElementDimension(child) ~= playerDim then 
                    setElementDimension(child,playerDim) 
                end 
            end 
        end 
    end 
end) 

Edited by Guest
Link to comment
Isnt the server going to lag if it sets the object to the players dimension every frame?

Follow what Solidsnake suggested, you have a variable that stores your dimension the previous frame and then you compare your new dimension onClientPreRender with the variable you had stored, only then has your dimension changed and you can trigger your own event.

It will only trigger once then per dimension change and server wont lag at all. You can even change the object dimension client sided if you wish, then its fully client sided.

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