Jump to content

[Help] Vehicle Enter Handler


Recommended Posts

Hello people!

I'm trying to write a script that allows player enter big planes like AT-400 without using a ladder.

function warptovehicle ()
    local id = getElementModel ( theVehicle )
    if id == 577 then 
	warpPedIntoVehicle ( thePlayer, theVehicle )
	end
end
addEventHandler("onClientVehicleStartEnter",root,warptovehicle)

[2017-07-14 08:00:42] WARNING: BigPlaneEnter\c_bigplane.lua:2: Bad argument @ 'getVehicleName' [Expected vehicle at argument 1, got nil]
[2017-07-14 08:04:44] WARNING: BigPlaneEnter\c_bigplane.lua:2: Bad argument @ 'getElementModel' [Expected element at argument 1, got nil]

Link to comment
function warptovehicle (player, seat)
    local id = getElementModel ( source )
    if id == 577 then 
	warpPedIntoVehicle ( player, source )
	end
end
addEventHandler("onClientVehicleStartEnter",root,warptovehicle)

try it like this i have not tried it.

Link to comment

The question is, does the player move around the AT-400 because I think not when it's not around it's door so.

 

[[CLIENT SIDE]]

-- VARIABLES

	-- VEHICLES WARP

	local theVehicles = {} -- IN CASE YOU WANT IT FOR MORE VEHICLES JUST ADD VALUES TO THE TABLE, theVehicles[ vehicleID ] = true
	theVehicles[ 577 ] = true	

-- FUNCTIONS

	-- CHECK AND WARP

    local function vehicleWarp()
      if not ( isPedInVehicle( localPlayer ) ) then
          local vehicles = getElementsByType( "vehicles" )
          for i = 1, #vehicles do
              local theVehicle = vehicles[ i ]
              if ( theVehicle ) then
                  local vx, vy, vz, px, py, pz = getElementPosition( theVehicle ), getElementPosition( localPlayer )
                  if ( ( ( getDistanceBetweenPoints3D( vx, vy, vz, px, py, pz ) ) <= 5 ) and ( theVehicles[ getElementModel( theVehicle ) ] ) ) then
                      triggerServerEvent( "onPlayerWarpIntoVehicle", localPlayer, theVehicle )
                      break
                  end
              end
          end
      end
  	end

-- BIND KEYS

	bindKey( "enter_exit", "down", vehicleWrap )

[[ SERVER SIDE ]]

-- EVENTS

	-- PLAYER WARP

	addEvent( "onPlayerWarpIntoVehicle", true )

-- FUNCTIONS	

	-- PLAYER WARP

	local function playerWarp( theVehicle )
  		if ( ( source ) and ( theVehicle ) ) then
    		local vehicleDriver = getVehicleOccupants( theVehicle )
    		vehicleDriver = vehicleDriver[ 1 ] or nil
    		if ( vehicleDriver ) then
      			removePedFromVehicle( vehicleDriver )
      			warpPedIntoVehicle( source, theVehicle, 0 )
      		else
      			warpPedIntoVehicle( source, theVehicle, 0 )
      		end
    	end
  	end

-- EVENT HANDLERS

	addEventHandler( "onPlayerWarpIntoVehicle", root, playerWarp )

 

  • Like 1
Link to comment
  • Administrators

Look at the code carefully, it's not that hard to work out what's going wrong. Change the 3rd argument of 'bindKey' to be 'vehicleWarp' (there's currently a typo, 'vehicleWrap')

Link to comment
1 hour ago, LopSided_ said:

Look at the code carefully, it's not that hard to work out what's going wrong. Change the 3rd argument of 'bindKey' to be 'vehicleWarp' (there's currently a typo, 'vehicleWrap')

oh didn't realized that :) 

but still nothing happens in attempt to enterVehicleStart

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