Jump to content

[HELP]Please help to correct my script


Jungs

Recommended Posts

Please help to correct my script. The idea of ​​the script is to move the object attached to the vehicle by bindkey. Currently object is attached, but it disappears by pressing the button. Sorry for my english, hope you understand and help me.

Thank you.

on = 0 
function checkModel( theVehicle ) 
Car = getElementModel ( theVehicle ) 
end 
addEventHandler ( "onPlayerVehicleEnter", getRootElement(), checkModel ) 
  
function onEnterVehicle ( theVehicle, seat, jacked ) 
if ( getElementModel ( theVehicle ) == 598 ) then 
bindKey ( source, "F10", "down", createObj ) 
end 
end 
  
addEventHandler ( "onPlayerVehicleEnter", getRootElement(), onEnterVehicle ) 
  
function createObj ( player ) 
   if Car == 598 then 
      if on == 0 then 
      on = 1   
      veh = getPedOccupiedVehicle (player) 
      x, y, z = getElementPosition (veh) 
      object1 = createObject ( 1983,  x, y, z ) 
      attachElements ( object1,  veh, 0, 0, 1.5) 
      else 
      on=0 
      destroyElement(object1) 
      end 
   end 
end 
  
left1 = function (player) 
      moveObject (object1, 1000, 1, 0, 0) 
end 
  
function onBind () 
bindKey ( source, "a", "down", left1 ) 
end 
addEventHandler ( "onPlayerVehicleEnter", getRootElement(), onBind ) 
  
function offBind () 
unbindKey ( source, "a", "down", left1 ) 
end 
addEventHandler ( "onPlayerVehicleExit", getRootElement(), offBind ) 

I do not understand what I did wrong

Link to comment

This should do the trick, though I'm not sure why you attached the object so I removed that line.

on = 0 
function checkModel( theVehicle ) 
Car = getElementModel ( theVehicle ) 
end 
addEventHandler ( "onPlayerVehicleEnter", getRootElement(), checkModel ) 
  
function onEnterVehicle ( theVehicle, seat, jacked ) 
if ( getElementModel ( theVehicle ) == 598 ) then 
bindKey ( source, "F10", "down", createObj ) 
end 
end 
  
addEventHandler ( "onPlayerVehicleEnter", getRootElement(), onEnterVehicle ) 
  
function createObj ( player ) 
   if Car == 598 then 
      if on == 0 then 
      on = 1   
      veh = getPedOccupiedVehicle (player) 
      x, y, z = getElementPosition (veh) 
      object1 = createObject ( 1983,  x, y, z ) 
      else 
      on=0 
      destroyElement(object1) 
      end 
   end 
end 
  
left1 = function (player) 
      veh = getPedOccupiedVehicle (player) 
      x, y, z = getElementPosition (veh) 
      moveObject (object1, 1000, x, y, z) 
end 
  
function onBind () 
bindKey ( source, "a", "down", left1 ) 
end 
addEventHandler ( "onPlayerVehicleEnter", getRootElement(), onBind ) 
  
function offBind () 
unbindKey ( source, "a", "down", left1 ) 
end 
addEventHandler ( "onPlayerVehicleExit", getRootElement(), offBind ) 

Link to comment

Thank you for your response. I'm really new to scripting, this is my second script. The problem is that I can not find a way to move the object relative to the vehicle, only relatively the world. Hope you put me in the right direction. Thank you.

Link to comment

Ok, i'll try to explain. I have a freeroam server with few replaced vehicles, and i have first person view for this vehicles. I want to make steering wheel is turned by pressing "A" and "D" buttons. To implement it I can make in zmodeller a car without a steering wheel. And make steering wheel a separate object and add it into the game by this code

function importTextures() 
    txd = engineLoadTXD ( "steering_wheel.txd" ) 
        engineImportTXD ( txd, 9822 ) 
    dff = engineLoadDFF ( "steering_wheel.dff", 0 ) 
    engineReplaceModel ( dff, 9822 ) 
end 

The problem is that I can not find a way how to implement the movement of object attached to the car.

Hope you understand me, thank you.

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