Jump to content

Vehicle parts coordinates


Maris

Recommended Posts

  • 2 weeks later...

I took a look into the code. Seems that getX() and getY() for VehicleParts seem to only return the vehicle's X and Y positions now.

image.thumb.png.40677093daf6329f323217dff2f3a89a.png

 

 

I looked around for another function and found two of them that might be helpful: getArea(), getAreaCenter().

local part = vehicle:getPartById("GasTank")
local areaCenter = vehicle:getAreaCenter(part:getArea())
local square = getCell():getGridSquare(areaCenter:getX(), areaCenter:getY(), vehicle:getZ())

 

local areaCenter = vehicle:getAreaCenter( part:getArea() )

areaCenter:getX()
areaCenter:getY()

 

 

I found this code in one of Project Zomboid's files, which uses the location of the "GasTank" to find the nearest Fuel Pump.

 

The file's name is "ISVehiclePartMenu.lua"

"..\steamapps\common\ProjectZomboid\media\lua\client\Vehicles\ISUI\ISVehiclePartMenu.lua"

function ISVehiclePartMenu.getNearbyFuelPump(vehicle)
	local part = vehicle:getPartById("GasTank")
	if not part then return nil end
	local areaCenter = vehicle:getAreaCenter(part:getArea())
	if not areaCenter then return nil end
	local square = getCell():getGridSquare(areaCenter:getX(), areaCenter:getY(), vehicle:getZ())
	if not square then return nil end
	for dy=-2,2 do
		for dx=-2,2 do
			-- TODO: check line-of-sight between 2 squares
			local square2 = getCell():getGridSquare(square:getX() + dx, square:getY() + dy, square:getZ())
			if square2 and square2:getProperties():Is("fuelAmount") and tonumber(square2:getProperties():Val("fuelAmount")) > 0 then
				return square2
			end
		end
	end
end

 

 

 

Edited by ATPHHe
Link to comment
Share on other sites

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
×
×
  • Create New...