Jump to content

how i can know my xyz in MTA


Liyones

Recommended Posts

  • MTA Anti-Cheat Team

I think you mean this:

local x, y, z = getElementPosition(element)

 

3 hours ago, X.Liyones.X said:

know my xyz position

I think you want to replace element with thePlayer or localPlayer

I guess you understand it now, but just in case: Example on how to use the position stored in the x, y, z local

local x, y, z = getElementPosition(thePlayer) -- get player's location
createVehicle(551, x, y, z) -- spawn a vehicle at player's location

That code would do exactly the same as this:

createVehicle(551, getElementPosition(thePlayer))

The reason that above code (single line) also works, is because createVehicle requires 3 float functions (x, y, z position) to spawn a vehicle, and getElementPosition returns exactly these 3 float values that it wants.

Note to others reading this in the future: you can't use a local like this (a, b, c) for all functions - the reason it fits getElementPosition is because it returns 3 float values, as the wiki page for this function reads:

rC2gLgl.png

However, you can store return values from plenty of functions in a local with the appropiate amount of values (not just local a, b, c) and the reason I am turning this reply into some kind of tutorial is because I've seen the prevalence of scripts that can be easily cleaned up by doing things like this.

@X.Liyones.X

  • Thanks 1
Link to comment
4 hours ago, AleksCore said:

 

On 28/12/2019 at 14:28, Dutchman101 said:

I think you mean this:


local x, y, z = getElementPosition(element)

 

I think you want to replace element with thePlayer or localPlayer

I guess you understand it now, but just in case: Example on how to use the position stored in the x, y, z local


local x, y, z = getElementPosition(thePlayer) -- get player's location
createVehicle(551, x, y, z) -- spawn a vehicle at player's location

That code would do exactly the same as this:


createVehicle(551, getElementPosition(thePlayer))

The reason that above code (single line) also works, is because createVehicle requires 3 float functions (x, y, z position) to spawn a vehicle, and getElementPosition returns exactly these 3 float values that it wants.

Note to others reading this in the future: you can't use a local like this (a, b, c) for all functions - the reason it fits getElementPosition is because it returns 3 float values, as the wiki page for this function reads:

rC2gLgl.png

However, you can store return values from plenty of functions in a local with the appropiate amount of values (not just local a, b, c) and the reason I am turning this reply into some kind of tutorial is because I've seen the prevalence of scripts that can be easily cleaned up by doing things like this.

@X.Liyones.X

thanks guys

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