Jump to content

line move


Recommended Posts

example about calculation pls

Think about it for a while, do some testing. Scripting and programming is a lot about trial and error, in fact, it's mostly trial and error. Can't expect to get everything served on a silver platter.

It's all about logical thinking;

Issue 1: You need to draw in 3D space.

Solution: dxDrawLine3D, dxDrawMaterialLine3D or dxDrawMaterialSectionLine3D

Issue 2: You need it to follow the vehicle.

Solution: Get the vehicle's position in 3D Space - getElementPosition.

Basically what you want to do is to get the vehicle's position and store it in a table. Then you draw whatever is stored inside this table. And to get the effect where it's removed after a certain distance you can either do by number of items in the table and remove the first item every time a new one is inserted. Or by time, which might be a bit more complicated.

1. Get vehicle position.

2. Store vehicle position in a table.

3. Loop through all items in the table, draw them.

4. Remove first item in the table if you want to.

You'll also probably want to use onClientPreRender instead of onClientRender. Just give it some time, read through the MTA Wiki examples and I'm sure you'll figure something out.

You shouldn't need any fancy trigonometry calculations unless you want to go over the top. :)

Link to comment
  • Moderators
local myTable = {} -- Create an empty table. 


local amountOfItems = #myTable -- # < Will return the highest position in this table.  
-- When the table is empty it will be 0.  
-- When there is 1 item in it, it will be most likely 1, but not always when the array/table isn't clean. 

What is the array?

local positionOfLastItem = amountOfItems -- This is most likely the position of the last item in the table. 


local dataThatIsInside = {345,57567,5777} -- x,y,z This is what you are going to save. 


local nextItemPosition = positionOfLastItem +1 -- Get the next position in the table, where you want to store your item.  


myTable[nextItemPosition] = dataThatIsInside -- Saving in the Table. 

The table will look like this at the end: (in the lua memory)

myTable = { 

There are also table.insert and table.remove. But those have more functionality. You should first understand the array before you start using those.

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