Jump to content

Object


Recommended Posts

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

Posted

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.

Posted

attach a object need to be server side use :"onVehicleEnter" and "onVehicleExit" (if you make attach client side only you will see the attached element on the car other player wil not see that object ...)

Posted

I fixed it but i have got 2 problems. I use this script on my race map but when map starts object doesnt creates. The other problem is when player die object is staying where player dies. How can i fix 2 bugs.

P.s: I use onMapStarting too

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