Overkillz Posted October 28, 2019 Share Posted October 28, 2019 Hello dear community, Im trying to create a preview of all the spawns from a map. In this case, the spawns are vehicles. Well, I need to hide the preview spawn if the playerVehicle is over the preview spawn. I know i can check the position of the playerVehicle and compare it with the spawn preview or adding an ID where Im storing all the spawn preview and another alternatives. But my question is, is there a function that check it? i know it sounds weird. Thanks for reading, best regards. Link to comment
Moderators IIYAMA Posted October 28, 2019 Moderators Share Posted October 28, 2019 21 minutes ago, Overkillz said: But my question is, is there a function that check it? Yes, just not by default. ---------- The website that originally contained the resource that could do that is gone because the owner crystalMV did quit MTA, but it seems a copy of it is still stored in the website archive: https://web.archive.org/web/20160507103732/http://crystalmv.net84.net/pages/scripts/server_coldata.php 1 Link to comment
Overkillz Posted October 28, 2019 Author Share Posted October 28, 2019 It looks interesting but looks like it requieres a higher performance than a simple id for each element inside a table or elementsData. I know that it could be the right choice for other cases (Not for mine in this case) Anyways I have no doubts that Im going to use it in a future. Thanks for the information. I have another question. Im working with different dimensions. My question is, if some of the players are in the same dimension like me and i try to get all the vehicles using getElementsByType. Will it drop me all the vehicles in the same dimension or from all dimension ? I know I can use other ways like getting the players dimension ...etc. But is just a question that have took all my attention. Thanks for reading. Regards. Link to comment
Moderators IIYAMA Posted October 28, 2019 Moderators Share Posted October 28, 2019 13 minutes ago, Overkillz said: My question is, if some of the players are in the same dimension like me and i try to get all the vehicles using getElementsByType. Will it drop me all the vehicles in the same dimension or from all dimension ? I know I can use other ways like getting the players dimension ...etc. But is just a question that have took all my attention. Good question. Yes it will get all vehicles by default. There is one thing that I do not know and that is: "Will vehicles in a different dimension be considered as streamed in?" Because getElementsByType does have a setting that allows the user to only collect streamed in vehicles. Which is incredible useful to improve the performance of the script. But if you need all streamed out vehicles as well, it might not be a good solution. https://wiki.multitheftauto.com/wiki/GetElementsByType Syntax (clientside) table getElementsByType ( string theType, [ element startat=getRootElement(), bool streamedIn=false ] ) Capturing only streamed in vehicles. local vehicles = getElementsByType ("vehicle", root, true ) A different method, but has to be partly implemented on the resource that creates vehicles. (not recommended unless you know how to to work with the element tree) local vehicleParent = createElement("vehicleParent") local newVehicle newVehicle = createVehicle ( 551, 0,0,0 ) setElementParent(newVehicle, vehicleParent) newVehicle = createVehicle ( 551, 0,0,0 ) setElementParent(newVehicle, vehicleParent) newVehicle = createVehicle ( 551, 0,0,0 ) setElementParent(newVehicle, vehicleParent) setElementDimension(vehicleParent, 100) -- move all current vehicles to a different dimension (fun fact) Getting only these 3 vehicles. local vehicles -- vehicles = getElementsByType ("vehicle", vehicleParent) -- or vehicles = getElementChildren ( vehicleParent, "vehicle" ) -- the difference: This function only captures the direct children of the parent 'vehicleParent'. But in this set-up it doesn't matter. Else you might need an utility function, like this: function filterElementsByDimension (elementList, dimension) local newElementList = {} for 1, #elementList do local element = elementList[i] if getElementDimension(element) == dimension then newElementList[#newElementList + 1] = element end end return newElementList end 1 Link to comment
Overkillz Posted October 28, 2019 Author Share Posted October 28, 2019 Ohh. I see. I wasn't aware about the streamed argument. Respecting the elements tree, the functionallity looks interesting. Might It could bring me a better result isntead dealing with arrays. Thanks newly It helped me a lot. Regards. 1 Link to comment
Moderators IIYAMA Posted October 28, 2019 Moderators Share Posted October 28, 2019 (edited) 15 minutes ago, Overkillz said: Respecting the elements tree, the functionallity looks interesting. Might It could bring me a better result isntead dealing with arrays. Yes and no. It does have some limitations, when it comes to multiple resources. You can't assign children to parents of different resources. A possible way around: Resource 1 local vehicleParent = createElement("vehicleParent") local newVehicle newVehicle = createVehicle ( 551, 0,0,0 ) setElementParent(newVehicle, vehicleParent) newVehicle = createVehicle ( 551, 0,0,0 ) setElementParent(newVehicle, vehicleParent) Resource 2 local vehicleParent = createElement("vehicleParent") local newVehicle newVehicle = createVehicle ( 551, 0,0,0 ) setElementParent(newVehicle, vehicleParent) newVehicle = createVehicle ( 551, 0,0,0 ) setElementParent(newVehicle, vehicleParent) Resource 3 local vehicleParents = getElementsByType ("vehicleParent") -- getElementChildren doesn't work at this first line, because those elements are not direct children of the root element. for i=1 #vehicleParents do local vehicleParent = vehicleParents[i] local vehicles = getElementChildren ( vehicleParent, "vehicle" ) for j=1 #vehicles do local vehicle = vehicles[j] end end Edited October 28, 2019 by IIYAMA 1 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