Jump to content

Object


Recommended Posts

  
function onResourceStart() 
    vehicle = getPedOccupiedVehicle(g_P) 
    x,y,z = getElementPosition(vehicle) 
    rx,ry,rz = getVehicleRotation(vehicle) 
    rocket = createObject(3786,x,y,z + 1.2,rx,ry,rz) 
    attachElements(rocket,g_P,0,0,2,rx,ry,rz) 
end 
addEventHandler("onClientResourceStart", resourceRoot, onResourceStart) 
  

I create this script but my rocket dont look where car looks.

Link to comment

1. use local variable for vehicle (since it can change and player can be not in a vehicle at all)

2. you may want to use some vehicle entry event, to attach a rocket to the current vehicle.

3. you dont need to know vehicle rotation or set rotation in createObject, because when you'll attach

the rocket to the car it will recieve the same position and rotation as the car anyway

4. offsets should be relative to the parent element.

  
function onResourceStart() 
    local vehicle = getPedOccupiedVehicle(g_P) 
    if vehicle then  
      local x, y, z = getElementPosition(vehicle) 
      rocket = createObject(3786, x, y, z) 
      attachElements(rocket, vehicle, 0, 0, 2, 0, 0, 0) 
    end   
end 
addEventHandler("onClientResourceStart", resourceRoot, onResourceStart) 

if the rocket is not in the right direction, you'll have to change rotation offsets

in attachElements (last 3 zeros), usually by 90 or 180 degrees on some axis.

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