Jump to content

[TUT] Attaching objects


Metall

Recommended Posts

Attaching objects tutorial, made by Metall

Let's begin, well this tutorial covers how to attach objects to something, a vehicle for example.

You can attach objects to a player too, which gives you the oppertunity to make urself a hamburger or whatever

:)

Well, here we go, i will make this tutorial like i will add 1 line, and explain it, much better for learning i hope

Creating the actual function name, also including player, which is used for getting the player easier.

function attachTest(player) 

Now let's get the X, Y, and Z of the player, by using this line:

x,y,z = getElementPosition(player) 

Now, we'll add the actual object, we'll be using a local variable for it, the function will be: createObject.

local object = createObject(objectID, x, y, z) 

Now let's get who's driving the actual car.

local veh = getPedOccupiedVehicle(player) 

Now, what you all have been waiting for, attaching the object to the actual car, more about this under this line.

attachElements(object, veh) 

The attachElements gets the object and or the player, it can also needs to have the variables in it, you cannot any other stuff there. Also, this thing does what it says, attaches the elements to together, like for now, the object to the car.

Example: If you wan't to add it to the car do:

local player = getLocalPlayer(player) 
attachElements(object, player) 

Let's continue on the main script, the object attaching the car.

We have to end the function, by using this: "end"

end 

Now let's add a command to add this object to your car:

addCommandHandler("attachobject", attachTest) 

If you didn't get the code properly, then use this fully script already made:

function attachTest(player) 
    x,y,z = getElementPosition(player) 
    local object = createObject(objectID, x, y, z) 
    local veh = getPedOccupiedVehicle(player) 
    attachElements(object, veh) 
end 
addCommandHandler("attachobject", attachTest) 

If you need any extra help or questions about attachElements, ask in a post down below.

Goodluck in ur scripting, and don't hestate to ask me for help.

Link to comment
function attachTest(player) 
    x,y,z = getElementPosition(player) 
    local object = createObject(objectID, x, y, z) 
    local veh = getPedOccupiedVehicle(player) 
    attachElements(object, veh) 
end 
addCommandHandler("attachobject", attachTest) 

This wrong won't never work .

Ofc, it's wrong, because objectID, won't give anything, this was an example, and in the tutorial i told to replace the objectID with an id.

Link to comment
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...