-- ISVehicleTrailerUtils.getTowableVehicleNear(square, ignoreVehicle, attachmentA, attachmentB) -- 在指定范围内查找可被拖走的车辆 -- 参数square: 搜索的中心点 -- 参数ignoreVehicle: 要忽略的车辆 -- 参数attachmentA: 拖车头部的附着点 -- 参数attachmentB: 车身的附着点 function ISVehicleTrailerUtils.getTowableVehicleNear(square, ignoreVehicle, attachmentA, attachmentB) -- 遍历指定范围内的格子 for y=square:getY() - 10,square:getY()+10 do for x=square:getX()-10,square:getX()+10 do -- 获取当前格子对象 local square2 = getCell():getGridSquare(x, y, square:getZ()) if square2 then -- 遍历当前格子的所有移动物体 for i=1,square2:getMovingObjects():size() do local obj = square2:getMovingObjects():get(i-1) -- 判断当前物体是否为车辆,且不是忽略的车辆,且可以被ignoreVehicle拖走 if instanceof(obj, 'BaseVehicle') and obj ~= ignoreVehicle and ignoreVehicle:canAttachTrailer(obj, attachmentA, attachmentB) then -- 返回找到的车辆 return obj end end end end end -- 没有找到可拖走的车辆,返回nil return nil end

Lua代码:查找附近可拖走的车辆

原文地址: https://www.cveoy.top/t/topic/nyrk 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录