Jump to content

Boxes in the trunk


Recommended Posts

addCommandHandler("create", function(sourcePlayer)
    if (sourcePlayer) then
    local x, y, z = getElementPosition ( sourcePlayer ) -- get the player's position
    local rotZ = getElementRotation ( sourcePlayer )  -- get the player's rotation around the Z axis in degrees
	Vehicle = createVehicle ( 411, x+2, y, z, 0, 0, rotZ)
   	Object = createObject ( objectid, 0, 0, 0)
    attachElements (Vehicle, Object, 0, 0, 5 )


Link to post


With this resource you are able to get/modify the position of a vehicle's cargo space.

The position you get is the middle of for example a Bobcat's bed, so if you want to add lots of objects you will have to use some loops for positioning. Look at the exampleS.Lua in the resource.

local function testFunction2()
	local vehicleObject
	if not isElement(vehicleObject) then
		local cargoPos = exports["vehiclecargo"]:getVehicleCargoPlacementPosition(source)
		if cargoPos then
			local x, y, z = getPositionFromElementOffset(source,cargoPos.x, cargoPos.y, cargoPos.z+0.285)
			local vehicleObject = createObject(1271, x, y, z, 0, 0, 0)
			setElementCollisionsEnabled(vehicleObject, false)
			setObjectScale(vehicleObject, 1.5)
			attachElements(vehicleObject, source, cargoPos.x, cargoPos.y, cargoPos.z+0.285)
			-- +value on Z because of the object scaling so the object doesn't collide with the vehicle
			addEventHandler("onVehicleExit", source, 
					if isElement(vehicleObject) then
						vehicleObject = nil
addEventHandler("onVehicleEnter", root, testFunction2)
Link to post

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