Jump to content

[HELP]Please help to correct my script


Jungs

Recommended Posts

Posted

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

Posted

We won't just fix it like that. You need to specify your problem more specifically.

We will help you, put you in the right direction, and possibly even fix the whole thing, but usually only if you're new to scripting.

Posted

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 ) 

Posted

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.

Posted

The steering wheel already works in cars. Try pressing V a few times when in a vehicle so you can get first person view.

Posted

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.

Posted

What ur doind is simpy really hard, and in some vehicles you cant, just on the whones where you can see it. Making it move.. im not sure if it is working alone already, but you cant move it.

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