Jump to content

set player position inside a vehicle


Xwad

Recommended Posts

No, i mean setting the x,y,z position. Gor example: I enter in a vehicle and set the z position of the player +10. Then the player will not inside the vehicle anymore, because its on the top of the vehicle. But it can still drive the car untin he exit from the car.

Link to comment

I don't think that's possible but you can do a workaround:

Create a ped (dummy) and attach it on the vehicle with specific offset (so in your case, Z => 10) and set its animation to be like he's sitting in a car or whatever you'd like. Next, set your alpha to 0 and you're done. I can do an example, but not now.

Functions/events would be:

createPed
setElementAlpha
attachElements
"onVehicleExit"
"onVehicleEnter"

 

Edited by GTX
Added functions
  • Like 1
Link to comment

Because I can't edit my post (This) (I didn't test this example, but it should work):

-- Server side script

local g_Offset = {0,0,2} -- Your offset (How far from vehicle it should be) (X, Y, Z)
local lPeds = {} -- Here we store peds of players

function onEnter(lPlayer)
	local lVehicleX, lVehicleY, lVehicleZ = getElementPosition(source) -- Get vehicle's position
	lPeds[lPlayer] = createPed(getElementModel(lPlayer),lVehicleX,lVehicleY,lVehicleZ) -- Create our dummy
	attachElements(lPeds[lPlayer],source,g_Offset[1],g_Offset[2],g_Offset[3]) -- Attach our dummy to the car with offset
	-- You can set your own animation here
	setPedAnimation(lPeds[lPlayer],"car","sit_relaxed") -- Set our dummy's animation
	setElementAlpha(lPlayer,0) -- Hide us
end
addEventHandler("onVehicleEnter",root,onEnter) -- When player sits in the car

function onStartExit(lPlayer)
	setElementAlpha(lPlayer,255) -- Set alpha back
	destroyElement(lPeds[lPlayer]) -- Destroy our dummy
end
addEventHandler("onVehicleStartExit",root,onStartExit) -- When you press to exit the car

You can edit the script however you want.

Edited by GTX
Fixed typo
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...