Xeno Posted January 6, 2012 Share Posted January 6, 2012 What functions would I use to get the nearest element to the localplayer? so like a car, object, ect. Thanks, Xeno. Link to comment
CapY Posted January 6, 2012 Share Posted January 6, 2012 Take a look at: https://wiki.multitheftauto.com/wiki/Get ... enPoints2D and https://wiki.multitheftauto.com/wiki/Get ... enPoints3D Hope it will help. Link to comment
Xeno Posted January 6, 2012 Author Share Posted January 6, 2012 vehicle1x, vehicle1y, vehicle1z = getElementPosition ( vehicle1 ) -- HERE I would get all the local vehicles? vehicle2x, vehicle2y, vehicle2z = getElementPosition ( vehicle2 ) -- SO HERE I would put the local player? --Warp stuff here? Link to comment
CapY Posted January 6, 2012 Share Posted January 6, 2012 vehicle1x, vehicle1y, vehicle1z = getElementPosition ( vehicle1 ) -- HERE I would get all the local vehicles? vehicle2x, vehicle2y, vehicle2z = getElementPosition ( vehicle2 ) -- SO HERE I would put the local player? --Warp stuff here? No, but you'll get specified vehicle. Yes, you can put local player. Link to comment
Xeno Posted January 6, 2012 Author Share Posted January 6, 2012 So it would not be possible to get the nearest Element? Link to comment
CapY Posted January 6, 2012 Share Posted January 6, 2012 So it would not be possible to get the nearest Element? It is possible to get the nearest element. Link to comment
Xeno Posted January 6, 2012 Author Share Posted January 6, 2012 How..? (Sorry im a noob) getElementRoot()? Link to comment
CapY Posted January 6, 2012 Share Posted January 6, 2012 You want a specified element or all elements ? Link to comment
Castillo Posted January 6, 2012 Share Posted January 6, 2012 Read his main post again: What functions would I use to get the nearest element to the localplayer? so like a car, object, ect. I think he want's a function to get the elements near to him ( I think all types ). Link to comment
CapY Posted January 6, 2012 Share Posted January 6, 2012 Oh. Then: for k,v in pairs(getElementsByType"object") do --code afaik.. Link to comment
myonlake Posted January 6, 2012 Share Posted January 6, 2012 (edited) @CapY: No! That will only give an error as it's not finished. local type = "object" -- Type: vehicle, ped, player, object ect. for key,value in ipairs(getElementsByType(type)) do -- Stuff here end He wants ALL ELEMENTS, not OBJECTS, meaning ALL TYPES that elements can be in MTA:SA. Create a colShape in your position and check all elements that are within the colShape. Now output everything like.. Objects: - ID: idhere Markers: - Type: typehere Players: - Name: namehere Vehicles: - Vehicle model and name: model, name Ecetera. It's easy if you'd know more scripting I am on my phone so can't do much but will help you tomorrow step by step. Edited January 6, 2012 by Guest Link to comment
Xeno Posted January 6, 2012 Author Share Posted January 6, 2012 Ok thats fine, but when I do setElementPosition ( [What would I put here? There is no specified name) Thanks, Xeno. Link to comment
CapY Posted January 6, 2012 Share Posted January 6, 2012 Could you atleast tell us, what type of the script are you doing ? What do you want to achieve with it, because i don't get you that much. Link to comment
Xeno Posted January 6, 2012 Author Share Posted January 6, 2012 Trying to get the nearest vehicle to warp too me, - Sorry didn't make it clear Link to comment
CapY Posted January 6, 2012 Share Posted January 6, 2012 Then just do like myonlake said. Create a colShape about 100m radius and attach it to a player, add a handler for colShape hit, then walk around, when your colShape hits an element, check if it's an vehicle, if it is, then warp player into. I'm bad at explaining. Link to comment
myonlake Posted January 6, 2012 Share Posted January 6, 2012 Hello again, This script is server-side. Few things you should know: - localPlayer: built-in source after 1.1 for client-side only - client-side: clients download the Lua file on their own computer, meaning that they are able to read your code if it's not compiled. Not much lag. However you should -always- try to make your scripts server-side. - server-side: clients will not download the Lua file on their on computer, meaning that the server reads the code. This lags more than client-side. - bugs: happens if not considered about them because of hurry There is a small 'bug' in this code, it's about that warping. It might end rough if many cars in the colshape. And to fix that, go to the previous page and take a look at the first reply. It's one option, use your imagination and ask help if you're not sure. Just remember to tell us some details what you think'll work. addCommandHandler("warpvehicle", function(player, cmd) local element = "vehicle" local radius = 100 local warp_successful = "Nearest vehicles warped to you." local x, y, z = getElementPosition(player) local colshape = createColSphere(tonumber(x), tonumber(y), tonumber(z), tonumber(radius)) for index, value in ipairs(getElementsWithinColShape(colshape, element)) do setElementPosition(value, tonumber(x) - 2, tonumber(y), tonumber(z)) outputChatBox(tostring(warp_successful), player, 220, 220, 0) end destroyElement(colshape) end) 1 Link to comment
Castillo Posted January 6, 2012 Share Posted January 6, 2012 There's no such function: createColShape, myonlake. Maybe you meant: createColTube? P.S: You're creating a colshape every time he writes the command, without destroying it. Link to comment
myonlake Posted January 6, 2012 Share Posted January 6, 2012 Fixed, solidsnake Feel free to modify it, going offline and coming online in the morning. Link to comment
Xeno Posted January 6, 2012 Author Share Posted January 6, 2012 Ok, so now should I set a timer that destroys the col? EDIT: Wait, he added it. NVM. Link to comment
myonlake Posted January 6, 2012 Share Posted January 6, 2012 Ok, so now should I set a timer that destroys the col?EDIT: Wait, he added it. NVM. As far as I know, you do not need a timer to destroy a colshape in a function as it destroys it -after- the 'check' is made. Link to comment
Xeno Posted January 6, 2012 Author Share Posted January 6, 2012 Thank you for the code, this will help me alot Link to comment
myonlake Posted January 6, 2012 Share Posted January 6, 2012 Thank you for the code, this will help me alot No problem P.S: Copy the code again, fixed some things in it. 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