Jump to content

Getting the nearest Element...


Xeno

Recommended Posts

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

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

Posted

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

Posted (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 :D

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

Edited by Guest
Posted

Ok thats fine, but when I do

setElementPosition ( [What would I put here? There is no specified name)  

Thanks,

Xeno.

Posted

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.

Posted

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.

Posted

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
Posted

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.

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

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