ThePCGuy Posted July 20, 2013 Share Posted July 20, 2013 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
Castillo Posted July 20, 2013 Share Posted July 20, 2013 There's no native event, but you can build your own. Event: onClientPreRender Function: getElementDimension You store the current dimension on a variable, then you check, if it changed, you trigger an event with: triggerEvent Link to comment
ThePCGuy Posted July 20, 2013 Author Share Posted July 20, 2013 Isnt the server going to lag if it sets the object to the players dimension every frame? Link to comment
Jaysds1 Posted July 20, 2013 Share Posted July 20, 2013 (edited) 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 July 20, 2013 by Guest Link to comment
FatalTerror Posted July 20, 2013 Share Posted July 20, 2013 Another dirty solution is using onElementDataChange When you setElementDimension, you set at the same time an element data to the player. That could work no? Link to comment
Castillo Posted July 20, 2013 Share Posted July 20, 2013 If the server uses a lot of element data, then it would be a problem. Link to comment
Jaysds1 Posted July 20, 2013 Share Posted July 20, 2013 Ya, where as if you set the object as the player's child then it would still sync but not as bad as using element data. Link to comment
arezu Posted July 20, 2013 Share Posted July 20, 2013 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
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