Jump to content

Getting the nearest Element...


Xeno

Recommended Posts

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

@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 :D

I am on my phone so can't do much but will help you tomorrow step by step.

Edited by Guest
Link to comment

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

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) 
 
  • Like 1
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...